UNPKG

2.14 kBTypeScriptView Raw
1import Maybe from '../tsutils/Maybe';
2import { GraphQLFieldConfigArgumentMap, GraphQLArgument } from './definition';
3import { DirectiveDefinitionNode } from '../language/ast';
4import { DirectiveLocationEnum } from '../language/directiveLocation';
5
6/**
7 * Test if the given value is a GraphQL directive.
8 */
9export function isDirective(directive: any): directive is GraphQLDirective;
10export function assertDirective(directive: any): GraphQLDirective;
11/**
12 * Directives are used by the GraphQL runtime as a way of modifying execution
13 * behavior. Type system creators will usually not create these directly.
14 */
15export class GraphQLDirective {
16 name: string;
17 description: Maybe<string>;
18 locations: DirectiveLocationEnum[];
19 isRepeatable: boolean;
20 args: GraphQLArgument[];
21 extensions?: Maybe<Readonly<Record<string, any>>>;
22 astNode: Maybe<DirectiveDefinitionNode>;
23
24 constructor(config: GraphQLDirectiveConfig);
25
26 toString(): string;
27
28 toConfig(): GraphQLDirectiveConfig & {
29 args: GraphQLFieldConfigArgumentMap;
30 extensions?: Maybe<Readonly<Record<string, any>>>;
31 isRepeatable: boolean;
32 };
33}
34
35export interface GraphQLDirectiveConfig {
36 name: string;
37 description?: Maybe<string>;
38 locations: DirectiveLocationEnum[];
39 args?: Maybe<GraphQLFieldConfigArgumentMap>;
40 isRepeatable?: Maybe<boolean>;
41 extensions?: Maybe<Readonly<Record<string, any>>>;
42 astNode?: Maybe<DirectiveDefinitionNode>;
43}
44
45/**
46 * Used to conditionally include fields or fragments.
47 */
48export const GraphQLIncludeDirective: GraphQLDirective;
49
50/**
51 * Used to conditionally skip (exclude) fields or fragments.
52 */
53export const GraphQLSkipDirective: GraphQLDirective;
54
55/**
56 * Constant string used for default reason for a deprecation.
57 */
58export const DEFAULT_DEPRECATION_REASON: 'No longer supported';
59
60/**
61 * Used to declare element of a GraphQL schema as deprecated.
62 */
63export const GraphQLDeprecatedDirective: GraphQLDirective;
64
65/**
66 * The full list of specified directives.
67 */
68export const specifiedDirectives: ReadonlyArray<GraphQLDirective>;
69
70export function isSpecifiedDirective(
71 directive: any,
72): directive is GraphQLDirective;