new Document(typeBundle)
This constructor should not be invoked directly. Use the factory function Client#document to create a Document.
Parameters:
Name | Type | Description |
---|---|---|
typeBundle |
Object | A set of ES6 modules generated by graphql-js-schema. |
- Source:
Members
fragmentDefinitions
All FragmentDefinitions on the Document.
- Source:
operations
- Source:
Methods
addMutation(mutation|mutationNameopt, variablesopt, callbackopt)
Adds a mutation to the Document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mutation|mutationName |
Mutation | String |
<optional> |
Either an instance of a mutation object, or the name of a mutation. Both are optional. |
variables |
Array.<Object> |
<optional> |
A list of variables in the mutation. See Client#variable. |
callback |
function |
<optional> |
The mutation builder callback. If a mutation instance is passed, this callback will be ignored. A SelectionSet is created using this callback. |
- Source:
Example
const input = client.variable('input', 'CatCreateInput!');
document.addMutation('myMutation', [input], (root) => {
root.add('catCreate', {args: {input}}, (catCreate) => {
catCreate.add('cat', (cat) => {
cat.add('name');
});
});
});
addQuery(query|queryNameopt, variablesopt, callbackopt)
Adds a query to the Document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
query|queryName |
Query | String |
<optional> |
Either an instance of a query object, or the name of a query. Both are optional. |
variables |
Array.<Object> |
<optional> |
A list of variables in the query. See Client#variable. |
callback |
function |
<optional> |
The query builder callback. If a query instance is passed, this callback will be ignored. A SelectionSet is created using this callback. |
- Source:
Example
document.addQuery('myQuery', (root) => {
root.add('cat', (cat) => {
cat.add('name');
});
});
defineFragment(name, onType, builderFunctionopt) → {FragmentSpread}
Defines a fragment on the Document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | The name of the fragment. |
|
onType |
String | The type the fragment is on. |
|
builderFunction |
function |
<optional> |
The query builder callback. A SelectionSet is created using this callback. |
- Source:
Returns:
A FragmentSpread to be used with SelectionSetBuilder#addFragment.
- Type
- FragmentSpread
toString() → {String}
Returns the GraphQL query string for the Document (e.g. query queryOne { ... } query queryTwo { ... }
).
- Source:
Returns:
The GraphQL query string for the Document.
- Type
- String