UNPKG

5.57 kBTypeScriptView Raw
1import type { Maybe } from '../jsutils/Maybe';
2import type { ObjMap } from '../jsutils/ObjMap';
3import type { GraphQLError } from '../error/GraphQLError';
4import type {
5 SchemaDefinitionNode,
6 SchemaExtensionNode,
7} from '../language/ast';
8import { OperationTypeNode } from '../language/ast';
9import type {
10 GraphQLAbstractType,
11 GraphQLInterfaceType,
12 GraphQLNamedType,
13 GraphQLObjectType,
14} from './definition';
15import type { GraphQLDirective } from './directives';
16/**
17 * Test if the given value is a GraphQL schema.
18 */
19export declare function isSchema(schema: unknown): schema is GraphQLSchema;
20export declare function assertSchema(schema: unknown): GraphQLSchema;
21/**
22 * Custom extensions
23 *
24 * @remarks
25 * Use a unique identifier name for your extension, for example the name of
26 * your library or project. Do not use a shortened identifier as this increases
27 * the risk of conflicts. We recommend you add at most one extension field,
28 * an object which can contain all the values you need.
29 */
30export interface GraphQLSchemaExtensions {
31 [attributeName: string]: unknown;
32}
33/**
34 * Schema Definition
35 *
36 * A Schema is created by supplying the root types of each type of operation,
37 * query and mutation (optional). A schema definition is then supplied to the
38 * validator and executor.
39 *
40 * Example:
41 *
42 * ```ts
43 * const MyAppSchema = new GraphQLSchema({
44 * query: MyAppQueryRootType,
45 * mutation: MyAppMutationRootType,
46 * })
47 * ```
48 *
49 * Note: When the schema is constructed, by default only the types that are
50 * reachable by traversing the root types are included, other types must be
51 * explicitly referenced.
52 *
53 * Example:
54 *
55 * ```ts
56 * const characterInterface = new GraphQLInterfaceType({
57 * name: 'Character',
58 * ...
59 * });
60 *
61 * const humanType = new GraphQLObjectType({
62 * name: 'Human',
63 * interfaces: [characterInterface],
64 * ...
65 * });
66 *
67 * const droidType = new GraphQLObjectType({
68 * name: 'Droid',
69 * interfaces: [characterInterface],
70 * ...
71 * });
72 *
73 * const schema = new GraphQLSchema({
74 * query: new GraphQLObjectType({
75 * name: 'Query',
76 * fields: {
77 * hero: { type: characterInterface, ... },
78 * }
79 * }),
80 * ...
81 * // Since this schema references only the `Character` interface it's
82 * // necessary to explicitly list the types that implement it if
83 * // you want them to be included in the final schema.
84 * types: [humanType, droidType],
85 * })
86 * ```
87 *
88 * Note: If an array of `directives` are provided to GraphQLSchema, that will be
89 * the exact list of directives represented and allowed. If `directives` is not
90 * provided then a default set of the specified directives (e.g. `@include` and
91 * `@skip`) will be used. If you wish to provide *additional* directives to these
92 * specified directives, you must explicitly declare them. Example:
93 *
94 * ```ts
95 * const MyAppSchema = new GraphQLSchema({
96 * ...
97 * directives: specifiedDirectives.concat([ myCustomDirective ]),
98 * })
99 * ```
100 */
101export declare class GraphQLSchema {
102 description: Maybe<string>;
103 extensions: Readonly<GraphQLSchemaExtensions>;
104 astNode: Maybe<SchemaDefinitionNode>;
105 extensionASTNodes: ReadonlyArray<SchemaExtensionNode>;
106 __validationErrors: Maybe<ReadonlyArray<GraphQLError>>;
107 private _queryType;
108 private _mutationType;
109 private _subscriptionType;
110 private _directives;
111 private _typeMap;
112 private _subTypeMap;
113 private _implementationsMap;
114 constructor(config: Readonly<GraphQLSchemaConfig>);
115 get [Symbol.toStringTag](): string;
116 getQueryType(): Maybe<GraphQLObjectType>;
117 getMutationType(): Maybe<GraphQLObjectType>;
118 getSubscriptionType(): Maybe<GraphQLObjectType>;
119 getRootType(operation: OperationTypeNode): Maybe<GraphQLObjectType>;
120 getTypeMap(): TypeMap;
121 getType(name: string): GraphQLNamedType | undefined;
122 getPossibleTypes(
123 abstractType: GraphQLAbstractType,
124 ): ReadonlyArray<GraphQLObjectType>;
125 getImplementations(interfaceType: GraphQLInterfaceType): {
126 objects: ReadonlyArray<GraphQLObjectType>;
127 interfaces: ReadonlyArray<GraphQLInterfaceType>;
128 };
129 isSubType(
130 abstractType: GraphQLAbstractType,
131 maybeSubType: GraphQLObjectType | GraphQLInterfaceType,
132 ): boolean;
133 getDirectives(): ReadonlyArray<GraphQLDirective>;
134 getDirective(name: string): Maybe<GraphQLDirective>;
135 toConfig(): GraphQLSchemaNormalizedConfig;
136}
137declare type TypeMap = ObjMap<GraphQLNamedType>;
138export interface GraphQLSchemaValidationOptions {
139 /**
140 * When building a schema from a GraphQL service's introspection result, it
141 * might be safe to assume the schema is valid. Set to true to assume the
142 * produced schema is valid.
143 *
144 * Default: false
145 */
146 assumeValid?: boolean;
147}
148export interface GraphQLSchemaConfig extends GraphQLSchemaValidationOptions {
149 description?: Maybe<string>;
150 query?: Maybe<GraphQLObjectType>;
151 mutation?: Maybe<GraphQLObjectType>;
152 subscription?: Maybe<GraphQLObjectType>;
153 types?: Maybe<ReadonlyArray<GraphQLNamedType>>;
154 directives?: Maybe<ReadonlyArray<GraphQLDirective>>;
155 extensions?: Maybe<Readonly<GraphQLSchemaExtensions>>;
156 astNode?: Maybe<SchemaDefinitionNode>;
157 extensionASTNodes?: Maybe<ReadonlyArray<SchemaExtensionNode>>;
158}
159/**
160 * @internal
161 */
162export interface GraphQLSchemaNormalizedConfig extends GraphQLSchemaConfig {
163 description: Maybe<string>;
164 types: ReadonlyArray<GraphQLNamedType>;
165 directives: ReadonlyArray<GraphQLDirective>;
166 extensions: Readonly<GraphQLSchemaExtensions>;
167 extensionASTNodes: ReadonlyArray<SchemaExtensionNode>;
168 assumeValid: boolean;
169}
170export {};