UNPKG

28.7 kBTypeScriptView Raw
1// FIXME
2/* eslint-disable import/no-cycle */
3
4import { Maybe } from '../jsutils/Maybe';
5
6import { PromiseOrValue } from '../jsutils/PromiseOrValue';
7import { Path } from '../jsutils/Path';
8
9import {
10 ScalarTypeDefinitionNode,
11 ObjectTypeDefinitionNode,
12 FieldDefinitionNode,
13 InputValueDefinitionNode,
14 InterfaceTypeDefinitionNode,
15 UnionTypeDefinitionNode,
16 EnumTypeDefinitionNode,
17 EnumValueDefinitionNode,
18 InputObjectTypeDefinitionNode,
19 ObjectTypeExtensionNode,
20 InterfaceTypeExtensionNode,
21 OperationDefinitionNode,
22 FieldNode,
23 FragmentDefinitionNode,
24 ValueNode,
25 ScalarTypeExtensionNode,
26 UnionTypeExtensionNode,
27 EnumTypeExtensionNode,
28 InputObjectTypeExtensionNode,
29} from '../language/ast';
30
31import { GraphQLSchema } from './schema';
32
33/**
34 * These are all of the possible kinds of types.
35 */
36export type GraphQLType =
37 | GraphQLScalarType
38 | GraphQLObjectType
39 | GraphQLInterfaceType
40 | GraphQLUnionType
41 | GraphQLEnumType
42 | GraphQLInputObjectType
43 | GraphQLList<any>
44 | GraphQLNonNull<any>;
45
46export function isType(type: any): type is GraphQLType;
47
48export function assertType(type: any): GraphQLType;
49
50export function isScalarType(type: any): type is GraphQLScalarType;
51
52export function assertScalarType(type: any): GraphQLScalarType;
53
54export function isObjectType(type: any): type is GraphQLObjectType;
55
56export function assertObjectType(type: any): GraphQLObjectType;
57
58export function isInterfaceType(type: any): type is GraphQLInterfaceType;
59
60export function assertInterfaceType(type: any): GraphQLInterfaceType;
61
62export function isUnionType(type: any): type is GraphQLUnionType;
63
64export function assertUnionType(type: any): GraphQLUnionType;
65
66export function isEnumType(type: any): type is GraphQLEnumType;
67
68export function assertEnumType(type: any): GraphQLEnumType;
69
70export function isInputObjectType(type: any): type is GraphQLInputObjectType;
71
72export function assertInputObjectType(type: any): GraphQLInputObjectType;
73
74export function isListType(type: any): type is GraphQLList<any>;
75
76export function assertListType(type: any): GraphQLList<any>;
77
78export function isNonNullType(type: any): type is GraphQLNonNull<any>;
79
80export function assertNonNullType(type: any): GraphQLNonNull<any>;
81
82/**
83 * These types may be used as input types for arguments and directives.
84 */
85// TS_SPECIFIC: TS does not allow recursive type definitions, hence the `any`s
86export type GraphQLInputType =
87 | GraphQLScalarType
88 | GraphQLEnumType
89 | GraphQLInputObjectType
90 | GraphQLList<any>
91 | GraphQLNonNull<
92 | GraphQLScalarType
93 | GraphQLEnumType
94 | GraphQLInputObjectType
95 | GraphQLList<any>
96 >;
97
98export function isInputType(type: any): type is GraphQLInputType;
99
100export function assertInputType(type: any): GraphQLInputType;
101
102/**
103 * These types may be used as output types as the result of fields.
104 */
105// TS_SPECIFIC: TS does not allow recursive type definitions, hence the `any`s
106export type GraphQLOutputType =
107 | GraphQLScalarType
108 | GraphQLObjectType
109 | GraphQLInterfaceType
110 | GraphQLUnionType
111 | GraphQLEnumType
112 | GraphQLList<any>
113 | GraphQLNonNull<
114 | GraphQLScalarType
115 | GraphQLObjectType
116 | GraphQLInterfaceType
117 | GraphQLUnionType
118 | GraphQLEnumType
119 | GraphQLList<any>
120 >;
121
122export function isOutputType(type: any): type is GraphQLOutputType;
123
124export function assertOutputType(type: any): GraphQLOutputType;
125
126/**
127 * These types may describe types which may be leaf values.
128 */
129export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType;
130
131export function isLeafType(type: any): type is GraphQLLeafType;
132
133export function assertLeafType(type: any): GraphQLLeafType;
134
135/**
136 * These types may describe the parent context of a selection set.
137 */
138export type GraphQLCompositeType =
139 | GraphQLObjectType
140 | GraphQLInterfaceType
141 | GraphQLUnionType;
142
143export function isCompositeType(type: any): type is GraphQLCompositeType;
144
145export function assertCompositeType(type: any): GraphQLCompositeType;
146
147/**
148 * These types may describe the parent context of a selection set.
149 */
150export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType;
151
152export function isAbstractType(type: any): type is GraphQLAbstractType;
153
154export function assertAbstractType(type: any): GraphQLAbstractType;
155
156/**
157 * List Modifier
158 *
159 * A list is a kind of type marker, a wrapping type which points to another
160 * type. Lists are often created within the context of defining the fields
161 * of an object type.
162 *
163 * Example:
164 *
165 * const PersonType = new GraphQLObjectType({
166 * name: 'Person',
167 * fields: () => ({
168 * parents: { type: new GraphQLList(Person) },
169 * children: { type: new GraphQLList(Person) },
170 * })
171 * })
172 *
173 */
174interface GraphQLList<T extends GraphQLType> {
175 readonly ofType: T;
176 toString: () => string;
177 toJSON: () => string;
178 inspect: () => string;
179}
180
181interface _GraphQLList<T extends GraphQLType> {
182 (type: T): GraphQLList<T>;
183 new (type: T): GraphQLList<T>;
184}
185
186// eslint-disable-next-line @typescript-eslint/no-redeclare
187export const GraphQLList: _GraphQLList<GraphQLType>;
188
189/**
190 * Non-Null Modifier
191 *
192 * A non-null is a kind of type marker, a wrapping type which points to another
193 * type. Non-null types enforce that their values are never null and can ensure
194 * an error is raised if this ever occurs during a request. It is useful for
195 * fields which you can make a strong guarantee on non-nullability, for example
196 * usually the id field of a database row will never be null.
197 *
198 * Example:
199 *
200 * const RowType = new GraphQLObjectType({
201 * name: 'Row',
202 * fields: () => ({
203 * id: { type: new GraphQLNonNull(GraphQLString) },
204 * })
205 * })
206 *
207 * Note: the enforcement of non-nullability occurs within the executor.
208 */
209interface GraphQLNonNull<T extends GraphQLNullableType> {
210 readonly ofType: T;
211 toString: () => string;
212 toJSON: () => string;
213 inspect: () => string;
214}
215
216interface _GraphQLNonNull<T extends GraphQLNullableType> {
217 (type: T): GraphQLNonNull<T>;
218 new (type: T): GraphQLNonNull<T>;
219}
220
221// eslint-disable-next-line @typescript-eslint/no-redeclare
222export const GraphQLNonNull: _GraphQLNonNull<GraphQLNullableType>;
223
224export type GraphQLWrappingType = GraphQLList<any> | GraphQLNonNull<any>;
225
226export function isWrappingType(type: any): type is GraphQLWrappingType;
227
228export function assertWrappingType(type: any): GraphQLWrappingType;
229
230/**
231 * These types can all accept null as a value.
232 */
233export type GraphQLNullableType =
234 | GraphQLScalarType
235 | GraphQLObjectType
236 | GraphQLInterfaceType
237 | GraphQLUnionType
238 | GraphQLEnumType
239 | GraphQLInputObjectType
240 | GraphQLList<any>;
241
242export function isNullableType(type: any): type is GraphQLNullableType;
243
244export function assertNullableType(type: any): GraphQLNullableType;
245
246export function getNullableType(type: undefined): undefined;
247export function getNullableType<T extends GraphQLNullableType>(type: T): T;
248export function getNullableType<T extends GraphQLNullableType>(
249 // FIXME Disabled because of https://github.com/yaacovCR/graphql-tools-fork/issues/40#issuecomment-586671219
250 // eslint-disable-next-line @typescript-eslint/unified-signatures
251 type: GraphQLNonNull<T>,
252): T;
253
254/**
255 * These named types do not include modifiers like List or NonNull.
256 */
257export type GraphQLNamedType =
258 | GraphQLScalarType
259 | GraphQLObjectType
260 | GraphQLInterfaceType
261 | GraphQLUnionType
262 | GraphQLEnumType
263 | GraphQLInputObjectType;
264
265export function isNamedType(type: any): type is GraphQLNamedType;
266
267export function assertNamedType(type: any): GraphQLNamedType;
268
269export function getNamedType(type: undefined): undefined;
270export function getNamedType(type: GraphQLType): GraphQLNamedType;
271
272/**
273 * Used while defining GraphQL types to allow for circular references in
274 * otherwise immutable type definitions.
275 */
276export type Thunk<T> = (() => T) | T;
277
278/**
279 * Custom extensions
280 *
281 * @remarks
282 * Use a unique identifier name for your extension, for example the name of
283 * your library or project. Do not use a shortened identifier as this increases
284 * the risk of conflicts. We recommend you add at most one extension field,
285 * an object which can contain all the values you need.
286 */
287export interface GraphQLScalarTypeExtensions {
288 [attributeName: string]: any;
289}
290
291/**
292 * Scalar Type Definition
293 *
294 * The leaf values of any request and input values to arguments are
295 * Scalars (or Enums) and are defined with a name and a series of functions
296 * used to parse input from ast or variables and to ensure validity.
297 *
298 * Example:
299 *
300 * const OddType = new GraphQLScalarType({
301 * name: 'Odd',
302 * serialize(value) {
303 * return value % 2 === 1 ? value : null;
304 * }
305 * });
306 *
307 */
308export class GraphQLScalarType {
309 name: string;
310 description: Maybe<string>;
311 specifiedByUrl: Maybe<string>;
312 serialize: GraphQLScalarSerializer<any>;
313 parseValue: GraphQLScalarValueParser<any>;
314 parseLiteral: GraphQLScalarLiteralParser<any>;
315 extensions: Maybe<Readonly<GraphQLScalarTypeExtensions>>;
316 astNode: Maybe<ScalarTypeDefinitionNode>;
317 extensionASTNodes: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
318
319 constructor(config: Readonly<GraphQLScalarTypeConfig<any, any>>);
320
321 toConfig(): GraphQLScalarTypeConfig<any, any> & {
322 specifiedByUrl: Maybe<string>;
323 serialize: GraphQLScalarSerializer<any>;
324 parseValue: GraphQLScalarValueParser<any>;
325 parseLiteral: GraphQLScalarLiteralParser<any>;
326 extensions: Maybe<Readonly<GraphQLScalarTypeExtensions>>;
327 extensionASTNodes: ReadonlyArray<ScalarTypeExtensionNode>;
328 };
329
330 toString(): string;
331 toJSON(): string;
332 inspect(): string;
333}
334
335export type GraphQLScalarSerializer<TExternal> = (
336 value: any,
337) => Maybe<TExternal>;
338export type GraphQLScalarValueParser<TInternal> = (
339 value: any,
340) => Maybe<TInternal>;
341export type GraphQLScalarLiteralParser<TInternal> = (
342 valueNode: ValueNode,
343 variables: Maybe<{ [key: string]: any }>,
344) => Maybe<TInternal>;
345
346export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
347 name: string;
348 description?: Maybe<string>;
349 specifiedByUrl?: Maybe<string>;
350 // Serializes an internal value to include in a response.
351 serialize?: GraphQLScalarSerializer<TExternal>;
352 // Parses an externally provided value to use as an input.
353 parseValue?: GraphQLScalarValueParser<TInternal>;
354 // Parses an externally provided literal value to use as an input.
355 parseLiteral?: GraphQLScalarLiteralParser<TInternal>;
356 extensions?: Maybe<Readonly<GraphQLScalarTypeExtensions>>;
357 astNode?: Maybe<ScalarTypeDefinitionNode>;
358 extensionASTNodes?: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
359}
360
361/**
362 * Custom extensions
363 *
364 * @remarks
365 * Use a unique identifier name for your extension, for example the name of
366 * your library or project. Do not use a shortened identifier as this increases
367 * the risk of conflicts. We recommend you add at most one extension field,
368 * an object which can contain all the values you need.
369 *
370 * We've provided these template arguments because this is an open type and
371 * you may find them useful.
372 */
373export interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
374 [attributeName: string]: any;
375}
376
377/**
378 * Object Type Definition
379 *
380 * Almost all of the GraphQL types you define will be object types. Object types
381 * have a name, but most importantly describe their fields.
382 *
383 * Example:
384 *
385 * const AddressType = new GraphQLObjectType({
386 * name: 'Address',
387 * fields: {
388 * street: { type: GraphQLString },
389 * number: { type: GraphQLInt },
390 * formatted: {
391 * type: GraphQLString,
392 * resolve(obj) {
393 * return obj.number + ' ' + obj.street
394 * }
395 * }
396 * }
397 * });
398 *
399 * When two types need to refer to each other, or a type needs to refer to
400 * itself in a field, you can use a function expression (aka a closure or a
401 * thunk) to supply the fields lazily.
402 *
403 * Example:
404 *
405 * const PersonType = new GraphQLObjectType({
406 * name: 'Person',
407 * fields: () => ({
408 * name: { type: GraphQLString },
409 * bestFriend: { type: PersonType },
410 * })
411 * });
412 *
413 */
414export class GraphQLObjectType<TSource = any, TContext = any> {
415 name: string;
416 description: Maybe<string>;
417 isTypeOf: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
418 extensions: Maybe<Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>>;
419 astNode: Maybe<ObjectTypeDefinitionNode>;
420 extensionASTNodes: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
421
422 constructor(config: Readonly<GraphQLObjectTypeConfig<TSource, TContext>>);
423
424 getFields(): GraphQLFieldMap<any, TContext>;
425 getInterfaces(): Array<GraphQLInterfaceType>;
426
427 toConfig(): GraphQLObjectTypeConfig<any, any> & {
428 interfaces: Array<GraphQLInterfaceType>;
429 fields: GraphQLFieldConfigMap<any, any>;
430 extensions: Maybe<Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>>;
431 extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>;
432 };
433
434 toString(): string;
435 toJSON(): string;
436 inspect(): string;
437}
438
439export function argsToArgsConfig(
440 args: ReadonlyArray<GraphQLArgument>,
441): GraphQLFieldConfigArgumentMap;
442
443export interface GraphQLObjectTypeConfig<TSource, TContext> {
444 name: string;
445 description?: Maybe<string>;
446 interfaces?: Thunk<Maybe<Array<GraphQLInterfaceType>>>;
447 fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>;
448 isTypeOf?: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
449 extensions?: Maybe<Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>>;
450 astNode?: Maybe<ObjectTypeDefinitionNode>;
451 extensionASTNodes?: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
452}
453
454export type GraphQLTypeResolver<TSource, TContext> = (
455 value: TSource,
456 context: TContext,
457 info: GraphQLResolveInfo,
458 abstractType: GraphQLAbstractType,
459) => PromiseOrValue<Maybe<GraphQLObjectType<TSource, TContext> | string>>;
460
461export type GraphQLIsTypeOfFn<TSource, TContext> = (
462 source: TSource,
463 context: TContext,
464 info: GraphQLResolveInfo,
465) => PromiseOrValue<boolean>;
466
467export type GraphQLFieldResolver<
468 TSource,
469 TContext,
470 TArgs = { [argName: string]: any }
471> = (
472 source: TSource,
473 args: TArgs,
474 context: TContext,
475 info: GraphQLResolveInfo,
476) => any;
477
478export interface GraphQLResolveInfo {
479 readonly fieldName: string;
480 readonly fieldNodes: ReadonlyArray<FieldNode>;
481 readonly returnType: GraphQLOutputType;
482 readonly parentType: GraphQLObjectType;
483 readonly path: Path;
484 readonly schema: GraphQLSchema;
485 readonly fragments: { [key: string]: FragmentDefinitionNode };
486 readonly rootValue: any;
487 readonly operation: OperationDefinitionNode;
488 readonly variableValues: { [variableName: string]: any };
489}
490
491/**
492 * Custom extensions
493 *
494 * @remarks
495 * Use a unique identifier name for your extension, for example the name of
496 * your library or project. Do not use a shortened identifier as this increases
497 * the risk of conflicts. We recommend you add at most one extension field,
498 * an object which can contain all the values you need.
499 *
500 * We've provided these template arguments because this is an open type and
501 * you may find them useful.
502 */
503export interface GraphQLFieldExtensions<
504 _TSource,
505 _TContext,
506 _TArgs = { [argName: string]: any }
507> {
508 [attributeName: string]: any;
509}
510
511export interface GraphQLFieldConfig<
512 TSource,
513 TContext,
514 TArgs = { [argName: string]: any }
515> {
516 description?: Maybe<string>;
517 type: GraphQLOutputType;
518 args?: GraphQLFieldConfigArgumentMap;
519 resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
520 subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
521 deprecationReason?: Maybe<string>;
522 extensions?: Maybe<
523 Readonly<GraphQLFieldExtensions<TSource, TContext, TArgs>>
524 >;
525 astNode?: Maybe<FieldDefinitionNode>;
526}
527
528export interface GraphQLFieldConfigArgumentMap {
529 [key: string]: GraphQLArgumentConfig;
530}
531
532/**
533 * Custom extensions
534 *
535 * @remarks
536 * Use a unique identifier name for your extension, for example the name of
537 * your library or project. Do not use a shortened identifier as this increases
538 * the risk of conflicts. We recommend you add at most one extension field,
539 * an object which can contain all the values you need.
540 */
541export interface GraphQLArgumentExtensions {
542 [attributeName: string]: any;
543}
544
545export interface GraphQLArgumentConfig {
546 description?: Maybe<string>;
547 type: GraphQLInputType;
548 defaultValue?: any;
549 deprecationReason?: Maybe<string>;
550 extensions?: Maybe<Readonly<GraphQLArgumentExtensions>>;
551 astNode?: Maybe<InputValueDefinitionNode>;
552}
553
554export interface GraphQLFieldConfigMap<TSource, TContext> {
555 [key: string]: GraphQLFieldConfig<TSource, TContext>;
556}
557
558export interface GraphQLField<
559 TSource,
560 TContext,
561 TArgs = { [key: string]: any }
562> {
563 name: string;
564 description: Maybe<string>;
565 type: GraphQLOutputType;
566 args: Array<GraphQLArgument>;
567 resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
568 subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
569 deprecationReason: Maybe<string>;
570 extensions: Maybe<Readonly<GraphQLFieldExtensions<TSource, TContext, TArgs>>>;
571 astNode?: Maybe<FieldDefinitionNode>;
572
573 // @deprecated and will be removed in v16
574 isDeprecated: boolean;
575}
576
577export interface GraphQLArgument {
578 name: string;
579 description: Maybe<string>;
580 type: GraphQLInputType;
581 defaultValue: any;
582 deprecationReason: Maybe<string>;
583 extensions: Maybe<Readonly<GraphQLArgumentExtensions>>;
584 astNode: Maybe<InputValueDefinitionNode>;
585}
586
587export function isRequiredArgument(arg: GraphQLArgument): boolean;
588
589export interface GraphQLFieldMap<TSource, TContext> {
590 [key: string]: GraphQLField<TSource, TContext>;
591}
592
593/**
594 * Custom extensions
595 *
596 * @remarks
597 * Use a unique identifier name for your extension, for example the name of
598 * your library or project. Do not use a shortened identifier as this increases
599 * the risk of conflicts. We recommend you add at most one extension field,
600 * an object which can contain all the values you need.
601 */
602export interface GraphQLInterfaceTypeExtensions {
603 [attributeName: string]: any;
604}
605
606/**
607 * Interface Type Definition
608 *
609 * When a field can return one of a heterogeneous set of types, a Interface type
610 * is used to describe what types are possible, what fields are in common across
611 * all types, as well as a function to determine which type is actually used
612 * when the field is resolved.
613 *
614 * Example:
615 *
616 * const EntityType = new GraphQLInterfaceType({
617 * name: 'Entity',
618 * fields: {
619 * name: { type: GraphQLString }
620 * }
621 * });
622 *
623 */
624export class GraphQLInterfaceType {
625 name: string;
626 description: Maybe<string>;
627 resolveType: Maybe<GraphQLTypeResolver<any, any>>;
628 extensions: Maybe<Readonly<GraphQLInterfaceTypeExtensions>>;
629 astNode?: Maybe<InterfaceTypeDefinitionNode>;
630 extensionASTNodes: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
631
632 constructor(config: Readonly<GraphQLInterfaceTypeConfig<any, any>>);
633 getFields(): GraphQLFieldMap<any, any>;
634 getInterfaces(): Array<GraphQLInterfaceType>;
635
636 toConfig(): GraphQLInterfaceTypeConfig<any, any> & {
637 interfaces: Array<GraphQLInterfaceType>;
638 fields: GraphQLFieldConfigMap<any, any>;
639 extensions: Maybe<Readonly<GraphQLInterfaceTypeExtensions>>;
640 extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
641 };
642
643 toString(): string;
644 toJSON(): string;
645 inspect(): string;
646}
647
648export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
649 name: string;
650 description?: Maybe<string>;
651 interfaces?: Thunk<Maybe<Array<GraphQLInterfaceType>>>;
652 fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>;
653 /**
654 * Optionally provide a custom type resolver function. If one is not provided,
655 * the default implementation will call `isTypeOf` on each implementing
656 * Object type.
657 */
658 resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext>>;
659 extensions?: Maybe<Readonly<GraphQLInterfaceTypeExtensions>>;
660 astNode?: Maybe<InterfaceTypeDefinitionNode>;
661 extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
662}
663
664/**
665 * Custom extensions
666 *
667 * @remarks
668 * Use a unique identifier name for your extension, for example the name of
669 * your library or project. Do not use a shortened identifier as this increases
670 * the risk of conflicts. We recommend you add at most one extension field,
671 * an object which can contain all the values you need.
672 */
673export interface GraphQLUnionTypeExtensions {
674 [attributeName: string]: any;
675}
676
677/**
678 * Union Type Definition
679 *
680 * When a field can return one of a heterogeneous set of types, a Union type
681 * is used to describe what types are possible as well as providing a function
682 * to determine which type is actually used when the field is resolved.
683 *
684 * Example:
685 *
686 * const PetType = new GraphQLUnionType({
687 * name: 'Pet',
688 * types: [ DogType, CatType ],
689 * resolveType(value) {
690 * if (value instanceof Dog) {
691 * return DogType;
692 * }
693 * if (value instanceof Cat) {
694 * return CatType;
695 * }
696 * }
697 * });
698 *
699 */
700export class GraphQLUnionType {
701 name: string;
702 description: Maybe<string>;
703 resolveType: Maybe<GraphQLTypeResolver<any, any>>;
704 extensions: Maybe<Readonly<GraphQLUnionTypeExtensions>>;
705 astNode: Maybe<UnionTypeDefinitionNode>;
706 extensionASTNodes: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
707
708 constructor(config: Readonly<GraphQLUnionTypeConfig<any, any>>);
709 getTypes(): Array<GraphQLObjectType>;
710
711 toConfig(): GraphQLUnionTypeConfig<any, any> & {
712 types: Array<GraphQLObjectType>;
713 extensions: Maybe<Readonly<GraphQLUnionTypeExtensions>>;
714 extensionASTNodes: ReadonlyArray<UnionTypeExtensionNode>;
715 };
716
717 toString(): string;
718 toJSON(): string;
719 inspect(): string;
720}
721
722export interface GraphQLUnionTypeConfig<TSource, TContext> {
723 name: string;
724 description?: Maybe<string>;
725 types: Thunk<Array<GraphQLObjectType>>;
726 /**
727 * Optionally provide a custom type resolver function. If one is not provided,
728 * the default implementation will call `isTypeOf` on each implementing
729 * Object type.
730 */
731 resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext>>;
732 extensions?: Maybe<Readonly<GraphQLUnionTypeExtensions>>;
733 astNode?: Maybe<UnionTypeDefinitionNode>;
734 extensionASTNodes?: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
735}
736
737/**
738 * Custom extensions
739 *
740 * @remarks
741 * Use a unique identifier name for your extension, for example the name of
742 * your library or project. Do not use a shortened identifier as this increases
743 * the risk of conflicts. We recommend you add at most one extension field,
744 * an object which can contain all the values you need.
745 */
746export interface GraphQLEnumTypeExtensions {
747 [attributeName: string]: any;
748}
749
750/**
751 * Enum Type Definition
752 *
753 * Some leaf values of requests and input values are Enums. GraphQL serializes
754 * Enum values as strings, however internally Enums can be represented by any
755 * kind of type, often integers.
756 *
757 * Example:
758 *
759 * const RGBType = new GraphQLEnumType({
760 * name: 'RGB',
761 * values: {
762 * RED: { value: 0 },
763 * GREEN: { value: 1 },
764 * BLUE: { value: 2 }
765 * }
766 * });
767 *
768 * Note: If a value is not provided in a definition, the name of the enum value
769 * will be used as its internal value.
770 */
771export class GraphQLEnumType {
772 name: string;
773 description: Maybe<string>;
774 extensions: Maybe<Readonly<GraphQLEnumTypeExtensions>>;
775 astNode: Maybe<EnumTypeDefinitionNode>;
776 extensionASTNodes: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
777
778 constructor(config: Readonly<GraphQLEnumTypeConfig>);
779 getValues(): Array<GraphQLEnumValue>;
780 getValue(name: string): Maybe<GraphQLEnumValue>;
781 serialize(value: any): Maybe<string>;
782 parseValue(value: any): Maybe<any>;
783 parseLiteral(
784 valueNode: ValueNode,
785 _variables: Maybe<{ [key: string]: any }>,
786 ): Maybe<any>;
787
788 toConfig(): GraphQLEnumTypeConfig & {
789 extensions: Maybe<Readonly<GraphQLEnumTypeExtensions>>;
790 extensionASTNodes: ReadonlyArray<EnumTypeExtensionNode>;
791 };
792
793 toString(): string;
794 toJSON(): string;
795 inspect(): string;
796}
797
798export interface GraphQLEnumTypeConfig {
799 name: string;
800 description?: Maybe<string>;
801 values: GraphQLEnumValueConfigMap;
802 extensions?: Maybe<Readonly<GraphQLEnumTypeExtensions>>;
803 astNode?: Maybe<EnumTypeDefinitionNode>;
804 extensionASTNodes?: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
805}
806
807export interface GraphQLEnumValueConfigMap {
808 [key: string]: GraphQLEnumValueConfig;
809}
810
811/**
812 * Custom extensions
813 *
814 * @remarks
815 * Use a unique identifier name for your extension, for example the name of
816 * your library or project. Do not use a shortened identifier as this increases
817 * the risk of conflicts. We recommend you add at most one extension field,
818 * an object which can contain all the values you need.
819 */
820export interface GraphQLEnumValueExtensions {
821 [attributeName: string]: any;
822}
823
824export interface GraphQLEnumValueConfig {
825 description?: Maybe<string>;
826 value?: any;
827 deprecationReason?: Maybe<string>;
828 extensions?: Maybe<Readonly<GraphQLEnumValueExtensions>>;
829 astNode?: Maybe<EnumValueDefinitionNode>;
830}
831
832export interface GraphQLEnumValue {
833 name: string;
834 description: Maybe<string>;
835 value: any;
836 deprecationReason: Maybe<string>;
837 extensions: Maybe<Readonly<GraphQLEnumValueExtensions>>;
838 astNode?: Maybe<EnumValueDefinitionNode>;
839
840 // @deprecated and will be removed in v16
841 isDeprecated: boolean;
842}
843
844/**
845 * Custom extensions
846 *
847 * @remarks
848 * Use a unique identifier name for your extension, for example the name of
849 * your library or project. Do not use a shortened identifier as this increases
850 * the risk of conflicts. We recommend you add at most one extension field,
851 * an object which can contain all the values you need.
852 */
853export interface GraphQLInputObjectTypeExtensions {
854 [attributeName: string]: any;
855}
856
857/**
858 * Input Object Type Definition
859 *
860 * An input object defines a structured collection of fields which may be
861 * supplied to a field argument.
862 *
863 * Using `NonNull` will ensure that a value must be provided by the query
864 *
865 * Example:
866 *
867 * const GeoPoint = new GraphQLInputObjectType({
868 * name: 'GeoPoint',
869 * fields: {
870 * lat: { type: new GraphQLNonNull(GraphQLFloat) },
871 * lon: { type: new GraphQLNonNull(GraphQLFloat) },
872 * alt: { type: GraphQLFloat, defaultValue: 0 },
873 * }
874 * });
875 *
876 */
877export class GraphQLInputObjectType {
878 name: string;
879 description: Maybe<string>;
880 extensions: Maybe<Readonly<GraphQLInputObjectTypeExtensions>>;
881 astNode: Maybe<InputObjectTypeDefinitionNode>;
882 extensionASTNodes: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
883
884 constructor(config: Readonly<GraphQLInputObjectTypeConfig>);
885 getFields(): GraphQLInputFieldMap;
886
887 toConfig(): GraphQLInputObjectTypeConfig & {
888 fields: GraphQLInputFieldConfigMap;
889 extensions: Maybe<Readonly<GraphQLInputObjectTypeExtensions>>;
890 extensionASTNodes: ReadonlyArray<InputObjectTypeExtensionNode>;
891 };
892
893 toString(): string;
894 toJSON(): string;
895 inspect(): string;
896}
897
898export interface GraphQLInputObjectTypeConfig {
899 name: string;
900 description?: Maybe<string>;
901 fields: Thunk<GraphQLInputFieldConfigMap>;
902 extensions?: Maybe<Readonly<GraphQLInputObjectTypeExtensions>>;
903 astNode?: Maybe<InputObjectTypeDefinitionNode>;
904 extensionASTNodes?: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
905}
906
907/**
908 * Custom extensions
909 *
910 * @remarks
911 * Use a unique identifier name for your extension, for example the name of
912 * your library or project. Do not use a shortened identifier as this increases
913 * the risk of conflicts. We recommend you add at most one extension field,
914 * an object which can contain all the values you need.
915 */
916export interface GraphQLInputFieldExtensions {
917 [attributeName: string]: any;
918}
919
920export interface GraphQLInputFieldConfig {
921 description?: Maybe<string>;
922 type: GraphQLInputType;
923 defaultValue?: any;
924 deprecationReason?: Maybe<string>;
925 extensions?: Maybe<Readonly<GraphQLInputFieldExtensions>>;
926 astNode?: Maybe<InputValueDefinitionNode>;
927}
928
929export interface GraphQLInputFieldConfigMap {
930 [key: string]: GraphQLInputFieldConfig;
931}
932
933export interface GraphQLInputField {
934 name: string;
935 description?: Maybe<string>;
936 type: GraphQLInputType;
937 defaultValue?: any;
938 deprecationReason: Maybe<string>;
939 extensions: Maybe<Readonly<GraphQLInputFieldExtensions>>;
940 astNode?: Maybe<InputValueDefinitionNode>;
941}
942
943export function isRequiredInputField(field: GraphQLInputField): boolean;
944
945export interface GraphQLInputFieldMap {
946 [key: string]: GraphQLInputField;
947}