Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
node-version: [20, 22, 24, 26]
graphql-version: ['~15.0', '~16.0']
graphql-version: ['~15.0', '~16.0', '~17.0']
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lodash.get": "^4.4.2"
},
"peerDependencies": {
"graphql": "^15.0.0 || ^16.0.0"
"graphql": "^15.0.0 || ^16.0.0 || ^17.0.0"
},
"files": [
"dist",
Expand Down Expand Up @@ -66,7 +66,7 @@
"@typescript-eslint/parser": "^5.1.0",
"chai": "^4.3.4",
"eslint": "^8.0.1",
"graphql": "~14.6.0 || ~15.0.0 || ~16.0.0",
"graphql": "~14.6.0 || ~15.0.0 || ~16.0.0 || ~17.0.0",
"mocha": "^11.7.6",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
28 changes: 27 additions & 1 deletion src/QueryComplexity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ValidationContext,
FragmentDefinitionNode,
OperationDefinitionNode,
VariableDefinitionNode,
FieldNode,
FragmentSpreadNode,
InlineFragmentNode,
Expand Down Expand Up @@ -187,7 +188,7 @@

// Get variable values from variables that are passed from options, merged
// with default values defined in the operation
const { coerced, errors } = getVariableValues(
const { coerced, errors } = getCoercedVariableValues(
this.context.getSchema(),
// We have to create a new array here because input argument is not readonly in graphql ~14.6.0
operation.variableDefinitions ? [...operation.variableDefinitions] : [],
Expand Down Expand Up @@ -303,7 +304,7 @@
const values = getDirectiveValues(
this.includeDirectiveDef,
childNode,
this.variableValues || {}

Check failure on line 307 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (24, ~17.0)

Argument of type 'Record<string, any>' is not assignable to parameter of type 'VariableValues'.

Check failure on line 307 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (22, ~17.0)

Argument of type 'Record<string, any>' is not assignable to parameter of type 'VariableValues'.
);
if (typeof values.if === 'boolean') {
includeNode = values.if;
Expand All @@ -314,7 +315,7 @@
const values = getDirectiveValues(
this.skipDirectiveDef,
childNode,
this.variableValues || {}

Check failure on line 318 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (24, ~17.0)

Argument of type 'Record<string, any>' is not assignable to parameter of type 'VariableValues'.

Check failure on line 318 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (22, ~17.0)

Argument of type 'Record<string, any>' is not assignable to parameter of type 'VariableValues'.
);
if (typeof values.if === 'boolean') {
skipNode = values.if;
Expand All @@ -329,7 +330,7 @@
}

switch (childNode.kind) {
case Kind.FIELD: {

Check failure on line 333 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (24, ~17.0)

'Kind' only refers to a type, but is being used as a value here.

Check failure on line 333 in src/QueryComplexity.ts

View workflow job for this annotation

GitHub Actions / test-and-build (22, ~17.0)

'Kind' only refers to a type, but is being used as a value here.
let field = null;

switch (childNode.name.value) {
Expand Down Expand Up @@ -534,6 +535,31 @@
}
}

/**
* GraphQL v17 changed getVariableValues() to return { variableValues }
* instead of { coerced }. This helper supports both shapes.
*/
function getCoercedVariableValues(
schema: GraphQLSchema,
variableDefinitions: readonly VariableDefinitionNode[],
inputs: Record<string, any>
): { coerced: Record<string, any>; errors?: ReadonlyArray<GraphQLError> } {
const result = getVariableValues(
schema,
variableDefinitions ?? [],
inputs
) as {
coerced?: Record<string, any>;
variableValues?: { coerced: Record<string, any> };
errors?: ReadonlyArray<GraphQLError>;
};

return {
coerced: result.variableValues?.coerced ?? result.coerced ?? {},
errors: result.errors,
};
}

/**
* Adds a complexity to the complexity map for all possible types
* @param complexity
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ globby@^11.0.4:
merge2 "^1.3.0"
slash "^3.0.0"

"graphql@~14.6.0 || ~15.0.0 || ~16.0.0":
"graphql@~14.6.0 || ~15.0.0 || ~16.0.0 || ~17.0.0":
version "16.0.1"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.0.1.tgz#93a13cd4e0e38ca8d0832e79614c8578bfd34f10"
integrity sha512-oPvCuu6dlLdiz8gZupJ47o1clgb72r1u8NDBcQYjcV6G/iEdmE11B1bBlkhXRvV0LisP/SXRFP7tT6AgaTjpzg==
Expand Down
Loading