Skip to content

Commit 01b9e80

Browse files
smartive-nicolai[bot]nicola-smartiveclaudemfeltscher
authored
fix(deps): support graphql 16 and 17 (#503)
* fix(deps): support graphql 16 and 17 Widen the graphql range to ^16.12.0 || ^17.0.0 (dependency + new peerDependency) and adjust the code to the v16-and-v17 API intersection: - errors.ts: use the object-form GraphQLError constructor (the positional form was removed in v17). - resolvers: read info.variableValues via a getVariableValues() helper that handles both v16's plain record and v17's { sources, coerced } shape. Verified: build + lint + full jest suite green against both graphql@16.14.2 and graphql@17.0.1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore: adjust matrix * huebscher * debug * debug * idefix * upgrade packages * fix: green CI after package upgrades (lint + tsc build) The 'upgrade packages' commit regenerated the lockfile, which pulled: - @typescript-eslint 8.63 — now flags the pre-existing union `Knex.RawBinding | Knex.ValueDict` in permissions/check.ts as no-redundant-type-constituents (RawBinding already subsumes it / collapses to any). Neither caller passes a ValueDict, so narrow the param to Knex.RawBinding. - @types/node 25.9.4 (was 25.3.3) — no longer auto-included into the build tsconfig's global scope, so tsc fails with TS2591 (Cannot find name 'process'/'http'/'crypto'). Add "types": ["node"] to tsconfig.json as TS itself recommends; version-independent and the build only needs node globals. Both issues fail 'npm run test' on every matrix cell (lint runs first, so the graphql-16/pg14 cell that finished first is what CI reported; fail-fast cancelled the rest). Verified green under graphql 16 and 17. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * cleanup * types --------- Co-authored-by: Nicola Marcacci Rossi <nicola@smartive.ch> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Moreno Feltscher <moreno@smartive.ch>
1 parent 2fd243a commit 01b9e80

7 files changed

Lines changed: 2233 additions & 1245 deletions

File tree

.github/workflows/testing.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ jobs:
2222
- version: 16
2323
- version: 17
2424
- version: 18
25-
name: test and build package (node ${{ matrix.node.version }}, postgres ${{ matrix.postgres.version }})
25+
graphql:
26+
- version: '16'
27+
spec: '^16.12.0'
28+
- version: '17'
29+
spec: '^17.0.0'
30+
name: test and build package (node ${{ matrix.node.version }}, postgres ${{ matrix.postgres.version }}, graphql ${{ matrix.graphql.version }})
2631
runs-on: ubuntu-latest
2732
container: node:${{ matrix.node.version }}-alpine
2833

@@ -47,6 +52,10 @@ jobs:
4752
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
4853
- name: Install dependencies
4954
run: npm ci
55+
- name: Install graphql ${{ matrix.graphql.spec }}
56+
# --legacy-peer-deps: @graphql-codegen/* still caps its graphql peer at
57+
# ^16, so installing graphql 17 otherwise trips ERESOLVE (see PR #503).
58+
run: npm install graphql@${{ matrix.graphql.spec }} --legacy-peer-deps
5059
- name: Lint
5160
run: npm run lint
5261
- name: Run tests

package-lock.json

Lines changed: 2195 additions & 1231 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,23 @@
4343
"access": "public"
4444
},
4545
"dependencies": {
46-
"@graphql-codegen/add": "^7.0.0",
47-
"@graphql-codegen/cli": "^7.0.0",
48-
"@graphql-codegen/typescript": "^6.0.0",
49-
"@graphql-codegen/typescript-operations": "^6.0.0",
50-
"@graphql-codegen/typescript-resolvers": "^6.0.0",
51-
"@types/node": "^25.0.9",
46+
"@graphql-codegen/add": "^7.1.0",
47+
"@graphql-codegen/cli": "^7.2.0",
48+
"@graphql-codegen/typescript": "^6.1.0",
49+
"@graphql-codegen/typescript-operations": "^6.1.0",
50+
"@graphql-codegen/typescript-resolvers": "^6.1.0",
5251
"code-block-writer": "^13.0.3",
5352
"dayjs": "^1.11.19",
5453
"dotenv": "^17.2.3",
55-
"graphql": "^16.12.0",
5654
"inflection": "^3.0.2",
57-
"knex": "^3.0.1",
5855
"knex-schema-inspector": "^3.1.0",
5956
"lodash": "^4.17.21",
6057
"luxon": "^3.7.2",
6158
"pg": "^8.17.1",
6259
"ts-morph": "^28.0.0"
6360
},
6461
"peerDependencies": {
62+
"graphql": "^16.12.0 || ^17.0.0",
6563
"knex": "^3.0.1"
6664
},
6765
"devDependencies": {
@@ -70,14 +68,17 @@
7068
"@types/jest": "30.0.0",
7169
"@types/lodash": "4.17.24",
7270
"@types/luxon": "3.7.2",
71+
"@types/node": "26.1.0",
7372
"@types/pg": "8.20.0",
7473
"conventional-changelog-conventionalcommits": "10.2.0",
7574
"create-ts-index": "1.14.0",
7675
"del-cli": "7.0.0",
7776
"esbuild": "0.28.1",
7877
"eslint": "9.39.4",
7978
"eslint-import-resolver-typescript": "4.4.5",
79+
"graphql": "17.0.2",
8080
"jest": "30.4.2",
81+
"knex": "3.0.1",
8182
"mock-knex": "0.4.13",
8283
"prettier": "3.9.4",
8384
"ts-jest": "29.4.11",

src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { GraphQLError as GQLError } from 'graphql';
1+
import { GraphQLError as GQLError, GraphQLErrorOptions } from 'graphql';
22
import { PermissionAction } from './permissions/generate';
33

44
export class GraphQLError extends GQLError {
5-
constructor(message: string, extensions: ConstructorParameters<typeof GQLError>[6]) {
6-
super(message, undefined, undefined, undefined, undefined, undefined, extensions);
5+
constructor(message: string, extensions: GraphQLErrorOptions['extensions']) {
6+
super(message, { extensions });
77
}
88
}
99

src/resolvers/arguments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Kind } from 'graphql';
33
import { summonByKey } from '../models/utils';
44
import { Value } from '../values';
55
import { FieldResolverNode } from './node';
6-
import { Maybe, VariableValues } from './utils';
6+
import { getVariableValues, Maybe, VariableValues } from './utils';
77

88
export type Where = Record<string, Value>;
99

@@ -70,7 +70,7 @@ export const normalizeArguments = (node: FieldResolverNode) => {
7070
const normalizedArguments: NormalizedArguments = {};
7171
if (node.field.arguments) {
7272
for (const argument of node.field.arguments) {
73-
const rawValue = getRawValue(argument.value, node.ctx.info.variableValues);
73+
const rawValue = getRawValue(argument.value, getVariableValues(node.ctx.info));
7474
const normalizedValue = normalizeValue(
7575
rawValue,
7676
summonByKey(node.fieldDefinition.arguments || [], 'name.value', argument.name.value).type,

src/resolvers/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
FragmentDefinitionNode,
66
FragmentSpreadNode,
77
GraphQLObjectType,
8+
GraphQLResolveInfo,
89
GraphQLSchema,
910
InlineFragmentNode,
1011
TypeNode,
@@ -23,6 +24,18 @@ export const TYPE_ALIAS = 'TYPE';
2324

2425
export type VariableValues = Record<string, Value>;
2526

27+
// graphql v16 exposes `info.variableValues` as a plain `{ [name]: value }` record,
28+
// whereas graphql v17 wraps it as `{ sources, coerced }` with the runtime values under
29+
// `coerced`. Read both shapes so resolvers work against either major version.
30+
export const getVariableValues = (info: GraphQLResolveInfo): VariableValues => {
31+
const variableValues = info.variableValues as unknown;
32+
if (variableValues && typeof variableValues === 'object' && 'coerced' in variableValues && 'sources' in variableValues) {
33+
return (variableValues as { coerced: VariableValues }).coerced;
34+
}
35+
36+
return variableValues as VariableValues;
37+
};
38+
2639
export const getTypeName = (t: TypeNode): string => {
2740
switch (t.kind) {
2841
case 'ListType':

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"sourceMap": true,
88
"declaration": true,
99
"target": "esnext",
10+
"types": ["node"],
1011
"moduleResolution": "bundler",
1112
"skipLibCheck": true,
1213
"strictNullChecks": true,

0 commit comments

Comments
 (0)