From 252159b951a9e7c69cfac135247d34d7fde56fb1 Mon Sep 17 00:00:00 2001 From: Abhik Mitra Date: Wed, 5 Sep 2018 22:23:48 +0530 Subject: [PATCH] Added Types for Graphql Query Complexity --- .../dist/QueryComplexity.d.ts | 26 +++++++++++++++++++ .../graphql-query-complexity/dist/index.d.ts | 2 ++ .../graphql-query-complexity-tests.ts | 4 +++ types/graphql-query-complexity/index.d.ts | 7 +++++ types/graphql-query-complexity/tsconfig.json | 24 +++++++++++++++++ types/graphql-query-complexity/tslint.json | 1 + 6 files changed, 64 insertions(+) create mode 100644 types/graphql-query-complexity/dist/QueryComplexity.d.ts create mode 100644 types/graphql-query-complexity/dist/index.d.ts create mode 100644 types/graphql-query-complexity/graphql-query-complexity-tests.ts create mode 100644 types/graphql-query-complexity/index.d.ts create mode 100644 types/graphql-query-complexity/tsconfig.json create mode 100644 types/graphql-query-complexity/tslint.json diff --git a/types/graphql-query-complexity/dist/QueryComplexity.d.ts b/types/graphql-query-complexity/dist/QueryComplexity.d.ts new file mode 100644 index 0000000000..898e2023bb --- /dev/null +++ b/types/graphql-query-complexity/dist/QueryComplexity.d.ts @@ -0,0 +1,26 @@ +/** + * Created by Ivo Meißner on 28.07.17. + */ +import { ValidationContext, FragmentDefinitionNode, OperationDefinitionNode, FieldNode, InlineFragmentNode, GraphQLUnionType, GraphQLObjectType, GraphQLInterfaceType, GraphQLError } from 'graphql'; +export interface QueryComplexityOptions { + maximumComplexity: number; + variables?: object; + onComplete?: (complexity: number) => void; + createError?: (max: number, actual: number) => GraphQLError; +} +export default class QueryComplexity { + context: ValidationContext; + complexity: number; + options: QueryComplexityOptions; + fragments: { + [name: string]: FragmentDefinitionNode; + }; + OperationDefinition: object; + constructor(context: ValidationContext, options: QueryComplexityOptions); + onOperationDefinitionEnter(operation: OperationDefinitionNode): void; + onOperationDefinitionLeave(): GraphQLError | undefined; + nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | + OperationDefinitionNode, typeDef: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType, complexity?: number): number; + createError(): GraphQLError; + getDefaultComplexity(args: object, childScore: number): number; +} diff --git a/types/graphql-query-complexity/dist/index.d.ts b/types/graphql-query-complexity/dist/index.d.ts new file mode 100644 index 0000000000..5ceb3a70ea --- /dev/null +++ b/types/graphql-query-complexity/dist/index.d.ts @@ -0,0 +1,2 @@ +import { QueryComplexityOptions } from './QueryComplexity'; +export default function createQueryComplexityValidator(options: QueryComplexityOptions): () => void; diff --git a/types/graphql-query-complexity/graphql-query-complexity-tests.ts b/types/graphql-query-complexity/graphql-query-complexity-tests.ts new file mode 100644 index 0000000000..7fc5696726 --- /dev/null +++ b/types/graphql-query-complexity/graphql-query-complexity-tests.ts @@ -0,0 +1,4 @@ +import QueryComplexity from "graphql-query-complexity/dist/QueryComplexity"; + +const complexity = new QueryComplexity(null as any, null as any); +complexity.createError().message; // $ExpectType string diff --git a/types/graphql-query-complexity/index.d.ts b/types/graphql-query-complexity/index.d.ts new file mode 100644 index 0000000000..e7d723884d --- /dev/null +++ b/types/graphql-query-complexity/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for graphql-query-complexity 0.1 +// Project: https://github.com/ivome/graphql-query-complexity +// Definitions by: Abhik Mitra +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 +import createQueryComplexityValidator from "./dist"; +export default createQueryComplexityValidator; diff --git a/types/graphql-query-complexity/tsconfig.json b/types/graphql-query-complexity/tsconfig.json new file mode 100644 index 0000000000..9853a69621 --- /dev/null +++ b/types/graphql-query-complexity/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "dist/index.d.ts", + "dist/QueryComplexity.d.ts", + "graphql-query-complexity-tests.ts" + ] +} \ No newline at end of file diff --git a/types/graphql-query-complexity/tslint.json b/types/graphql-query-complexity/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/graphql-query-complexity/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }