graphql/utilities/operations
Functions
getOperationAST()
Returns an operation AST given a document AST and optionally an operation name. If a name is not provided, an operation is only returned if only one is provided in the document.
Signature:
getOperationAST(documentAST: DocumentNode, operationName?: null | undefined | string): null | undefined | OperationDefinitionNode
Arguments
| Name | Type | Description |
|---|---|---|
| documentAST | DocumentNode | The parsed GraphQL document AST. |
| operationName? | null | undefined | string | The optional operation name to select. |
Returns
| Type | Description |
|---|---|
null | undefined | OperationDefinitionNode | The resolved operation ast. |
Example
import { parse } from 'graphql/language';
import { getOperationAST } from 'graphql/utilities';
const document = parse('query GetName { name }');
const operation = getOperationAST(document, 'GetName');
// operation?.name?.value: 'GetName'getOperationRootType()
Deprecated in v16Extracts the root type of the operation from the schema. This helper is
retained for backwards compatibility; call GraphQLSchema.getRootType instead
because getOperationRootType will be removed in v17.
Signature:
getOperationRootType(schema: GraphQLSchema, operation: OperationDefinitionNode | OperationTypeDefinitionNode): GraphQLObjectType
Arguments
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| operation | OperationDefinitionNode | OperationTypeDefinitionNode | The operation definition to inspect. |
Returns
| Type | Description |
|---|---|
GraphQLObjectType | The resolved operation root type. |
Example
import { buildSchema, getOperationRootType } from 'graphql/utilities';
import { parse } from 'graphql/language';
const schema = buildSchema('type Query { name: String }');
const operation = parse('{ name }').definitions[0];
const rootType = getOperationRootType(schema, operation);
// rootType.name: 'Query'