graphql/utilities/type-info
Classes
TypeInfo
TypeInfo is a utility class which, given a GraphQL schema, can keep track
of the current field and type definitions at any point in a GraphQL document
AST during a recursive descent by calling enter(node) and leave(node).
Constructor
Creates a TypeInfo instance.
Signature:
new TypeInfo(schema: GraphQLSchema, initialType?: null | undefined | GraphQLType, getFieldDefFn?: (schema: GraphQLSchema, parentType: GraphQLType, fieldNode: FieldNode) => null | undefined | GraphQLField<unknown, unknown>)
Arguments
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| initialType? | null | undefined | GraphQLType | Initial traversal type when traversal starts below a document. |
| getFieldDefFn? | (schema: GraphQLSchema, parentType: GraphQLType, fieldNode: FieldNode) => null | undefined | GraphQLField<unknown, unknown> | Optional field definition lookup override. |
Returns
| Type | Description |
|---|---|
TypeInfo |
getType()
Returns the current output type at this point in traversal.
Signature:
getType(): null | undefined | GraphQLOutputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLOutputType | The current output type, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getType();
// result contains the getType return valuegetParentType()
Returns the current parent composite type.
Signature:
getParentType(): null | undefined | GraphQLCompositeType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLCompositeType | The current parent composite type, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getParentType();
// result contains the getParentType return valuegetInputType()
Returns the current input type at this point in traversal.
Signature:
getInputType(): null | undefined | GraphQLInputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLInputType | The current input type, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getInputType();
// result contains the getInputType return valuegetParentInputType()
Returns the parent input type for the current input position.
Signature:
getParentInputType(): null | undefined | GraphQLInputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLInputType | The parent input type, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getParentInputType();
// result contains the getParentInputType return valuegetFieldDef()
Returns the current field definition.
Signature:
getFieldDef(): null | undefined | GraphQLField<unknown, unknown>
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLField<unknown, unknown> | The current field definition, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getFieldDef();
// result contains the getFieldDef return valuegetDefaultValue()
Returns the default value for the current input position.
Signature:
getDefaultValue(): unknown
Returns
| Type | Description |
|---|---|
unknown | The current default value, if one is available. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getDefaultValue();
// result contains the getDefaultValue return valuegetDirective()
Returns the current directive definition.
Signature:
getDirective(): null | undefined | GraphQLDirective
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLDirective | The current directive definition, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getDirective();
// result contains the getDirective return valuegetArgument()
Returns the current argument definition.
Signature:
getArgument(): null | undefined | GraphQLArgument
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLArgument | The current argument definition, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getArgument();
// result contains the getArgument return valuegetEnumValue()
Returns the current enum value definition.
Signature:
getEnumValue(): null | undefined | GraphQLEnumValue
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLEnumValue | The current enum value definition, if known. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.getEnumValue();
// result contains the getEnumValue return valueenter()
Updates this TypeInfo instance for an entered AST node.
Signature:
enter(node: ASTNode): void
Arguments
| Name | Type | Description |
|---|---|---|
| node | ASTNode | AST node being entered. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.enter(node);
// result contains the enter return valueleave()
Updates this TypeInfo instance for a left AST node.
Signature:
leave(node: ASTNode): void
Arguments
| Name | Type | Description |
|---|---|---|
| node | ASTNode | AST node being entered. |
Example
// Given a TypeInfo instance named typeInfo:
const result = typeInfo.leave(node);
// result contains the leave return valueFunctions
visitWithTypeInfo()
Creates a new visitor instance which maintains a provided TypeInfo instance along with visiting visitor.
Signature:
visitWithTypeInfo(typeInfo: TypeInfo, visitor: ASTVisitor): ASTVisitor
Arguments
| Name | Type | Description |
|---|---|---|
| typeInfo | TypeInfo | Optional type information to reuse during validation. |
| visitor | ASTVisitor | The visitor value. |
Returns
| Type | Description |
|---|---|
ASTVisitor | A visitor that updates TypeInfo before and after delegating to the provided visitor. |
Example
import { visitWithTypeInfo } from 'graphql/utilities';
const result = visitWithTypeInfo(typeInfo, visitor);
// result contains the visitWithTypeInfo return value