UNPKG

14.9 kBTypeScriptView Raw
1import { DefinitionNode, DocumentNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, FieldDefinitionNode, FieldNode, FragmentDefinitionNode, GraphQLArgument, GraphQLArgumentConfig, GraphQLDirective, GraphQLEnumType, GraphQLEnumValue, GraphQLEnumValueConfig, GraphQLError, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLIsTypeOfFn, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLScalarLiteralParser, GraphQLScalarSerializer, GraphQLScalarType, GraphQLScalarValueParser, GraphQLSchema, GraphQLType, GraphQLTypeResolver, GraphQLUnionType, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationTypeNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, SelectionNode, Source, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';
2import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3/**
4 * The result of GraphQL execution.
5 *
6 * - `errors` is included when any errors occurred as a non-empty array.
7 * - `data` is the result of a successful execution of the query.
8 * - `hasNext` is true if a future payload is expected.
9 * - `extensions` is reserved for adding non-standard properties.
10 */
11export interface ExecutionResult<TData = any, TExtensions = any> {
12 incremental?: ReadonlyArray<ExecutionResult<TData, TExtensions>>;
13 data?: TData | null;
14 errors?: ReadonlyArray<GraphQLError>;
15 hasNext?: boolean;
16 extensions?: TExtensions;
17 label?: string;
18 path?: ReadonlyArray<string | number>;
19 items?: TData | null;
20}
21export interface ExecutionRequest<TVariables extends Record<string, any> = any, TContext = any, TRootValue = any, TExtensions = Record<string, any>, TReturn = any> {
22 document: TypedDocumentNode<TReturn, TVariables>;
23 variables?: TVariables;
24 operationType?: OperationTypeNode;
25 operationName?: string;
26 extensions?: TExtensions;
27 rootValue?: TRootValue;
28 context?: TContext;
29 info?: GraphQLResolveInfo;
30}
31export interface GraphQLParseOptions {
32 noLocation?: boolean;
33 allowLegacySDLEmptyFields?: boolean;
34 allowLegacySDLImplementsInterfaces?: boolean;
35 experimentalFragmentVariables?: boolean;
36 /**
37 * Set to `true` in order to convert all GraphQL comments (marked with # sign) to descriptions (""")
38 * GraphQL has built-in support for transforming descriptions to comments (with `print`), but not while
39 * parsing. Turning the flag on will support the other way as well (`parse`)
40 */
41 commentDescriptions?: boolean;
42}
43export type ValidatorBehavior = 'error' | 'warn' | 'ignore';
44/**
45 * Options for validating resolvers
46 */
47export interface IResolverValidationOptions {
48 /**
49 * Enable to require a resolver to be defined for any field that has
50 * arguments. Defaults to `ignore`.
51 */
52 requireResolversForArgs?: ValidatorBehavior;
53 /**
54 * Enable to require a resolver to be defined for any field which has
55 * a return type that isn't a scalar. Defaults to `ignore`.
56 */
57 requireResolversForNonScalar?: ValidatorBehavior;
58 /**
59 * Enable to require a resolver for be defined for all fields defined
60 * in the schema. Defaults to `ignore`.
61 */
62 requireResolversForAllFields?: ValidatorBehavior;
63 /**
64 * Enable to require a `resolveType()` for Interface and Union types.
65 * Defaults to `ignore`.
66 */
67 requireResolversForResolveType?: ValidatorBehavior;
68 /**
69 * Enable to require all defined resolvers to match fields that
70 * actually exist in the schema. Defaults to `error` to catch common errors.
71 */
72 requireResolversToMatchSchema?: ValidatorBehavior;
73}
74/**
75 * Configuration object for adding resolvers to a schema
76 */
77export interface IAddResolversToSchemaOptions {
78 /**
79 * The schema to which to add resolvers
80 */
81 schema: GraphQLSchema;
82 /**
83 * Object describing the field resolvers to add to the provided schema
84 */
85 resolvers: IResolvers;
86 /**
87 * Override the default field resolver provided by `graphql-js`
88 */
89 defaultFieldResolver?: IFieldResolver<any, any>;
90 /**
91 * Additional options for validating the provided resolvers
92 */
93 resolverValidationOptions?: IResolverValidationOptions;
94 /**
95 * GraphQL object types that implement interfaces will inherit any missing
96 * resolvers from their interface types defined in the `resolvers` object
97 */
98 inheritResolversFromInterfaces?: boolean;
99 /**
100 * Set to `true` to modify the existing schema instead of creating a new one
101 */
102 updateResolversInPlace?: boolean;
103}
104export type IScalarTypeResolver = GraphQLScalarType & {
105 __name?: string;
106 __description?: string;
107 __serialize?: GraphQLScalarSerializer<any>;
108 __parseValue?: GraphQLScalarValueParser<any>;
109 __parseLiteral?: GraphQLScalarLiteralParser<any>;
110 __extensions?: Record<string, any>;
111 __astNode?: ScalarTypeDefinitionNode;
112 __extensionASTNodes?: Array<ScalarTypeExtensionNode>;
113};
114export type IEnumTypeResolver = Record<string, any> & {
115 __name?: string;
116 __description?: string;
117 __extensions?: Record<string, any>;
118 __astNode?: EnumTypeDefinitionNode;
119 __extensionASTNodes?: Array<EnumTypeExtensionNode>;
120};
121export interface IFieldResolverOptions<TSource = any, TContext = any, TArgs = any> {
122 name?: string;
123 description?: string;
124 type?: GraphQLOutputType;
125 args?: Array<GraphQLArgument>;
126 resolve?: IFieldResolver<TSource, TContext, TArgs>;
127 subscribe?: IFieldResolver<TSource, TContext, TArgs>;
128 isDeprecated?: boolean;
129 deprecationReason?: string;
130 extensions?: Record<string, any>;
131 astNode?: FieldDefinitionNode;
132}
133export type FieldNodeMapper = (fieldNode: FieldNode, fragments: Record<string, FragmentDefinitionNode>, transformationContext: Record<string, any>) => SelectionNode | Array<SelectionNode>;
134export type FieldNodeMappers = Record<string, Record<string, FieldNodeMapper>>;
135export type InputFieldFilter = (typeName?: string, fieldName?: string, inputFieldConfig?: GraphQLInputFieldConfig) => boolean;
136export type FieldFilter = (typeName: string, fieldName: string, fieldConfig: GraphQLFieldConfig<any, any> | GraphQLInputFieldConfig) => boolean;
137export type ObjectFieldFilter = (typeName: string, fieldName: string, fieldConfig: GraphQLFieldConfig<any, any>) => boolean;
138export type RootFieldFilter = (operation: 'Query' | 'Mutation' | 'Subscription', rootFieldName: string, fieldConfig: GraphQLFieldConfig<any, any>) => boolean;
139export type TypeFilter = (typeName: string, type: GraphQLType) => boolean;
140export type ArgumentFilter = (typeName?: string, fieldName?: string, argName?: string, argConfig?: GraphQLArgumentConfig) => boolean;
141export type DirectiveFilter = (directiveName: string, directive: GraphQLDirective) => boolean;
142export type EnumValueFilter = (typeName: string, valueName: string, valueConfig: GraphQLEnumValueConfig) => boolean;
143export type RenameTypesOptions = {
144 renameBuiltins: boolean;
145 renameScalars: boolean;
146};
147export type IFieldResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TReturn;
148export type TypeSource = string | Source | DocumentNode | GraphQLSchema | DefinitionNode | Array<TypeSource> | (() => TypeSource);
149export type IObjectTypeResolver<TSource = any, TContext = any, TArgs = any> = {
150 [key: string]: IFieldResolver<TSource, TContext, TArgs> | IFieldResolverOptions<TSource, TContext>;
151} & {
152 __name?: string;
153 __description?: string;
154 __isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext>;
155 __extensions?: Record<string, any>;
156 __astNode?: ObjectTypeDefinitionNode;
157 __extensionASTNodes?: ObjectTypeExtensionNode;
158};
159export type IInterfaceTypeResolver<TSource = any, TContext = any, TArgs = any> = {
160 [key: string]: IFieldResolver<TSource, TContext, TArgs> | IFieldResolverOptions<TSource, TContext>;
161} & {
162 __name?: string;
163 __description?: string;
164 __resolveType?: GraphQLTypeResolver<any, any>;
165 __extensions?: Record<string, any>;
166 __astNode?: InterfaceTypeDefinitionNode;
167 __extensionASTNodes?: Array<InterfaceTypeExtensionNode>;
168};
169export type IUnionTypeResolver = {
170 __name?: string;
171 __description?: string;
172 __resolveType?: GraphQLTypeResolver<any, any>;
173 __extensions?: Record<string, any>;
174 __astNode?: UnionTypeDefinitionNode;
175 __extensionASTNodes?: Array<UnionTypeExtensionNode>;
176};
177export type IInputObjectTypeResolver = {
178 __name?: string;
179 __description?: string;
180 __extensions?: Record<string, any>;
181 __astNode?: InputObjectTypeDefinitionNode;
182 __extensionASTNodes?: Array<InputObjectTypeExtensionNode>;
183};
184export type ISchemaLevelResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = IFieldResolver<TSource, TContext, TArgs, TReturn>;
185export type IResolvers<TSource = any, TContext = any, TArgs = Record<string, any>, TReturn = any> = Record<string, ISchemaLevelResolver<TSource, TContext, TArgs, TReturn> | IObjectTypeResolver<TSource, TContext> | IInterfaceTypeResolver<TSource, TContext> | IUnionTypeResolver | IScalarTypeResolver | IEnumTypeResolver | IInputObjectTypeResolver>;
186export type IFieldIteratorFn = (fieldDef: GraphQLField<any, any>, typeName: string, fieldName: string) => void;
187export type IDefaultValueIteratorFn = (type: GraphQLInputType, value: any) => void;
188export type NextResolverFn = () => Promise<any>;
189export type VisitableSchemaType = GraphQLSchema | GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType | GraphQLNamedType | GraphQLScalarType | GraphQLField<any, any> | GraphQLInputField | GraphQLArgument | GraphQLUnionType | GraphQLEnumType | GraphQLEnumValue;
190export declare enum MapperKind {
191 TYPE = "MapperKind.TYPE",
192 SCALAR_TYPE = "MapperKind.SCALAR_TYPE",
193 ENUM_TYPE = "MapperKind.ENUM_TYPE",
194 COMPOSITE_TYPE = "MapperKind.COMPOSITE_TYPE",
195 OBJECT_TYPE = "MapperKind.OBJECT_TYPE",
196 INPUT_OBJECT_TYPE = "MapperKind.INPUT_OBJECT_TYPE",
197 ABSTRACT_TYPE = "MapperKind.ABSTRACT_TYPE",
198 UNION_TYPE = "MapperKind.UNION_TYPE",
199 INTERFACE_TYPE = "MapperKind.INTERFACE_TYPE",
200 ROOT_OBJECT = "MapperKind.ROOT_OBJECT",
201 QUERY = "MapperKind.QUERY",
202 MUTATION = "MapperKind.MUTATION",
203 SUBSCRIPTION = "MapperKind.SUBSCRIPTION",
204 DIRECTIVE = "MapperKind.DIRECTIVE",
205 FIELD = "MapperKind.FIELD",
206 COMPOSITE_FIELD = "MapperKind.COMPOSITE_FIELD",
207 OBJECT_FIELD = "MapperKind.OBJECT_FIELD",
208 ROOT_FIELD = "MapperKind.ROOT_FIELD",
209 QUERY_ROOT_FIELD = "MapperKind.QUERY_ROOT_FIELD",
210 MUTATION_ROOT_FIELD = "MapperKind.MUTATION_ROOT_FIELD",
211 SUBSCRIPTION_ROOT_FIELD = "MapperKind.SUBSCRIPTION_ROOT_FIELD",
212 INTERFACE_FIELD = "MapperKind.INTERFACE_FIELD",
213 INPUT_OBJECT_FIELD = "MapperKind.INPUT_OBJECT_FIELD",
214 ARGUMENT = "MapperKind.ARGUMENT",
215 ENUM_VALUE = "MapperKind.ENUM_VALUE"
216}
217export interface SchemaMapper {
218 [MapperKind.TYPE]?: NamedTypeMapper;
219 [MapperKind.SCALAR_TYPE]?: ScalarTypeMapper;
220 [MapperKind.ENUM_TYPE]?: EnumTypeMapper;
221 [MapperKind.COMPOSITE_TYPE]?: CompositeTypeMapper;
222 [MapperKind.OBJECT_TYPE]?: ObjectTypeMapper;
223 [MapperKind.INPUT_OBJECT_TYPE]?: InputObjectTypeMapper;
224 [MapperKind.ABSTRACT_TYPE]?: AbstractTypeMapper;
225 [MapperKind.UNION_TYPE]?: UnionTypeMapper;
226 [MapperKind.INTERFACE_TYPE]?: InterfaceTypeMapper;
227 [MapperKind.ROOT_OBJECT]?: ObjectTypeMapper;
228 [MapperKind.QUERY]?: ObjectTypeMapper;
229 [MapperKind.MUTATION]?: ObjectTypeMapper;
230 [MapperKind.SUBSCRIPTION]?: ObjectTypeMapper;
231 [MapperKind.ENUM_VALUE]?: EnumValueMapper;
232 [MapperKind.FIELD]?: GenericFieldMapper<GraphQLFieldConfig<any, any> | GraphQLInputFieldConfig>;
233 [MapperKind.OBJECT_FIELD]?: FieldMapper;
234 [MapperKind.ROOT_FIELD]?: FieldMapper;
235 [MapperKind.QUERY_ROOT_FIELD]?: FieldMapper;
236 [MapperKind.MUTATION_ROOT_FIELD]?: FieldMapper;
237 [MapperKind.SUBSCRIPTION_ROOT_FIELD]?: FieldMapper;
238 [MapperKind.INTERFACE_FIELD]?: FieldMapper;
239 [MapperKind.COMPOSITE_FIELD]?: FieldMapper;
240 [MapperKind.ARGUMENT]?: ArgumentMapper;
241 [MapperKind.INPUT_OBJECT_FIELD]?: InputFieldMapper;
242 [MapperKind.DIRECTIVE]?: DirectiveMapper;
243}
244export type SchemaFieldMapperTypes = Array<MapperKind.FIELD | MapperKind.COMPOSITE_FIELD | MapperKind.OBJECT_FIELD | MapperKind.ROOT_FIELD | MapperKind.QUERY_ROOT_FIELD | MapperKind.MUTATION_ROOT_FIELD | MapperKind.SUBSCRIPTION_ROOT_FIELD | MapperKind.INTERFACE_FIELD | MapperKind.INPUT_OBJECT_FIELD>;
245export type NamedTypeMapper = (type: GraphQLNamedType, schema: GraphQLSchema) => GraphQLNamedType | null | undefined;
246export type ScalarTypeMapper = (type: GraphQLScalarType, schema: GraphQLSchema) => GraphQLScalarType | null | undefined;
247export type EnumTypeMapper = (type: GraphQLEnumType, schema: GraphQLSchema) => GraphQLEnumType | null | undefined;
248export type EnumValueMapper = (valueConfig: GraphQLEnumValueConfig, typeName: string, schema: GraphQLSchema, externalValue: string) => GraphQLEnumValueConfig | [string, GraphQLEnumValueConfig] | null | undefined;
249export type CompositeTypeMapper = (type: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | null | undefined;
250export type ObjectTypeMapper = (type: GraphQLObjectType, schema: GraphQLSchema) => GraphQLObjectType | null | undefined;
251export type InputObjectTypeMapper = (type: GraphQLInputObjectType, schema: GraphQLSchema) => GraphQLInputObjectType | null | undefined;
252export type AbstractTypeMapper = (type: GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLInterfaceType | GraphQLUnionType | null | undefined;
253export type UnionTypeMapper = (type: GraphQLUnionType, schema: GraphQLSchema) => GraphQLUnionType | null | undefined;
254export type InterfaceTypeMapper = (type: GraphQLInterfaceType, schema: GraphQLSchema) => GraphQLInterfaceType | null | undefined;
255export type DirectiveMapper = (directive: GraphQLDirective, schema: GraphQLSchema) => GraphQLDirective | null | undefined;
256export type GenericFieldMapper<F extends GraphQLFieldConfig<any, any> | GraphQLInputFieldConfig> = (fieldConfig: F, fieldName: string, typeName: string, schema: GraphQLSchema) => F | [string, F] | null | undefined;
257export type FieldMapper = GenericFieldMapper<GraphQLFieldConfig<any, any>>;
258export type ArgumentMapper = (argumentConfig: GraphQLArgumentConfig, fieldName: string, typeName: string, schema: GraphQLSchema) => GraphQLArgumentConfig | [string, GraphQLArgumentConfig] | null | undefined;
259export type InputFieldMapper = GenericFieldMapper<GraphQLInputFieldConfig>;