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
| Name | Type | Description |
|---|---|---|
| config | Readonly<GraphQLDirectiveConfig> | Configuration describing this object. |
Returns
| Type | Description |
|---|---|
GraphQLDirective |
Members
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description | null | undefined | string | Human-readable description for this schema element, if provided. |
| locations | readonly DirectiveLocation[] | Locations where this directive may be applied. |
| args | readonly GraphQLArgument[] | Arguments accepted by this field or directive. |
| isRepeatable | boolean | Whether this directive may appear more than once at the same location. |
| deprecationReason | null | undefined | string | Reason this element is deprecated, if one was provided. |
| extensions | Readonly<GraphQLDirectiveExtensions> | Extension fields to include in the formatted result. |
| astNode | null | undefined | DirectiveDefinitionNode | AST node from which this schema element was built, if available. |
| extensionASTNodes | readonly 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
| Type | Description |
|---|---|
{ 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 valuetoString()
Returns the schema coordinate identifying this directive.
Signature:
toString(): string
Returns
| Type | Description |
|---|---|
string | The 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
| Type | Description |
|---|---|
string | The JSON-serializable representation. |
Example
const json = directive.toJSON();
// json: the JSON representationFunctions
isDirective()
Test if the given value is a GraphQL directive.
Signature:
isDirective(directive: unknown): directive is GraphQLDirective
Arguments
| Name | Type | Description |
|---|---|---|
| directive | unknown | The directive value. |
Returns
| Type | Description |
|---|---|
directive is GraphQLDirective | True when the value matches this type. |
Example
import { isDirective, GraphQLString } from 'graphql/type';
const result = isDirective(GraphQLString);
// result: true for matching GraphQL typesassertDirective()
Returns the value as a GraphQLDirective, or throws if it is not a directive.
Signature:
assertDirective(directive: unknown): GraphQLDirective
Arguments
| Name | Type | Description |
|---|---|---|
| directive | unknown | The directive value. |
Returns
| Type | Description |
|---|---|
GraphQLDirective | The value typed as a GraphQLDirective. |
Example
import { assertDirective, GraphQLString } from 'graphql/type';
const type = assertDirective(GraphQLString);
// type: GraphQLStringisSpecifiedDirective()
Returns true when the directive is one of the directives specified by GraphQL.
Signature:
isSpecifiedDirective(directive: GraphQLDirective): boolean
Arguments
| Name | Type | Description |
|---|---|---|
| directive | GraphQLDirective | The directive value. |
Returns
| Type | Description |
|---|---|
boolean | True when the value matches this type. |
Example
import { isSpecifiedDirective, GraphQLString } from 'graphql/type';
const result = isSpecifiedDirective(GraphQLString);
// result: true for matching GraphQL typesConstants
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
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| locations | readonly DirectiveLocation[] | Locations where this directive may be applied. |
| args? | null | undefined | GraphQLFieldConfigArgumentMap | Arguments accepted by this field or directive. |
| isRepeatable? | null | undefined | boolean | Whether this directive may appear more than once at the same location. |
| deprecationReason? | null | undefined | string | Reason this element is deprecated, if one was provided. |
| extensions? | null | undefined | Readonly<GraphQLDirectiveExtensions> | Extension fields to include in the formatted result. |
| astNode? | null | undefined | DirectiveDefinitionNode | AST node from which this schema element was built, if available. |
| extensionASTNodes? | null | undefined | readonly DirectiveExtensionNode[] | AST extension nodes applied to this schema element. |