Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
23 KiB
Plaintext
1 line
23 KiB
Plaintext
{"version":3,"sources":["../../../src/packages/graphql-query-complexity/QueryComplexity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n/**\n * Created by Ivo Meißner on 28.07.17.\n */\n\nimport type {\n DocumentNode,\n FieldNode,\n FragmentDefinitionNode,\n FragmentSpreadNode,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLField,\n GraphQLFieldMap,\n GraphQLNamedType,\n GraphQLSchema,\n GraphQLUnionType,\n InlineFragmentNode,\n OperationDefinitionNode,\n} from 'graphql'\n\nimport {\n getNamedType,\n GraphQLError,\n GraphQLInterfaceType,\n GraphQLObjectType,\n isAbstractType,\n isCompositeType,\n Kind,\n TypeInfo,\n ValidationContext,\n visit,\n visitWithTypeInfo,\n} from 'graphql'\nimport {\n getArgumentValues,\n getDirectiveValues,\n getVariableValues,\n} from 'graphql/execution/values.js'\n\nexport type ComplexityEstimatorArgs = {\n args: { [key: string]: any }\n childComplexity: number\n context?: Record<string, any>\n field: GraphQLField<any, any>\n node: FieldNode\n type: GraphQLCompositeType\n}\n\nexport type ComplexityEstimator = (options: ComplexityEstimatorArgs) => number | void\n\n// Complexity can be anything that is supported by the configured estimators\nexport type Complexity = any\n\n// Map of complexities for possible types (of Union, Interface types)\ntype ComplexityMap = {\n [typeName: string]: number\n}\n\nexport interface QueryComplexityOptions {\n // Pass request context to the estimators via estimationContext\n context?: Record<string, any>\n\n // The query variables. This is needed because the variables are not available\n // Optional function to create a custom error\n createError?: (max: number, actual: number) => GraphQLError\n\n // An array of complexity estimators to use for estimating the complexity\n estimators: Array<ComplexityEstimator>\n\n // Optional callback function to retrieve the determined query complexity\n // Will be invoked whether the query is rejected or not\n // The maximum allowed query complexity, queries above this threshold will be rejected\n maximumComplexity: number\n\n // This can be used for logging or to implement rate limiting\n onComplete?: (complexity: number) => void\n\n // specify operation name only when pass multi-operation documents\n operationName?: string\n\n // in the visitor of the graphql-js library\n variables?: Record<string, any>\n}\n\nfunction queryComplexityMessage(max: number, actual: number): string {\n return `The query exceeds the maximum complexity of ${max}. ` + `Actual complexity is ${actual}`\n}\n\nexport function getComplexity(options: {\n context?: Record<string, any>\n estimators: ComplexityEstimator[]\n operationName?: string\n query: DocumentNode\n schema: GraphQLSchema\n variables?: Record<string, any>\n}): number {\n const typeInfo = new TypeInfo(options.schema)\n\n const errors: GraphQLError[] = []\n const context = new ValidationContext(options.schema, options.query, typeInfo, (error) =>\n errors.push(error),\n )\n const visitor = new QueryComplexity(context, {\n // Maximum complexity does not matter since we're only interested in the calculated complexity.\n context: options.context,\n estimators: options.estimators,\n maximumComplexity: Infinity,\n operationName: options.operationName,\n variables: options.variables,\n })\n\n visit(options.query, visitWithTypeInfo(typeInfo, visitor))\n\n // Throw first error if any\n if (errors.length) {\n throw errors.pop()\n }\n\n return visitor.complexity\n}\n\nexport class QueryComplexity {\n complexity: number\n context: ValidationContext\n estimators: Array<ComplexityEstimator>\n includeDirectiveDef: GraphQLDirective\n OperationDefinition: Record<string, any>\n options: QueryComplexityOptions\n requestContext?: Record<string, any>\n skipDirectiveDef: GraphQLDirective\n variableValues: Record<string, any>\n\n constructor(context: ValidationContext, options: QueryComplexityOptions) {\n if (!(typeof options.maximumComplexity === 'number' && options.maximumComplexity > 0)) {\n throw new Error('Maximum query complexity must be a positive number')\n }\n\n this.context = context\n this.complexity = 0\n this.options = options\n\n this.includeDirectiveDef = this.context.getSchema().getDirective('include')\n this.skipDirectiveDef = this.context.getSchema().getDirective('skip')\n this.estimators = options.estimators\n this.variableValues = {}\n this.requestContext = options.context\n\n this.OperationDefinition = {\n enter: this.onOperationDefinitionEnter,\n leave: this.onOperationDefinitionLeave,\n }\n }\n\n createError(): GraphQLError {\n if (typeof this.options.createError === 'function') {\n return this.options.createError(this.options.maximumComplexity, this.complexity)\n }\n return new GraphQLError(queryComplexityMessage(this.options.maximumComplexity, this.complexity))\n }\n\n nodeComplexity(\n node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode,\n typeDef: GraphQLInterfaceType | GraphQLObjectType | GraphQLUnionType,\n ): number {\n if (node.selectionSet) {\n let fields: GraphQLFieldMap<any, any> = {}\n if (typeDef instanceof GraphQLObjectType || typeDef instanceof GraphQLInterfaceType) {\n fields = typeDef.getFields()\n }\n\n // Determine all possible types of the current node\n let possibleTypeNames: string[]\n if (isAbstractType(typeDef)) {\n possibleTypeNames = this.context\n .getSchema()\n .getPossibleTypes(typeDef)\n .map((t) => t.name)\n } else {\n possibleTypeNames = [typeDef.name]\n }\n\n // Collect complexities for all possible types individually\n const selectionSetComplexities: ComplexityMap = node.selectionSet.selections.reduce(\n (\n complexities: ComplexityMap,\n childNode: FieldNode | FragmentSpreadNode | InlineFragmentNode,\n ): ComplexityMap => {\n // let nodeComplexity = 0;\n let innerComplexities = complexities\n\n let includeNode = true\n let skipNode = false\n\n for (const directive of childNode.directives ?? []) {\n const directiveName = directive.name.value\n switch (directiveName) {\n case 'include': {\n const values = getDirectiveValues(\n this.includeDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n includeNode = values.if\n }\n break\n }\n case 'skip': {\n const values = getDirectiveValues(\n this.skipDirectiveDef,\n childNode,\n this.variableValues || {},\n )\n if (typeof values.if === 'boolean') {\n skipNode = values.if\n }\n break\n }\n }\n }\n\n if (!includeNode || skipNode) {\n return complexities\n }\n\n switch (childNode.kind) {\n case Kind.FIELD: {\n const field = fields[childNode.name.value]\n // Invalid field, should be caught by other validation rules\n if (!field) {\n break\n }\n const fieldType = getNamedType(field.type)\n\n // Get arguments\n let args: { [key: string]: any }\n try {\n args = getArgumentValues(field, childNode, this.variableValues || {})\n } catch (e) {\n this.context.reportError(e)\n return complexities\n }\n\n // Check if we have child complexity\n let childComplexity = 0\n if (isCompositeType(fieldType)) {\n childComplexity = this.nodeComplexity(childNode, fieldType)\n }\n\n // Run estimators one after another and return first valid complexity\n // score\n const estimatorArgs: ComplexityEstimatorArgs = {\n type: typeDef,\n args,\n childComplexity,\n context: this.requestContext,\n field,\n node: childNode,\n }\n const validScore = this.estimators.find((estimator) => {\n const tmpComplexity = estimator(estimatorArgs)\n\n if (typeof tmpComplexity === 'number' && !isNaN(tmpComplexity)) {\n innerComplexities = addComplexities(\n tmpComplexity,\n complexities,\n possibleTypeNames,\n )\n return true\n }\n\n return false\n })\n if (!validScore) {\n this.context.reportError(\n new GraphQLError(\n `No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +\n 'At least one complexity estimator has to return a complexity score.',\n ),\n )\n return complexities\n }\n break\n }\n case Kind.FRAGMENT_SPREAD: {\n const fragment = this.context.getFragment(childNode.name.value)\n // Unknown fragment, should be caught by other validation rules\n if (!fragment) {\n break\n }\n const fragmentType = this.context\n .getSchema()\n .getType(fragment.typeCondition.name.value)\n // Invalid fragment type, ignore. Should be caught by other validation rules\n if (!isCompositeType(fragmentType)) {\n break\n }\n const nodeComplexity = this.nodeComplexity(fragment, fragmentType)\n if (isAbstractType(fragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(fragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n fragmentType.name,\n ])\n }\n break\n }\n case Kind.INLINE_FRAGMENT: {\n let inlineFragmentType: GraphQLNamedType = typeDef\n if (childNode.typeCondition && childNode.typeCondition.name) {\n inlineFragmentType = this.context\n .getSchema()\n .getType(childNode.typeCondition.name.value)\n if (!isCompositeType(inlineFragmentType)) {\n break\n }\n }\n\n const nodeComplexity = this.nodeComplexity(childNode, inlineFragmentType)\n if (isAbstractType(inlineFragmentType)) {\n // Add fragment complexity for all possible types\n innerComplexities = addComplexities(\n nodeComplexity,\n complexities,\n this.context\n .getSchema()\n .getPossibleTypes(inlineFragmentType)\n .map((t) => t.name),\n )\n } else {\n // Add complexity for object type\n innerComplexities = addComplexities(nodeComplexity, complexities, [\n inlineFragmentType.name,\n ])\n }\n break\n }\n default: {\n innerComplexities = addComplexities(\n this.nodeComplexity(childNode, typeDef),\n complexities,\n possibleTypeNames,\n )\n break\n }\n }\n\n return innerComplexities\n },\n {},\n )\n // Only return max complexity of all possible types\n if (!selectionSetComplexities) {\n return NaN\n }\n return Math.max(...Object.values(selectionSetComplexities), 0)\n }\n return 0\n }\n\n onOperationDefinitionEnter(operation: OperationDefinitionNode): void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n // Get variable values from variables that are passed from options, merged\n // with default values defined in the operation\n const { coerced, errors } = getVariableValues(\n this.context.getSchema(),\n // We have to create a new array here because input argument is not readonly in graphql ~14.6.0\n operation.variableDefinitions ? [...operation.variableDefinitions] : [],\n this.options.variables ?? {},\n )\n if (errors && errors.length) {\n // We have input validation errors, report errors and abort\n errors.forEach((error) => this.context.reportError(error))\n return\n }\n this.variableValues = coerced\n\n switch (operation.operation) {\n case 'mutation':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getMutationType(),\n )\n break\n case 'query':\n this.complexity += this.nodeComplexity(operation, this.context.getSchema().getQueryType())\n break\n case 'subscription':\n this.complexity += this.nodeComplexity(\n operation,\n this.context.getSchema().getSubscriptionType(),\n )\n break\n default:\n throw new Error(\n `Query complexity could not be calculated for operation of type ${operation.operation}`,\n )\n }\n }\n\n onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void {\n if (\n typeof this.options.operationName === 'string' &&\n this.options.operationName !== operation.name.value\n ) {\n return\n }\n\n if (this.options.onComplete) {\n this.options.onComplete(this.complexity)\n }\n\n if (this.complexity > this.options.maximumComplexity) {\n return this.context.reportError(this.createError())\n }\n }\n}\n\n/**\n * Adds a complexity to the complexity map for all possible types\n * @param complexity\n * @param complexityMap\n * @param possibleTypes\n */\nfunction addComplexities(\n complexity: number,\n complexityMap: ComplexityMap,\n possibleTypes: string[],\n): ComplexityMap {\n for (const type of possibleTypes) {\n if (Object.prototype.hasOwnProperty.call(complexityMap, type)) {\n complexityMap[type] += complexity\n } else {\n complexityMap[type] = complexity\n }\n }\n return complexityMap\n}\n"],"names":["getNamedType","GraphQLError","GraphQLInterfaceType","GraphQLObjectType","isAbstractType","isCompositeType","Kind","TypeInfo","ValidationContext","visit","visitWithTypeInfo","getArgumentValues","getDirectiveValues","getVariableValues","queryComplexityMessage","max","actual","getComplexity","options","typeInfo","schema","errors","context","query","error","push","visitor","QueryComplexity","estimators","maximumComplexity","Infinity","operationName","variables","length","pop","complexity","includeDirectiveDef","OperationDefinition","requestContext","skipDirectiveDef","variableValues","Error","getSchema","getDirective","enter","onOperationDefinitionEnter","leave","onOperationDefinitionLeave","createError","nodeComplexity","node","typeDef","selectionSet","fields","getFields","possibleTypeNames","getPossibleTypes","map","t","name","selectionSetComplexities","selections","reduce","complexities","childNode","innerComplexities","includeNode","skipNode","directive","directives","directiveName","value","values","if","kind","FIELD","field","fieldType","type","args","e","reportError","childComplexity","estimatorArgs","validScore","find","estimator","tmpComplexity","isNaN","addComplexities","FRAGMENT_SPREAD","fragment","getFragment","fragmentType","getType","typeCondition","INLINE_FRAGMENT","inlineFragmentType","NaN","Math","Object","operation","coerced","variableDefinitions","forEach","getMutationType","getQueryType","getSubscriptionType","onComplete","complexityMap","possibleTypes","prototype","hasOwnProperty","call"],"mappings":"AAAA,qDAAqD,GAErD,+DAA+D,GAC/D;;CAEC,GAkBD,SACEA,YAAY,EACZC,YAAY,EACZC,oBAAoB,EACpBC,iBAAiB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