Add types for graphql-depth-limit (#25568)

* add types for graphql-depth-limit

* improve type declaration

* remove "strict-export-declare-modifiers" rule disable
This commit is contained in:
eritikass
2018-05-08 17:39:09 +03:00
committed by Andy
parent 27e6a748e9
commit 842899eee2
4 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
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....
},
)]);

14
types/graphql-depth-limit/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for graphql-depth-limit 1.1
// Project: https://github.com/stems/graphql-depth-limit#readme
// Definitions by: Siim Tiilen <https://github.com/eritikass>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
declare function depthLimit(depthLimit: number, options?: depthLimit.Options, callback?: (obj: any) => void): any;
export = depthLimit;
declare namespace depthLimit {
interface Options {
ignore: Array<string | RegExp | ((queryDepths: any[]) => boolean)>;
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"graphql-depth-limit-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }