UNPKG

2.83 kBTypeScriptView Raw
1// FIXME
2/* eslint-disable import/no-cycle */
3
4import { Maybe } from '../jsutils/Maybe';
5
6import { DirectiveDefinitionNode } from '../language/ast';
7import { DirectiveLocationEnum } from '../language/directiveLocation';
8
9import { GraphQLFieldConfigArgumentMap, GraphQLArgument } from './definition';
10
11/**
12 * Test if the given value is a GraphQL directive.
13 */
14export function isDirective(directive: any): directive is GraphQLDirective;
15export function assertDirective(directive: any): GraphQLDirective;
16
17/**
18 * Custom extensions
19 *
20 * @remarks
21 * Use a unique identifier name for your extension, for example the name of
22 * your library or project. Do not use a shortened identifier as this increases
23 * the risk of conflicts. We recommend you add at most one extension field,
24 * an object which can contain all the values you need.
25 */
26export interface GraphQLDirectiveExtensions {
27 [attributeName: string]: any;
28}
29
30/**
31 * Directives are used by the GraphQL runtime as a way of modifying execution
32 * behavior. Type system creators will usually not create these directly.
33 */
34export class GraphQLDirective {
35 name: string;
36 description: Maybe<string>;
37 locations: Array<DirectiveLocationEnum>;
38 isRepeatable: boolean;
39 args: Array<GraphQLArgument>;
40 extensions: Maybe<Readonly<GraphQLDirectiveExtensions>>;
41 astNode: Maybe<DirectiveDefinitionNode>;
42
43 constructor(config: Readonly<GraphQLDirectiveConfig>);
44
45 toConfig(): GraphQLDirectiveConfig & {
46 args: GraphQLFieldConfigArgumentMap;
47 isRepeatable: boolean;
48 extensions: Maybe<Readonly<GraphQLDirectiveExtensions>>;
49 };
50
51 toString(): string;
52 toJSON(): string;
53 inspect(): string;
54}
55
56export interface GraphQLDirectiveConfig {
57 name: string;
58 description?: Maybe<string>;
59 locations: Array<DirectiveLocationEnum>;
60 args?: Maybe<GraphQLFieldConfigArgumentMap>;
61 isRepeatable?: Maybe<boolean>;
62 extensions?: Maybe<Readonly<GraphQLDirectiveExtensions>>;
63 astNode?: Maybe<DirectiveDefinitionNode>;
64}
65
66/**
67 * Used to conditionally include fields or fragments.
68 */
69export const GraphQLIncludeDirective: GraphQLDirective;
70
71/**
72 * Used to conditionally skip (exclude) fields or fragments.
73 */
74export const GraphQLSkipDirective: GraphQLDirective;
75
76/**
77 * Used to provide a URL for specifying the behavior of custom scalar definitions.
78 */
79export const GraphQLSpecifiedByDirective: GraphQLDirective;
80
81/**
82 * Constant string used for default reason for a deprecation.
83 */
84export const DEFAULT_DEPRECATION_REASON: 'No longer supported';
85
86/**
87 * Used to declare element of a GraphQL schema as deprecated.
88 */
89export const GraphQLDeprecatedDirective: GraphQLDirective;
90
91/**
92 * The full list of specified directives.
93 */
94export const specifiedDirectives: ReadonlyArray<GraphQLDirective>;
95
96export function isSpecifiedDirective(directive: GraphQLDirective): boolean;