Utilities for the GraphQL warrior
Utilities for the GraphQL warrior
yarn add graphql-zealot
Or: npm install --save graphql-zealot
.
- AddTo
- addEdge
- addEdgeToFragment
- removeEdge
- removeEdgeFromFragment
- replaceEdgeInFragment
- replaceEdge
- cursorForObjectInConnection
- getContentTypeFromFilename
- getTypenameForFile
- optimisticFileResponse
- formValues
- isEmpty
- isEmptyProp
- isEmptyPath
- isOptimistic
- addEdgeToMutationResult
- addEdgeAndCursorToMutationResult
- optimisticResponse
- mapEdgesToProp
- flattenEdges
Direction to add to in a list. Either "head" or "tail"
Type: ("head"
| "tail"
)
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.
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.
Remove an edge from a list
Parameters
Returns any
Remove edge from a list in Fragment
Parameters
fragment
DocumentNodeedgeId
stringrootId
stringedgePath
Array<string>fragmentOptions
(DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions)
Returns Function
Replaces an edge in a Fragment
Parameters
Returns any
Replaces an edge in a list
Parameters
Returns any
Modified version of cursorForObjectInConnection which uses primary ID as well
Parameters
Returns any
Return a content type from a filename, uses mime
.
Parameters
filename
string
Returns string ContentType
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
Returns an optimistic response for a File for instant display
Parameters
Returns any
Return values for obj
omitting id
and __typename
.
- See: Ramda's isEmpty
Returns true whether the arguments is nil or and empty string
Type: Function
Returns whether a prop isEmpty
Type: Function
Returns whether the given Ramda path isEmpty
Type: Function
Returns true is a given string is an UUID.
UUIDs are commonly used to mark optimistic responses.
Type: function (string): boolean
Add edge to a mutation result
Shape: { edge: { node: result } }
Parameters
response
any
Returns {edge: {node: any}}
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
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
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.
Flattens edges recursively
Replaces edges structures with arrays of nodes.
Type: Function
Parameters
connection
Connection
- Ramda
- Apollo
- GraphQL
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
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
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.
yarn test
We base our code style on AirBnB's style guide and we check with ESLint and automatically format our code with Prettier.
This project is licensed under the MIT License - see the license file for details.
- Hat tip to anyone who's code was used
- Inspiration
- etc
If you're interested in contributing to this project in any form, please read our Contribution Guidelines.
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.
Thanks goes to these people (emoji key):
Adrian Perez π» π π |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!