graphql-query-complexity
Advanced tools
Comparing version 0.12.0 to 1.0.0
@@ -47,4 +47,4 @@ /** | ||
onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void; | ||
nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode, typeDef: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType): number; | ||
nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode, typeDef: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | undefined): number; | ||
createError(): GraphQLError; | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.getComplexity = void 0; | ||
const values_js_1 = require("graphql/execution/values.js"); | ||
const values_1 = require("graphql/execution/values"); | ||
const graphql_1 = require("graphql"); | ||
@@ -63,3 +63,3 @@ function queryComplexityMessage(max, actual) { | ||
// with default values defined in the operation | ||
const { coerced, errors } = (0, values_js_1.getVariableValues)(this.context.getSchema(), | ||
const { coerced, errors } = (0, values_1.getVariableValues)(this.context.getSchema(), | ||
// We have to create a new array here because input argument is not readonly in graphql ~14.6.0 | ||
@@ -100,3 +100,3 @@ operation.variableDefinitions ? [...operation.variableDefinitions] : [], (_a = this.options.variables) !== null && _a !== void 0 ? _a : {}); | ||
nodeComplexity(node, typeDef) { | ||
if (node.selectionSet) { | ||
if (node.selectionSet && typeDef) { | ||
let fields = {}; | ||
@@ -129,3 +129,3 @@ if (typeDef instanceof graphql_1.GraphQLObjectType || | ||
case 'include': { | ||
const values = (0, values_js_1.getDirectiveValues)(this.includeDirectiveDef, childNode, this.variableValues || {}); | ||
const values = (0, values_1.getDirectiveValues)(this.includeDirectiveDef, childNode, this.variableValues || {}); | ||
if (typeof values.if === 'boolean') { | ||
@@ -137,3 +137,3 @@ includeNode = values.if; | ||
case 'skip': { | ||
const values = (0, values_js_1.getDirectiveValues)(this.skipDirectiveDef, childNode, this.variableValues || {}); | ||
const values = (0, values_1.getDirectiveValues)(this.skipDirectiveDef, childNode, this.variableValues || {}); | ||
if (typeof values.if === 'boolean') { | ||
@@ -151,3 +151,17 @@ skipNode = values.if; | ||
case graphql_1.Kind.FIELD: { | ||
const field = fields[childNode.name.value]; | ||
let field = null; | ||
switch (childNode.name.value) { | ||
case graphql_1.SchemaMetaFieldDef.name: | ||
field = graphql_1.SchemaMetaFieldDef; | ||
break; | ||
case graphql_1.TypeMetaFieldDef.name: | ||
field = graphql_1.TypeMetaFieldDef; | ||
break; | ||
case graphql_1.TypeNameMetaFieldDef.name: | ||
field = graphql_1.TypeNameMetaFieldDef; | ||
break; | ||
default: | ||
field = fields[childNode.name.value]; | ||
break; | ||
} | ||
// Invalid field, should be caught by other validation rules | ||
@@ -161,3 +175,3 @@ if (!field) { | ||
try { | ||
args = (0, values_js_1.getArgumentValues)(field, childNode, this.variableValues || {}); | ||
args = (0, values_1.getArgumentValues)(field, childNode, this.variableValues || {}); | ||
} | ||
@@ -164,0 +178,0 @@ catch (e) { |
@@ -47,4 +47,4 @@ /** | ||
onOperationDefinitionLeave(operation: OperationDefinitionNode): GraphQLError | void; | ||
nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode, typeDef: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType): number; | ||
nodeComplexity(node: FieldNode | FragmentDefinitionNode | InlineFragmentNode | OperationDefinitionNode, typeDef: GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | undefined): number; | ||
createError(): GraphQLError; | ||
} |
@@ -6,4 +6,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
*/ | ||
import { getArgumentValues, getDirectiveValues, getVariableValues, } from 'graphql/execution/values.js'; | ||
import { ValidationContext, isCompositeType, TypeInfo, visit, visitWithTypeInfo, isAbstractType, GraphQLObjectType, GraphQLInterfaceType, Kind, getNamedType, GraphQLError, } from 'graphql'; | ||
import { getArgumentValues, getDirectiveValues, getVariableValues, } from 'graphql/execution/values'; | ||
import { ValidationContext, isCompositeType, TypeInfo, visit, visitWithTypeInfo, isAbstractType, GraphQLObjectType, GraphQLInterfaceType, Kind, getNamedType, GraphQLError, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql'; | ||
function queryComplexityMessage(max, actual) { | ||
@@ -95,3 +95,3 @@ return (`The query exceeds the maximum complexity of ${max}. ` + | ||
nodeComplexity(node, typeDef) { | ||
if (node.selectionSet) { | ||
if (node.selectionSet && typeDef) { | ||
let fields = {}; | ||
@@ -144,3 +144,17 @@ if (typeDef instanceof GraphQLObjectType || | ||
case Kind.FIELD: { | ||
const field = fields[childNode.name.value]; | ||
let field = null; | ||
switch (childNode.name.value) { | ||
case SchemaMetaFieldDef.name: | ||
field = SchemaMetaFieldDef; | ||
break; | ||
case TypeMetaFieldDef.name: | ||
field = TypeMetaFieldDef; | ||
break; | ||
case TypeNameMetaFieldDef.name: | ||
field = TypeNameMetaFieldDef; | ||
break; | ||
default: | ||
field = fields[childNode.name.value]; | ||
break; | ||
} | ||
// Invalid field, should be caught by other validation rules | ||
@@ -147,0 +161,0 @@ if (!field) { |
{ | ||
"name": "graphql-query-complexity", | ||
"version": "0.12.0", | ||
"version": "1.0.0", | ||
"description": "Validation rule for GraphQL query complexity analysis", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
55355
959
1