mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Merge pull request #28651 from abhikmitra/master
Added Types for GraphQL Query Complexity
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { QueryComplexityOptions } from './QueryComplexity';
|
||||
export default function createQueryComplexityValidator(options: QueryComplexityOptions): () => void;
|
||||
export type ComplexityResolver = (args: any, complexity: number) => number;
|
||||
export type Complexity = number | ComplexityResolver;
|
||||
@@ -0,0 +1,5 @@
|
||||
import QueryComplexity from "graphql-query-complexity/dist/QueryComplexity";
|
||||
import complexityFunction from "graphql-query-complexity";
|
||||
const complexity = new QueryComplexity(null as any, null as any);
|
||||
complexity.createError().message; // $ExpectType string
|
||||
complexityFunction({maximumComplexity: 10});
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Type definitions for graphql-query-complexity 0.1
|
||||
// Project: https://github.com/ivome/graphql-query-complexity
|
||||
// Definitions by: Abhik Mitra <https://github.com/abhikmitra>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
import createQueryComplexityValidator from "./dist";
|
||||
export default createQueryComplexityValidator;
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"dist/index.d.ts",
|
||||
"dist/QueryComplexity.d.ts",
|
||||
"graphql-query-complexity-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user