UNPKG

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