graphql/language/ast-predicates

Functions

isDefinitionNode()

Returns true when the AST node is a definition node.

Signature:

isDefinitionNode(node: ASTNode): node is DefinitionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is DefinitionNodeTrue when the AST node is a definition node.

Example

import { parse, isDefinitionNode } from 'graphql/language';
 
const document = parse('{ hello }');
const isDefinition = isDefinitionNode(document.definitions[0]);
 
// isDefinition: true

isExecutableDefinitionNode()

Returns true when the AST node is an executable definition node.

Signature:

isExecutableDefinitionNode(node: ASTNode): node is ExecutableDefinitionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is ExecutableDefinitionNodeTrue when the AST node is an executable definition node.

Example

import { parse, isExecutableDefinitionNode } from 'graphql/language';
 
const document = parse('{ hello }');
const isExecutable = isExecutableDefinitionNode(document.definitions[0]);
 
// isExecutable: true

isSelectionNode()

Returns true when the AST node is a selection node.

Signature:

isSelectionNode(node: ASTNode): node is SelectionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is SelectionNodeTrue when the AST node is a selection node.

Example

import { Kind, isSelectionNode } from 'graphql/language';
 
const node = { kind: Kind.FIELD, name: { kind: Kind.NAME, value: 'hello' } };
const isSelection = isSelectionNode(node);
 
// isSelection: true

isValueNode()

Returns true when the AST node is a value node.

Signature:

isValueNode(node: ASTNode): node is ValueNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is ValueNodeTrue when the AST node is a value node.

Example

import { parseValue, isValueNode } from 'graphql/language';
 
const value = parseValue('[42]');
const isValue = isValueNode(value);
 
// isValue: true

isConstValueNode()

Returns true when the AST node is a constant value node.

Signature:

isConstValueNode(node: ASTNode): node is ConstValueNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is ConstValueNodeTrue when the AST node is a constant value node.

Example

import { parseConstValue, isConstValueNode } from 'graphql/language';
 
const value = parseConstValue('[42]');
const isConstValue = isConstValueNode(value);
 
// isConstValue: true

isTypeNode()

Returns true when the AST node is a type node.

Signature:

isTypeNode(node: ASTNode): node is TypeNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is TypeNodeTrue when the AST node is a type node.

Example

import { parseType, isTypeNode } from 'graphql/language';
 
const type = parseType('[String!]');
const isType = isTypeNode(type);
 
// isType: true

isTypeSystemDefinitionNode()

Returns true when the AST node is a type system definition node.

Signature:

isTypeSystemDefinitionNode(node: ASTNode): node is TypeSystemDefinitionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is TypeSystemDefinitionNodeTrue when the AST node is a type system definition node.

Example

import { parse, isTypeSystemDefinitionNode } from 'graphql/language';
 
const document = parse('type Query { hello: String }');
const isTypeSystemDefinition = isTypeSystemDefinitionNode(document.definitions[0]);
 
// isTypeSystemDefinition: true

isTypeDefinitionNode()

Returns true when the AST node is a type definition node.

Signature:

isTypeDefinitionNode(node: ASTNode): node is TypeDefinitionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is TypeDefinitionNodeTrue when the AST node is a type definition node.

Example

import { parse, isTypeDefinitionNode } from 'graphql/language';
 
const document = parse('type Query { hello: String }');
const isTypeDefinition = isTypeDefinitionNode(document.definitions[0]);
 
// isTypeDefinition: true

isTypeSystemExtensionNode()

Returns true when the AST node is a type system extension node.

Signature:

isTypeSystemExtensionNode(node: ASTNode): node is TypeSystemExtensionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is TypeSystemExtensionNodeTrue when the AST node is a type system extension node.

Example

import { parse, isTypeSystemExtensionNode } from 'graphql/language';
 
const document = parse('extend type Query { hello: String }');
const isTypeSystemExtension = isTypeSystemExtensionNode(document.definitions[0]);
 
// isTypeSystemExtension: true

isTypeExtensionNode()

Returns true when the AST node is a type extension node.

Signature:

isTypeExtensionNode(node: ASTNode): node is TypeExtensionNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is TypeExtensionNodeTrue when the AST node is a type extension node.

Example

import { parse, isTypeExtensionNode } from 'graphql/language';
 
const document = parse('extend type Query { hello: String }');
const isTypeExtension = isTypeExtensionNode(document.definitions[0]);
 
// isTypeExtension: true

isSchemaCoordinateNode()

Returns true when the AST node is a schema coordinate node.

Signature:

isSchemaCoordinateNode(node: ASTNode): node is SchemaCoordinateNode

Arguments

NameTypeDescription
nodeASTNodeThe AST node to test.

Returns

TypeDescription
node is SchemaCoordinateNodeTrue when the AST node is a schema coordinate node.

Example

import { parseSchemaCoordinate, isSchemaCoordinateNode } from 'graphql/language';
 
const coordinate = parseSchemaCoordinate('Query.hero');
const isCoordinate = isSchemaCoordinateNode(coordinate);
 
// isCoordinate: true