-
-
Save Ponjimon/0c085f624291d7575dc5666b71768ce4 to your computer and use it in GitHub Desktop.
graphql-cost-analysis types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'graphql-cost-analysis' { | |
import { | |
DirectiveNode, | |
FieldNode, | |
FragmentDefinitionNode, | |
GraphQLError, | |
GraphQLNamedType, | |
OperationDefinitionNode, | |
ValidationContext, | |
ValueNode, | |
} from 'graphql'; | |
import Maybe from 'graphql/tsutils/Maybe'; | |
declare interface CostAnalysisOptions { | |
maximumCost: number; | |
variables?: object; | |
onComplete?: (cost: number) => void; | |
createError?: (maximumCost: number, cost: number) => GraphQLError; | |
defaultCost?: number; | |
costMap?: object; | |
complexityRange?: { min: number; max: number }; | |
} | |
declare interface NodeCostConfiguration { | |
multiplier?: Maybe<number>; | |
useMultipliers?: boolean; | |
complexity?: number; | |
multipliers?: number[]; | |
} | |
declare class CostAnalysis { | |
context: ValidationContext; | |
cost: number; | |
options: CostAnalysisOptions; | |
fragments: { [name: string]: FragmentDefinitionNode }; | |
OperationDefinition: object; | |
operationMultipliers: number[]; | |
defaultCost: number; | |
defaultComplexity: number; | |
constructor( | |
context: ValidationContext, | |
options: CostAnalysisOptions | |
): void; | |
onOperationDefinitionEnter(operation: OperationDefinitionNode): void; | |
onOperationDefinitionLeave(): void | GraphQLError; | |
computeCost({ | |
multiplier, | |
useMultipliers, | |
complexity, | |
multipliers, | |
}: NodeCostConfiguration): number; | |
getArgsFromCostMap( | |
node: FieldNode, | |
parentType: string, | |
fieldArgs: { [argument: string]: any } | |
): void | NodeCostConfiguration; | |
getMultipliersFromListNode( | |
listNode: ReadOnlyArray<ValueNode>, | |
fieldArgs: { [argument: string]: any } | |
): number[]; | |
getMultipliersFromString( | |
multipliers: string[], | |
fieldArgs: { [argument: string]: any } | |
): number[]; | |
getArgsFromDirectives( | |
directives: ReadOnlyArray<DirectiveNode>, | |
fieldArgs: { [argument: string]: any } | |
): NodeCostConfiguration; | |
computeNodeCost( | |
node: NodeType, | |
typeDef: Maybe<GraphQLNamedType>, | |
parentMultipliers: number[] | |
): number; | |
createError(): GraphQLError; | |
} | |
export default function createCostAnalysis( | |
options: CostAnalysisOptions | |
): (context: ValidationContext) => CostAnalysis; | |
} | |
declare module 'graphql-cost-analysis/dist/costAnalysis' { | |
export default class CostAnalysis { | |
context: ValidationContext; | |
cost: number; | |
options: CostAnalysisOptions; | |
fragments: { [name: string]: FragmentDefinitionNode }; | |
OperationDefinition: object; | |
operationMultipliers: number[]; | |
defaultCost: number; | |
defaultComplexity: number; | |
constructor( | |
context: ValidationContext, | |
options: CostAnalysisOptions | |
): void; | |
onOperationDefinitionEnter(operation: OperationDefinitionNode): void; | |
onOperationDefinitionLeave(): void | GraphQLError; | |
computeCost({ | |
multiplier, | |
useMultipliers, | |
complexity, | |
multipliers, | |
}: NodeCostConfiguration): number; | |
getArgsFromCostMap( | |
node: FieldNode, | |
parentType: string, | |
fieldArgs: { [argument: string]: any } | |
): void | NodeCostConfiguration; | |
getMultipliersFromListNode( | |
listNode: ReadOnlyArray<ValueNode>, | |
fieldArgs: { [argument: string]: any } | |
): number[]; | |
getMultipliersFromString( | |
multipliers: string[], | |
fieldArgs: { [argument: string]: any } | |
): number[]; | |
getArgsFromDirectives( | |
directives: ReadOnlyArray<DirectiveNode>, | |
fieldArgs: { [argument: string]: any } | |
): NodeCostConfiguration; | |
computeNodeCost( | |
node: NodeType, | |
typeDef: Maybe<GraphQLNamedType>, | |
parentMultipliers: number[] | |
): number; | |
createError(): GraphQLError; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment