graphql/type/directives

Classes

GraphQLDirective

Directives are used by the GraphQL runtime as a way of modifying execution behavior. Type system creators will usually not create these directly.

Constructor

Creates a GraphQLDirective instance.

Signature:

new GraphQLDirective(config: Readonly<GraphQLDirectiveConfig>)
Arguments
NameTypeDescription
configReadonly<GraphQLDirectiveConfig>Configuration describing this object.
Returns
TypeDescription
GraphQLDirective

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionnull | undefined | stringHuman-readable description for this schema element, if provided.
locationsreadonly DirectiveLocation[]Locations where this directive may be applied.
argsreadonly GraphQLArgument[]Arguments accepted by this field or directive.
isRepeatablebooleanWhether this directive may appear more than once at the same location.
deprecationReasonnull | undefined | stringReason this element is deprecated, if one was provided.
extensionsReadonly<GraphQLDirectiveExtensions>Extension fields to include in the formatted result.
astNodenull | undefined | DirectiveDefinitionNodeAST node from which this schema element was built, if available.
extensionASTNodesreadonly DirectiveExtensionNode[]AST extension nodes applied to this schema element.

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): { args: GraphQLFieldConfigArgumentMap; isRepeatable: boolean; extensions: Readonly<GraphQLDirectiveExtensions>; extensionASTNodes: ReadonlyArray<DirectiveExtensionNode> }
Returns
TypeDescription
{ args: GraphQLFieldConfigArgumentMap; isRepeatable: boolean; extensions: Readonly<GraphQLDirectiveExtensions>; extensionASTNodes: ReadonlyArray<DirectiveExtensionNode> }A configuration object that can be used to recreate this object.
Example
// Given a GraphQLDirective instance named directive:
const result = directive.toConfig();
 
// result contains the toConfig return value

toString()

Returns the schema coordinate identifying this directive.

Signature:

toString(): string
Returns
TypeDescription
stringThe directive schema coordinate.
Example
const coordinate = directive.toString();
 
// coordinate: a directive schema coordinate, for example '@include'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string
Returns
TypeDescription
stringThe JSON-serializable representation.
Example
const json = directive.toJSON();
 
// json: the JSON representation

Functions

isDirective()

Test if the given value is a GraphQL directive.

Signature:

isDirective(directive: unknown): directive is GraphQLDirective

Arguments

NameTypeDescription
directiveunknownThe directive value.

Returns

TypeDescription
directive is GraphQLDirectiveTrue when the value matches this type.

Example

import { isDirective, GraphQLString } from 'graphql/type';
 
const result = isDirective(GraphQLString);
 
// result: true for matching GraphQL types

assertDirective()

Returns the value as a GraphQLDirective, or throws if it is not a directive.

Signature:

assertDirective(directive: unknown): GraphQLDirective

Arguments

NameTypeDescription
directiveunknownThe directive value.

Returns

TypeDescription
GraphQLDirectiveThe value typed as a GraphQLDirective.

Example

import { assertDirective, GraphQLString } from 'graphql/type';
 
const type = assertDirective(GraphQLString);
 
// type: GraphQLString

isSpecifiedDirective()

Returns true when the directive is one of the directives specified by GraphQL.

Signature:

isSpecifiedDirective(directive: GraphQLDirective): boolean

Arguments

NameTypeDescription
directiveGraphQLDirectiveThe directive value.

Returns

TypeDescription
booleanTrue when the value matches this type.

Example

import { isSpecifiedDirective, GraphQLString } from 'graphql/type';
 
const result = isSpecifiedDirective(GraphQLString);
 
// result: true for matching GraphQL types

Constants

GraphQLIncludeDirective

Used to conditionally include fields or fragments.

GraphQLDirective

GraphQLSkipDirective

Used to conditionally skip (exclude) fields or fragments.

GraphQLDirective

DEFAULT_DEPRECATION_REASON

Constant string used for default reason for a deprecation.

”No longer supported”

GraphQLDeprecatedDirective

Used to declare element of a GraphQL schema as deprecated.

GraphQLDirective

GraphQLSpecifiedByDirective

Used to provide a URL for specifying the behavior of custom scalar definitions.

GraphQLDirective

GraphQLOneOfDirective

Used to indicate an Input Object is a OneOf Input Object.

GraphQLDirective

specifiedDirectives

The full list of specified directives.

ReadonlyArray<GraphQLDirective>

Types

GraphQLDirectiveExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.

GraphQLDirectiveConfig

Interface. Configuration used to construct a GraphQLDirective.

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
locationsreadonly DirectiveLocation[]Locations where this directive may be applied.
args?null | undefined | GraphQLFieldConfigArgumentMapArguments accepted by this field or directive.
isRepeatable?null | undefined | booleanWhether this directive may appear more than once at the same location.
deprecationReason?null | undefined | stringReason this element is deprecated, if one was provided.
extensions?null | undefined | Readonly<GraphQLDirectiveExtensions>Extension fields to include in the formatted result.
astNode?null | undefined | DirectiveDefinitionNodeAST node from which this schema element was built, if available.
extensionASTNodes?null | undefined | readonly DirectiveExtensionNode[]AST extension nodes applied to this schema element.