graphql-zealot
Utilities for the GraphQL warrior
!Semantically Releasedsemantic-release-badgesemantic-release !Build Statusbuild-badgebuild !Code Coveragecoverage-badgecoverage !versionversion-badgepackage !downloadsdownloads-badgenpmtrends !Styled with Prettierprettier-badgeprettier !AirBnB style guideairbnb-style-badgeairbnb-style
!MIT Licenselicense-badgelicense !PRs Welcomeprs-badgeprs !Commitizen friendlycommitizen-badgecommitizen !Code of Conductcoc-badgecoc
!Watch on GitHubgithub-watch-badgegithub-watch !Star on GitHubgithub-star-badgegithub-star !Tweettwitter-badgetwitter
Utilities for the GraphQL warrior
Installing
yarn add graphql-zealot
Or:
npm install --save graphql-zealot
.API Reference
Table of Contents
- AddTo
- addEdge
- addEdgeToFragment
- removeEdge
- removeEdgeFromFragment
- replaceEdgeInFragment
- replaceEdge
- cursorForObjectInConnection
- getContentTypeFromFilename
- getTypenameForFile
- optimisticFileResponse
- formValues
- isEmpty
- isEmptyProp
- isEmptyPath
- isOptimistic
- addEdgeToMutationResult
- addEdgeAndCursorToMutationResult
- optimisticResponse
- mapEdgesToProp
- flattenEdges
AddTo
src/apollo.js:19-19Direction to add to in a list. Either "head" or "tail"
Type: (
"head"
\| "tail"
)addEdge
src/apollo.js:32-47Returns a function that will use Apollo's DataProxy to update a Query by adding an edge to a list of edges.
Parameters
query
DocumentNode GraphQL query constructed withgraphql-tag
operationName
string Mutation nameedgePath
Array<string> An array to a path to the list of edgesaddTo
AddTo Whether to add the new edge to the beginning or end of the list
Returns Function A function that it's passed to Apollo's update function.
addEdgeToFragment
src/apollo.js:75-108Returns a function that will use Apollo's DataProxy to update a Fragment by adding an edge to a list of edges.
Parameters
fragment
DocumentNode GraphQL fragment constructed withgraphql-tag
operationName
string Mutation nameedgePath
Array<string> An array to a path to the list of edgesrootId
string The root ID for this fragmentaddTo
string Whether to add the new edge to the beginning or end of the listfragmentOptions
(DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions) (optional, default{}
)
Examples
{
// ...
update: addEdgeToFragment(
Favorites.fragments.favorites,
'toggleFavorite',
['favorites'],
userId,
'head',
{
fragmentName: 'Favorites',
}
),
}
Returns Function A function that it's passed to Apollo's update function.
removeEdge
src/apollo.js:119-147Remove an edge from a list
Parameters
Returns any
removeEdgeFromFragment
src/apollo.js:159-184Remove edge from a list in Fragment
Parameters
fragment
DocumentNodeedgeId
stringrootId
stringedgePath
Array<string>fragmentOptions
(DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions)
Returns Function
replaceEdgeInFragment
src/apollo.js:223-232Replaces an edge in a Fragment
Parameters
Returns any
replaceEdge
src/connection.js:38-55Replaces an edge in a list
Parameters
Returns any
cursorForObjectInConnection
src/connection.js:64-79Modified version of cursorForObjectInConnection which uses primary ID as well
Parameters
Returns any
getContentTypeFromFilename
src/files.js:26-29Return a content type from a filename, uses
mime
.Parameters
filename
string
Returns string ContentType
getTypenameForFile
src/files.js:37-48Convert a content-type to a valid GraphQL scbema type
Parameters
file
{contentType: string}
Returns string Image, Video, Audio if content type matches, GenericFile otherwise
optimisticFileResponse
src/files.js:56-80Returns an optimistic response for a File for instant display
Parameters
Returns any
formValues
src/forms.js:7-9Return values for
obj
omitting id
and __typename
.isEmpty
src/isEmpty.js:18-18- See: Ramda's isEmpty
Returns true whether the arguments is nil or and empty string
Type: Function
isEmptyProp
src/isEmpty.js:24-26Returns whether a prop
isEmpty
Type: Function
isEmptyPath
src/isEmpty.js:32-34Returns whether the given Ramda path
isEmpty
Type: Function
isOptimistic
src/isOptimistic.js:14-14Returns true is a given string is an UUID.
UUIDs are commonly used to mark optimistic responses.
Type: function (string): boolean
addEdgeToMutationResult
src/mutations.js:18-25Add edge to a mutation result
Shape: { edge: {
node: result
}
}Parameters
response
any
Returns {edge: {node: any}}
addEdgeAndCursorToMutationResult
src/mutations.js:35-46Add both edge and cursor to a mutation result Cursor is calculated via
cursorForObjectInConnection
.Type: Function
Parameters
connectionGetter
Function Function that returns a promise of a Connection of all recordsobj
Object The current object
optimisticResponse
src/mutations.js:59-77Generate an optimistic response
Type: Function
Parameters
operationName
String The name of the mutation that was runpayloadName
String The name of the payload in the response objectresponse
Object Partial response for the object that's to be returned by the server
Returns Function function that takes variables and can be passed to Apollo's
optimisticResponse
mapEdgesToProp
src/props.js:25-44Map edges to prop
Convert edges structure to an array of objects (nodes).
Type: Function
Parameters
edgePath
String A dot-path to the edges (e.gviewer.user.favorites
,edges
suffix is optional)propName
String Name of the prop to map edges to
Returns Function Function that takes a data object. mapEdgesToProp is curried so you can pass it directly.
flattenEdges
src/props.js:54-75Flattens edges recursively
Replaces edges structures with arrays of nodes.
Type: Function
Parameters
connection
Connection
Developing
Built With
- Ramda
- Apollo
- GraphQL
Pre-requisites
Setting up Dev
Here's a brief intro about what a developer must do in order to start developing the project further:git clone https://github.com/blackxored/graphql-zealot
cd graphql-zealot
yarn
Building
If your project needs some additional steps for the developer to build the project after some code changes, state them here. for example:yarn build
Versioning
We use SemVersemver for versioning. In addition, it's automatic via semantic-releasesemantic-release, and our commit conventioncommit-convention.For the versions available, see the Releasesreleases on this repository.
Tests
yarn test
Style guide
We base our code style on AirBnB's style guideairbnb-style and we check with ESLinteslint and automatically format our code with Prettierprettier.License
This project is licensed under the MIT License - see the license file for details.Acknowledgments
- Hat tip to anyone who's code was used
- Inspiration
- etc
Contributing
If you're interested in contributing to this project in any form, please read our Contribution Guidelinescontributing.Code of Conduct
We've adopted a Code of Conduct that we expect project participants to adhere to. Please read the full textcoc so that you can understand what actions will and will not be tolerated.Contributors
Thanks goes to these people (emoji keyemojis):|
Adrian Perez
💻 📖 🚇") ⚠️ | | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
This project follows the all-contributorsall-contributors specification. Contributions of any kind welcome!