UNPKG

1.65 kBTypeScriptView Raw
1import Maybe from '../tsutils/Maybe';
2import { ASTNode, FieldNode } from '../language/ast';
3import { GraphQLSchema } from '../type/schema';
4import { GraphQLDirective } from '../type/directives';
5import {
6 GraphQLType,
7 GraphQLInputType,
8 GraphQLOutputType,
9 GraphQLCompositeType,
10 GraphQLField,
11 GraphQLArgument,
12 GraphQLEnumValue,
13} from '../type/definition';
14
15/**
16 * TypeInfo is a utility class which, given a GraphQL schema, can keep track
17 * of the current field and type definitions at any point in a GraphQL document
18 * AST during a recursive descent by calling `enter(node)` and `leave(node)`.
19 */
20export class TypeInfo {
21 constructor(
22 schema: GraphQLSchema,
23 // NOTE: this experimental optional second parameter is only needed in order
24 // to support non-spec-compliant codebases. You should never need to use it.
25 // It may disappear in the future.
26 getFieldDefFn?: getFieldDef,
27 // Initial type may be provided in rare cases to facilitate traversals
28 // beginning somewhere other than documents.
29 initialType?: GraphQLType,
30 );
31
32 getType(): Maybe<GraphQLOutputType>;
33 getParentType(): Maybe<GraphQLCompositeType>;
34 getInputType(): Maybe<GraphQLInputType>;
35 getParentInputType(): Maybe<GraphQLInputType>;
36 getFieldDef(): GraphQLField<any, Maybe<any>>;
37 getDefaultValue(): Maybe<any>;
38 getDirective(): Maybe<GraphQLDirective>;
39 getArgument(): Maybe<GraphQLArgument>;
40 getEnumValue(): Maybe<GraphQLEnumValue>;
41 enter(node: ASTNode): any;
42 leave(node: ASTNode): any;
43}
44
45type getFieldDef = (
46 schema: GraphQLSchema,
47 parentType: GraphQLType,
48 fieldNode: FieldNode,
49) => Maybe<GraphQLField<any, any>>;