UNPKG

17.4 kBTypeScriptView Raw
1import { GraphQLSchema, GraphQLField, GraphQLInputType, GraphQLNamedType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLScalarType, DocumentNode, FieldNode, GraphQLEnumValue, GraphQLEnumType, GraphQLUnionType, GraphQLArgument, GraphQLInputField, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLDirective, FragmentDefinitionNode, SelectionNode, OperationDefinitionNode, GraphQLError, ExecutionResult as GraphQLExecutionResult, GraphQLOutputType, FieldDefinitionNode, GraphQLFieldConfig, GraphQLInputFieldConfig, GraphQLArgumentConfig, GraphQLEnumValueConfig, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, GraphQLIsTypeOfFn, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, InterfaceTypeExtensionNode, InterfaceTypeDefinitionNode, GraphQLTypeResolver, UnionTypeDefinitionNode, UnionTypeExtensionNode, InputObjectTypeExtensionNode, InputObjectTypeDefinitionNode } from 'graphql';
2import { SchemaVisitor } from './SchemaVisitor';
3export interface ExecutionResult<TData = Record<string, any>> extends GraphQLExecutionResult {
4 data?: TData | null;
5 extensions?: Record<string, any>;
6}
7export declare type Result = ExecutionResult;
8export declare type TypeMap = Record<string, GraphQLNamedType>;
9export interface GraphQLExecutionContext {
10 schema: GraphQLSchema;
11 fragments: Record<string, FragmentDefinitionNode>;
12 rootValue: any;
13 contextValue: any;
14 operation: OperationDefinitionNode;
15 variableValues: Record<string, any>;
16 fieldResolver: GraphQLFieldResolver<any, any>;
17 errors: Array<GraphQLError>;
18}
19export interface GraphQLParseOptions {
20 noLocation?: boolean;
21 allowLegacySDLEmptyFields?: boolean;
22 allowLegacySDLImplementsInterfaces?: boolean;
23 experimentalFragmentVariables?: boolean;
24}
25/**
26 * Options for validating resolvers
27 */
28export interface IResolverValidationOptions {
29 /**
30 * Set to `true` to require a resolver to be defined for any field that has
31 * arguments. Defaults to `false`.
32 */
33 requireResolversForArgs?: boolean;
34 /**
35 * Set to `true` to require a resolver to be defined for any field which has
36 * a return type that isn't a scalar. Defaults to `false`.
37 */
38 requireResolversForNonScalar?: boolean;
39 /**
40 * Set to `true` to require a resolver for be defined for all fields defined
41 * in the schema. Defaults to `false`.
42 */
43 requireResolversForAllFields?: boolean;
44 /**
45 * Set to `true` to require a `resolveType()` for Interface and Union types.
46 * Defaults to `false`.
47 */
48 requireResolversForResolveType?: boolean;
49 /**
50 * Set to `false` to require all defined resolvers to match fields that
51 * actually exist in the schema. Defaults to `true`.
52 */
53 allowResolversNotInSchema?: boolean;
54}
55/**
56 * Configuration object for adding resolvers to a schema
57 */
58export interface IAddResolversToSchemaOptions {
59 /**
60 * The schema to which to add resolvers
61 */
62 schema: GraphQLSchema;
63 /**
64 * Object describing the field resolvers to add to the provided schema
65 */
66 resolvers: IResolvers;
67 /**
68 * Override the default field resolver provided by `graphql-js`
69 */
70 defaultFieldResolver?: IFieldResolver<any, any>;
71 /**
72 * Additional options for validating the provided resolvers
73 */
74 resolverValidationOptions?: IResolverValidationOptions;
75 /**
76 * GraphQL object types that implement interfaces will inherit any missing
77 * resolvers from their interface types defined in the `resolvers` object
78 */
79 inheritResolversFromInterfaces?: boolean;
80 /**
81 * Set to `true` to modify the existing schema instead of creating a new one
82 */
83 updateResolversInPlace?: boolean;
84}
85export declare type IScalarTypeResolver = GraphQLScalarType & {
86 __name?: string;
87 __description?: string;
88 __serialize?: GraphQLScalarSerializer<any>;
89 __parseValue?: GraphQLScalarValueParser<any>;
90 __parseLiteral?: GraphQLScalarLiteralParser<any>;
91 __extensions?: Record<string, any>;
92 __astNode?: ScalarTypeDefinitionNode;
93 __extensionASTNodes?: Array<ScalarTypeExtensionNode>;
94};
95export declare type IEnumTypeResolver = Record<string, any> & {
96 __name?: string;
97 __description?: string;
98 __extensions?: Record<string, any>;
99 __astNode?: EnumTypeDefinitionNode;
100 __extensionASTNodes?: Array<EnumTypeExtensionNode>;
101};
102export interface IFieldResolverOptions<TSource = any, TContext = any, TArgs = any> {
103 name?: string;
104 description?: string;
105 type?: GraphQLOutputType;
106 args?: Array<GraphQLArgument>;
107 resolve?: IFieldResolver<TSource, TContext, TArgs>;
108 subscribe?: IFieldResolver<TSource, TContext, TArgs>;
109 isDeprecated?: boolean;
110 deprecationReason?: string;
111 extensions?: Record<string, any>;
112 astNode?: FieldDefinitionNode;
113}
114export declare type SchemaTransform = (originalSchema: GraphQLSchema) => GraphQLSchema;
115export declare type RequestTransform<T = Record<string, any>> = (originalRequest: Request, delegationContext?: Record<string, any>, transformationContext?: T) => Request;
116export declare type ResultTransform<T = Record<string, any>> = (originalResult: ExecutionResult, delegationContext?: Record<string, any>, transformationContext?: T) => ExecutionResult;
117export interface Transform<T = Record<string, any>> {
118 transformSchema?: SchemaTransform;
119 transformRequest?: RequestTransform<T>;
120 transformResult?: ResultTransform<T>;
121}
122export declare type FieldNodeMapper = (fieldNode: FieldNode, fragments: Record<string, FragmentDefinitionNode>, transformationContext: Record<string, any>) => SelectionNode | Array<SelectionNode>;
123export declare type FieldNodeMappers = Record<string, Record<string, FieldNodeMapper>>;
124export declare type InputFieldFilter = (typeName?: string, fieldName?: string, inputFieldConfig?: GraphQLInputFieldConfig) => boolean;
125export declare type FieldFilter = (typeName?: string, fieldName?: string, fieldConfig?: GraphQLFieldConfig<any, any>) => boolean;
126export declare type RootFieldFilter = (operation?: 'Query' | 'Mutation' | 'Subscription', rootFieldName?: string, fieldConfig?: GraphQLFieldConfig<any, any>) => boolean;
127export declare type RenameTypesOptions = {
128 renameBuiltins: boolean;
129 renameScalars: boolean;
130};
131export declare type IFieldResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TReturn;
132export declare type ITypedef = (() => Array<ITypedef>) | string | DocumentNode;
133export declare type ITypeDefinitions = ITypedef | Array<ITypedef>;
134export declare type IObjectTypeResolver<TSource = any, TContext = any, TArgs = any> = {
135 [key: string]: IFieldResolver<TSource, TContext, TArgs> | IFieldResolverOptions<TSource, TContext>;
136} & {
137 __name?: string;
138 __description?: string;
139 __isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext>;
140 __extensions?: Record<string, any>;
141 __astNode?: ObjectTypeDefinitionNode;
142 __extensionASTNodes?: ObjectTypeExtensionNode;
143};
144export declare type IInterfaceTypeResolver<TSource = any, TContext = any, TArgs = any> = {
145 [key: string]: IFieldResolver<TSource, TContext, TArgs> | IFieldResolverOptions<TSource, TContext>;
146} & {
147 __name?: string;
148 __description?: string;
149 __resolveType?: GraphQLTypeResolver<any, any>;
150 __extensions?: Record<string, any>;
151 __astNode?: InterfaceTypeDefinitionNode;
152 __extensionASTNodes?: Array<InterfaceTypeExtensionNode>;
153};
154export declare type IUnionTypeResolver = {
155 __name?: string;
156 __description?: string;
157 __resolveType?: GraphQLTypeResolver<any, any>;
158 __extensions?: Record<string, any>;
159 __astNode?: UnionTypeDefinitionNode;
160 __extensionASTNodes?: Array<UnionTypeExtensionNode>;
161};
162export declare type IInputObjectTypeResolver = {
163 __name?: string;
164 __description?: string;
165 __extensions?: Record<string, any>;
166 __astNode?: InputObjectTypeDefinitionNode;
167 __extensionASTNodes?: Array<InputObjectTypeExtensionNode>;
168};
169export declare type ISchemaLevelResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = IFieldResolver<TSource, TContext, TArgs, TReturn>;
170export declare 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>;
171export declare type IFieldIteratorFn = (fieldDef: GraphQLField<any, any>, typeName: string, fieldName: string) => void;
172export declare type IDefaultValueIteratorFn = (type: GraphQLInputType, value: any) => void;
173export declare type NextResolverFn = () => Promise<any>;
174export declare type DirectiveResolverFn<TSource = any, TContext = any> = (next: NextResolverFn, source: TSource, args: {
175 [argName: string]: any;
176}, context: TContext, info: GraphQLResolveInfo) => any;
177export interface IDirectiveResolvers<TSource = any, TContext = any> {
178 [directiveName: string]: DirectiveResolverFn<TSource, TContext>;
179}
180export declare type Operation = 'query' | 'mutation' | 'subscription';
181export interface Request {
182 document: DocumentNode;
183 variables: Record<string, any>;
184 extensions?: Record<string, any>;
185}
186export declare type VisitableSchemaType = GraphQLSchema | GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType | GraphQLNamedType | GraphQLScalarType | GraphQLField<any, any> | GraphQLInputField | GraphQLArgument | GraphQLUnionType | GraphQLEnumType | GraphQLEnumValue;
187export declare type VisitorSelector = (type: VisitableSchemaType, methodName: string) => Array<SchemaVisitor | SchemaVisitorMap>;
188export declare enum VisitSchemaKind {
189 TYPE = "VisitSchemaKind.TYPE",
190 SCALAR_TYPE = "VisitSchemaKind.SCALAR_TYPE",
191 ENUM_TYPE = "VisitSchemaKind.ENUM_TYPE",
192 COMPOSITE_TYPE = "VisitSchemaKind.COMPOSITE_TYPE",
193 OBJECT_TYPE = "VisitSchemaKind.OBJECT_TYPE",
194 INPUT_OBJECT_TYPE = "VisitSchemaKind.INPUT_OBJECT_TYPE",
195 ABSTRACT_TYPE = "VisitSchemaKind.ABSTRACT_TYPE",
196 UNION_TYPE = "VisitSchemaKind.UNION_TYPE",
197 INTERFACE_TYPE = "VisitSchemaKind.INTERFACE_TYPE",
198 ROOT_OBJECT = "VisitSchemaKind.ROOT_OBJECT",
199 QUERY = "VisitSchemaKind.QUERY",
200 MUTATION = "VisitSchemaKind.MUTATION",
201 SUBSCRIPTION = "VisitSchemaKind.SUBSCRIPTION"
202}
203export interface SchemaVisitorMap {
204 [VisitSchemaKind.TYPE]?: NamedTypeVisitor;
205 [VisitSchemaKind.SCALAR_TYPE]?: ScalarTypeVisitor;
206 [VisitSchemaKind.ENUM_TYPE]?: EnumTypeVisitor;
207 [VisitSchemaKind.COMPOSITE_TYPE]?: CompositeTypeVisitor;
208 [VisitSchemaKind.OBJECT_TYPE]?: ObjectTypeVisitor;
209 [VisitSchemaKind.INPUT_OBJECT_TYPE]?: InputObjectTypeVisitor;
210 [VisitSchemaKind.ABSTRACT_TYPE]?: AbstractTypeVisitor;
211 [VisitSchemaKind.UNION_TYPE]?: UnionTypeVisitor;
212 [VisitSchemaKind.INTERFACE_TYPE]?: InterfaceTypeVisitor;
213 [VisitSchemaKind.ROOT_OBJECT]?: ObjectTypeVisitor;
214 [VisitSchemaKind.QUERY]?: ObjectTypeVisitor;
215 [VisitSchemaKind.MUTATION]?: ObjectTypeVisitor;
216 [VisitSchemaKind.SUBSCRIPTION]?: ObjectTypeVisitor;
217}
218export declare type NamedTypeVisitor = (type: GraphQLNamedType, schema: GraphQLSchema) => GraphQLNamedType | null | undefined;
219export declare type ScalarTypeVisitor = (type: GraphQLScalarType, schema: GraphQLSchema) => GraphQLScalarType | null | undefined;
220export declare type EnumTypeVisitor = (type: GraphQLEnumType, schema: GraphQLSchema) => GraphQLEnumType | null | undefined;
221export declare type CompositeTypeVisitor = (type: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | null | undefined;
222export declare type ObjectTypeVisitor = (type: GraphQLObjectType, schema: GraphQLSchema) => GraphQLObjectType | null | undefined;
223export declare type InputObjectTypeVisitor = (type: GraphQLInputObjectType, schema: GraphQLSchema) => GraphQLInputObjectType | null | undefined;
224export declare type AbstractTypeVisitor = (type: GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLInterfaceType | GraphQLUnionType | null | undefined;
225export declare type UnionTypeVisitor = (type: GraphQLUnionType, schema: GraphQLSchema) => GraphQLUnionType | null | undefined;
226export declare type InterfaceTypeVisitor = (type: GraphQLInterfaceType, schema: GraphQLSchema) => GraphQLInterfaceType | null | undefined;
227export declare enum MapperKind {
228 TYPE = "MapperKind.TYPE",
229 SCALAR_TYPE = "MapperKind.SCALAR_TYPE",
230 ENUM_TYPE = "MapperKind.ENUM_TYPE",
231 COMPOSITE_TYPE = "MapperKind.COMPOSITE_TYPE",
232 OBJECT_TYPE = "MapperKind.OBJECT_TYPE",
233 INPUT_OBJECT_TYPE = "MapperKind.INPUT_OBJECT_TYPE",
234 ABSTRACT_TYPE = "MapperKind.ABSTRACT_TYPE",
235 UNION_TYPE = "MapperKind.UNION_TYPE",
236 INTERFACE_TYPE = "MapperKind.INTERFACE_TYPE",
237 ROOT_OBJECT = "MapperKind.ROOT_OBJECT",
238 QUERY = "MapperKind.QUERY",
239 MUTATION = "MapperKind.MUTATION",
240 SUBSCRIPTION = "MapperKind.SUBSCRIPTION",
241 DIRECTIVE = "MapperKind.DIRECTIVE",
242 FIELD = "MapperKind.FIELD",
243 COMPOSITE_FIELD = "MapperKind.COMPOSITE_FIELD",
244 OBJECT_FIELD = "MapperKind.OBJECT_FIELD",
245 ROOT_FIELD = "MapperKind.ROOT_FIELD",
246 QUERY_ROOT_FIELD = "MapperKind.QUERY_ROOT_FIELD",
247 MUTATION_ROOT_FIELD = "MapperKind.MUTATION_ROOT_FIELD",
248 SUBSCRIPTION_ROOT_FIELD = "MapperKind.SUBSCRIPTION_ROOT_FIELD",
249 INTERFACE_FIELD = "MapperKind.INTERFACE_FIELD",
250 INPUT_OBJECT_FIELD = "MapperKind.INPUT_OBJECT_FIELD",
251 ARGUMENT = "MapperKind.ARGUMENT",
252 ENUM_VALUE = "MapperKind.ENUM_VALUE"
253}
254export interface SchemaMapper {
255 [MapperKind.TYPE]?: NamedTypeMapper;
256 [MapperKind.SCALAR_TYPE]?: ScalarTypeMapper;
257 [MapperKind.ENUM_TYPE]?: EnumTypeMapper;
258 [MapperKind.COMPOSITE_TYPE]?: CompositeTypeMapper;
259 [MapperKind.OBJECT_TYPE]?: ObjectTypeMapper;
260 [MapperKind.INPUT_OBJECT_TYPE]?: InputObjectTypeMapper;
261 [MapperKind.ABSTRACT_TYPE]?: AbstractTypeMapper;
262 [MapperKind.UNION_TYPE]?: UnionTypeMapper;
263 [MapperKind.INTERFACE_TYPE]?: InterfaceTypeMapper;
264 [MapperKind.ROOT_OBJECT]?: ObjectTypeMapper;
265 [MapperKind.QUERY]?: ObjectTypeMapper;
266 [MapperKind.MUTATION]?: ObjectTypeMapper;
267 [MapperKind.SUBSCRIPTION]?: ObjectTypeMapper;
268 [MapperKind.ENUM_VALUE]?: EnumValueMapper;
269 [MapperKind.FIELD]?: GenericFieldMapper<GraphQLFieldConfig<any, any> | GraphQLInputFieldConfig>;
270 [MapperKind.OBJECT_FIELD]?: FieldMapper;
271 [MapperKind.ROOT_FIELD]?: FieldMapper;
272 [MapperKind.QUERY_ROOT_FIELD]?: FieldMapper;
273 [MapperKind.MUTATION_ROOT_FIELD]?: FieldMapper;
274 [MapperKind.SUBSCRIPTION_ROOT_FIELD]?: FieldMapper;
275 [MapperKind.INTERFACE_FIELD]?: FieldMapper;
276 [MapperKind.COMPOSITE_FIELD]?: FieldMapper;
277 [MapperKind.ARGUMENT]?: ArgumentMapper;
278 [MapperKind.INPUT_OBJECT_FIELD]?: InputFieldMapper;
279 [MapperKind.DIRECTIVE]?: DirectiveMapper;
280}
281export declare type NamedTypeMapper = (type: GraphQLNamedType, schema: GraphQLSchema) => GraphQLNamedType | null | undefined;
282export declare type ScalarTypeMapper = (type: GraphQLScalarType, schema: GraphQLSchema) => GraphQLScalarType | null | undefined;
283export declare type EnumTypeMapper = (type: GraphQLEnumType, schema: GraphQLSchema) => GraphQLEnumType | null | undefined;
284export declare type EnumValueMapper = (valueConfig: GraphQLEnumValueConfig, typeName: string, schema: GraphQLSchema, externalValue: string) => GraphQLEnumValueConfig | [string, GraphQLEnumValueConfig] | null | undefined;
285export declare type CompositeTypeMapper = (type: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | null | undefined;
286export declare type ObjectTypeMapper = (type: GraphQLObjectType, schema: GraphQLSchema) => GraphQLObjectType | null | undefined;
287export declare type InputObjectTypeMapper = (type: GraphQLInputObjectType, schema: GraphQLSchema) => GraphQLInputObjectType | null | undefined;
288export declare type AbstractTypeMapper = (type: GraphQLInterfaceType | GraphQLUnionType, schema: GraphQLSchema) => GraphQLInterfaceType | GraphQLUnionType | null | undefined;
289export declare type UnionTypeMapper = (type: GraphQLUnionType, schema: GraphQLSchema) => GraphQLUnionType | null | undefined;
290export declare type InterfaceTypeMapper = (type: GraphQLInterfaceType, schema: GraphQLSchema) => GraphQLInterfaceType | null | undefined;
291export declare type DirectiveMapper = (directive: GraphQLDirective, schema: GraphQLSchema) => GraphQLDirective | null | undefined;
292export declare type GenericFieldMapper<F extends GraphQLFieldConfig<any, any> | GraphQLInputFieldConfig> = (fieldConfig: F, fieldName: string, typeName: string, schema: GraphQLSchema) => F | [string, F] | null | undefined;
293export declare type FieldMapper = GenericFieldMapper<GraphQLFieldConfig<any, any>>;
294export declare type ArgumentMapper = (argumentConfig: GraphQLArgumentConfig, fieldName: string, typeName: string, schema: GraphQLSchema) => GraphQLArgumentConfig | [string, GraphQLArgumentConfig] | null | undefined;
295export declare type InputFieldMapper = GenericFieldMapper<GraphQLInputFieldConfig>;