graphql-zealot
v1.1.1
Published
Utilities for the GraphQL warrior
Downloads
11
Readme
graphql-zealot
Utilities for the GraphQL warrior
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
Direction to add to in a list. Either "head" or "tail"
Type: ("head"
| "tail"
)
addEdge
Returns 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
Returns 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
Remove an edge from a list
Parameters
Returns any
removeEdgeFromFragment
Remove edge from a list in Fragment
Parameters
fragment
DocumentNodeedgeId
stringrootId
stringedgePath
Array<string>fragmentOptions
(DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions)
Returns Function
replaceEdgeInFragment
Replaces an edge in a Fragment
Parameters
Returns any
replaceEdge
Replaces an edge in a list
Parameters
Returns any
cursorForObjectInConnection
Modified version of cursorForObjectInConnection which uses primary ID as well
Parameters
Returns any
getContentTypeFromFilename
Return a content type from a filename, uses mime
.
Parameters
filename
string
Returns string ContentType
getTypenameForFile
Convert 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
Returns an optimistic response for a File for instant display
Parameters
Returns any
formValues
Return values for obj
omitting id
and __typename
.
isEmpty
- See: Ramda's isEmpty
Returns true whether the arguments is nil or and empty string
Type: Function
isEmptyProp
Returns whether a prop isEmpty
Type: Function
isEmptyPath
Returns whether the given Ramda path isEmpty
Type: Function
isOptimistic
Returns true is a given string is an UUID.
UUIDs are commonly used to mark optimistic responses.
Type: function (string): boolean
addEdgeToMutationResult
Add edge to a mutation result
Shape: { edge: { node: result } }
Parameters
response
any
Returns {edge: {node: any}}
addEdgeAndCursorToMutationResult
Add 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
Generate 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
Map 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
Flattens 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 SemVer for versioning. In addition, it's automatic via semantic-release, and our commit convention.
For the versions available, see the Releases on this repository.
Tests
yarn test
Style guide
We base our code style on AirBnB's style guide and we check with ESLint and automatically format our code with Prettier.
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 Guidelines.
Code of Conduct
We've adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.
Contributors
Thanks goes to these people (emoji key):
| Adrian Perez💻 📖 🚇 ⚠️ | | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
This project follows the all-contributors specification. Contributions of any kind welcome!