Constructor
new Client(typeBundle, options)
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
typeBundle |
Object | A set of ES6 modules generated by graphql-js-schema. |
||||||||||||||||||||
options |
Object | An options object. Must include either Properties
|
Methods
document() → {Document}
Creates a GraphQL document.
Returns:
A GraphQL document.
- Type
- Document
Example
const document = client.document();
enum(key) → {Enum}
Parameters:
Name | Type | Description |
---|---|---|
key |
String | The key of the enum. |
Returns:
- Type
- Enum
Example
const titleEnum = client.enum('TITLE');
fetchAllPages(paginatedModels, options) → {Promise.<Array.<GraphModel>>}
Fetches all subsequent pages of a paginated array of nodes.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
paginatedModels |
Array.<GraphModel> | The list of nodes on which to fetch all pages. |
||||||
options |
Object | Options object containing: Properties
|
Returns:
A promise resolving with all pages of GraphModels, including the original list.
- Type
- Promise.<Array.<GraphModel>>
Example
client.fetchAllPages(nodes, {pageSize: 20}).then((result) => {
// Do something with all the models
console.log(result);
});
fetchNextPage(nodeOrNodes, optionsopt) → {Promise.<Array.<GraphModel>>}
Fetches the next page of a paginated node or array of nodes.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
nodeOrNodes |
GraphModel | Array.<GraphModel> | The node or list of nodes on which to fetch the next page. |
|||||||||
options |
Object |
<optional> |
Options object containing: Properties
|
Returns:
A promise resolving with the next page of GraphModels.
- Type
- Promise.<Array.<GraphModel>>
Example
client.fetchNextPage(node, {first: 10}).then((result) => {
// Do something with the next page
console.log(result);
});
mutation(nameopt, variablesopt, selectionSetCallback) → {Mutation}
Creates a GraphQL mutation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String |
<optional> |
A name for the mutation. |
variables |
Array.<VariableDefinition> |
<optional> |
A list of variables in the mutation. See Client#variable. |
selectionSetCallback |
function | The mutation builder callback. A SelectionSet is created using this callback. |
Returns:
A GraphQL mutation.
- Type
- Mutation
Example
const input = client.variable('input', 'CatCreateInput!');
const mutation = client.mutation('myMutation', [input], (root) => {
root.add('catCreate', {args: {input}}, (catCreate) => {
catCreate.add('cat', (cat) => {
cat.add('name');
});
});
});
query(nameopt, variablesopt, selectionSetCallback) → {Query}
Creates a GraphQL query.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String |
<optional> |
A name for the query. |
variables |
Array.<VariableDefinition> |
<optional> |
A list of variables in the query. See Client#variable. |
selectionSetCallback |
function | The query builder callback. A SelectionSet is created using this callback. |
Returns:
A GraphQL query.
- Type
- Query
Example
const query = client.query('myQuery', (root) => {
root.add('cat', (cat) => {
cat.add('name');
});
});
refetch(nodeType) → {Promise.<GraphModel>}
Refetches a GraphModel whose type implements Node
.
Parameters:
Name | Type | Description |
---|---|---|
nodeType |
GraphModel | A GraphModel whose type implements |
Returns:
The refetched GraphModel.
- Type
- Promise.<GraphModel>
Example
client.refetch(node).then((result) => {
// Do something with the refetched node
console.log(result);
});
send(request, variableValuesopt, otherPropertiesopt, headersopt) → {Promise.<Object>}
Sends a GraphQL operation (query or mutation) or a document.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
request |
Query | Mutation | Document | function | The operation or document to send. If represented
as a function, it must return |
||
variableValues |
Object |
<optional> |
null | The values for variables in the operation or document. |
otherProperties |
Object |
<optional> |
null | Other properties to send with the query. For example, a custom operation name. |
headers |
Object |
<optional> |
null | Additional headers to be applied on a request by request basis. |
Returns:
A promise resolving to an object containing the response data.
- Type
- Promise.<Object>
Example
client.send(query, {id: '12345'}).then((result) => {
// Do something with the returned result
console.log(result);
});
variable(name, type, defaultValueopt) → {VariableDefinition}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | The name of the variable. |
|
type |
String | The GraphQL type of the variable. |
|
defaultValue |
* |
<optional> |
The default value of the variable. |
Returns:
- Type
- VariableDefinition
Example
const idVariable = client.variable('id', 'ID!', '12345');