From 842899eee264b5952b9c837abe00d90aef998d8a Mon Sep 17 00:00:00 2001 From: eritikass Date: Tue, 8 May 2018 17:39:09 +0300 Subject: [PATCH] Add types for graphql-depth-limit (#25568) * add types for graphql-depth-limit * improve type declaration * remove "strict-export-declare-modifiers" rule disable --- .../graphql-depth-limit-tests.ts | 29 +++++++++++++++++++ types/graphql-depth-limit/index.d.ts | 14 +++++++++ types/graphql-depth-limit/tsconfig.json | 23 +++++++++++++++ types/graphql-depth-limit/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/graphql-depth-limit/graphql-depth-limit-tests.ts create mode 100644 types/graphql-depth-limit/index.d.ts create mode 100644 types/graphql-depth-limit/tsconfig.json create mode 100644 types/graphql-depth-limit/tslint.json diff --git a/types/graphql-depth-limit/graphql-depth-limit-tests.ts b/types/graphql-depth-limit/graphql-depth-limit-tests.ts new file mode 100644 index 0000000000..68a5aa51f9 --- /dev/null +++ b/types/graphql-depth-limit/graphql-depth-limit-tests.ts @@ -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.... + }, +)]); diff --git a/types/graphql-depth-limit/index.d.ts b/types/graphql-depth-limit/index.d.ts new file mode 100644 index 0000000000..281f8fdaff --- /dev/null +++ b/types/graphql-depth-limit/index.d.ts @@ -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 +// 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 boolean)>; + } +} diff --git a/types/graphql-depth-limit/tsconfig.json b/types/graphql-depth-limit/tsconfig.json new file mode 100644 index 0000000000..5c59137102 --- /dev/null +++ b/types/graphql-depth-limit/tsconfig.json @@ -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" + ] +} diff --git a/types/graphql-depth-limit/tslint.json b/types/graphql-depth-limit/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/graphql-depth-limit/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }