DefinitelyTyped/types/graphql-depth-limit/graphql-depth-limit-tests.ts
eritikass 842899eee2 Add types for graphql-depth-limit (#25568)
* add types for graphql-depth-limit

* improve type declaration

* remove "strict-export-declare-modifiers" rule disable
2018-05-08 07:39:09 -07:00

30 lines
678 B
TypeScript

import graphqlDepthLimit = require('graphql-depth-limit');
import {
GraphQLSchema,
DocumentNode,
buildSchema,
Source,
parse,
validate,
specifiedRules
} from 'graphql';
const schema: GraphQLSchema = buildSchema(`
# graphql schema goes here...
`);
const document: DocumentNode = parse(new Source(`
# graphql query goes here...
`, 'GraphQL request'));
validate(schema, document, [ graphqlDepthLimit(5) ]);
validate(schema, document, [ ...specifiedRules, graphqlDepthLimit(10) ]);
validate(schema, document, [ graphqlDepthLimit(
10,
{ ignore: [ /_trusted$/, 'idontcare' ] },
(depths: any) => {
// do something....
},
)]);