-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
index.d.ts
92 lines (81 loc) · 3.33 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {GraphQLSchema, GraphQLError, DocumentNode, ValidationContext} from "graphql";
import {OperationDefinitionNode, FragmentDefinitionNode, InlineFragmentNode, FieldNode, ArgumentNode} from 'graphql/language';
import {PluginDefinition} from "apollo-server-core";
export class QueryValidationVisitor {
onOperationDefinitionEnter (operation: OperationDefinitionNode): void;
onFragmentEnter (node: FragmentDefinitionNode | InlineFragmentNode): void;
onFragmentLeave (node: FragmentDefinitionNode | InlineFragmentNode): void;
onFieldEnter (node: FieldNode): void;
onFieldLeave (node: FieldNode): void;
onArgumentEnter (arg: ArgumentNode): void;
}
/**
* Schema transformer which adds custom types performing validations based on the @constraint directives.
*/
export function constraintDirective () : (schema: GraphQLSchema) => GraphQLSchema;
interface DocumentationOptions {
/** Header for the constraints documentation block in the field or argument description */
header?: string;
/** Names for distinct constraint types */
descriptionsMap?: {
minLength: string,
maxLength: string,
startsWith: string,
endsWith: string,
contains: string,
notContains: string,
pattern: string,
format: string,
min: string,
max: string,
exclusiveMin: string,
exclusiveMax: string,
multipleOf: string,
minItems: string,
maxItems: string
};
}
interface StringArguments {
maxLength?: number;
minLength?: number;
startsWith?: string;
endWith?: string;
contains?: string;
notContains?: string;
pattern?: string;
}
interface PluginOptions {
formats: Record<string, (value: string, args?: StringArguments) => boolean>;
}
/**
* Schema transformer which adds @constraint directives documentation to the fields and arguments descriptions.
* Documentation not added if it already exists (`header` is present in the field or argument description)
*
* @param options options to customize the documentation process
*/
export function constraintDirectiveDocumentation (options: DocumentationOptions) : (schema: GraphQLSchema) => GraphQLSchema;
/**
* Type definition for @constraint directive.
*/
export const constraintDirectiveTypeDefs: string
/**
* Method for query validation based on the @constraint directives defined in the schema.
*
* @param schema GraphQL schema to look for directives
* @param query GraphQL query to validate
* @param variables used in the query to validate
* @param operationName optional name of the GraphQL operation to validate
*/
export function validateQuery () : (schema: GraphQLSchema, query: DocumentNode, variables: Record<string, any>, operationName?: string, pluginOptions?: {}) => Array<GraphQLError>;
/**
* Create Apollo 3 plugin performing query validation.
*/
export function createApolloQueryValidationPlugin ( options: { schema: GraphQLSchema }, pluginOptions?: PluginOptions ) : PluginDefinition;
/**
* Create JS GraphQL Validation Rule performing query validation.
*/
export function createQueryValidationRule( options: { [key: string]: any }) : (context: ValidationContext) => QueryValidationVisitor;
/**
* Create Envelop plugin performing query validation.
*/
export function createEnvelopQueryValidationPlugin( pluginOptions?: PluginOptions ) : { onExecute: Function };