Open svtbuica opened 4 years ago
That is correct. No TS types for this but it has got a really simple interface
I stumbled upon the same issue and fixed it by adding this to my index.d.ts
file:
declare module "graphql-validation-complexity" {
import type { ASTNode, GraphQLError, ValidationContext } from "graphql";
export interface ComplexityLimitRuleOptions {
onCost?: (cost: number, context: ValidationContext) => void;
createError?: (cost: number, node: ASTNode) => GraphQLError;
formatErrorMessage?: (cost: number) => string;
scalarCost?: number;
objectCost?: number;
listFactor?: number;
introspectionListFactor?: number;
}
export function createComplexityLimitRule(
maxCost: number,
options?: ComplexityLimitRuleOptions,
): (ctx: ValidationContext) => any;
}
If you don't have an index.d.ts
file, just create one at your project's root and tsc
will pick it up automatically.
The declaration is not complete (the ComplexityVisitor
class and complexityLimitExceededErrorMessage
function is missing), but if you're only using createComplexityLimitRule
, this should be enough.
@cmd-johnson I used your declarations to open a PR (#284), hope you don't mind? :+1:
@jquense Could this be published, so that people can use the definitions? Thanks!
@jquense Are you still maintaining this package?
Added types in DefinitelyTyped PR #61569
It seems that there is no type declaration in the npm package to use with typescript.
npm i -D @types/graphql-validation-complexity
npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fgraphql-validation-complexity - Not found npm ERR! 404 npm ERR! 404 '@types/graphql-validation-complexity@latest' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url.