UNPKG

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