diff --git a/.changeset/rare-schools-judge.md b/.changeset/rare-schools-judge.md new file mode 100644 index 00000000000..89d8c7d17ea --- /dev/null +++ b/.changeset/rare-schools-judge.md @@ -0,0 +1,6 @@ +--- +'@graphql-tools/links': patch +'@graphql-tools/utils': patch +--- + +Fix GraphQL v17 incompatibility issues and introduce `createGraphQLError` helper function for backwards compatibility. diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81afe8f1cc4..005c03fe540 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -77,6 +77,7 @@ jobs: - 14 - 15 - 16 + - '17.0.0-alpha.1' steps: - name: Checkout Master uses: actions/checkout@v3 @@ -117,6 +118,7 @@ jobs: - 14 - 15 - 16 + - '17.0.0-alpha.1' include: - node-version: 14 os: windows-latest diff --git a/jest.config.js b/jest.config.js index 44a3d699aa5..bfa9306f0f7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,4 +15,5 @@ module.exports = { moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: `${ROOT_DIR}/` }), collectCoverage: false, cacheDirectory: resolve(ROOT_DIR, `${CI ? '' : 'node_modules/'}.cache/jest`), + transformIgnorePatterns: ['node_modules/(?!graphql)'], }; diff --git a/packages/batch-delegate/package.json b/packages/batch-delegate/package.json index a092ac7515e..cf0771c5dd5 100644 --- a/packages/batch-delegate/package.json +++ b/packages/batch-delegate/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/batch-execute/package.json b/packages/batch-execute/package.json index 670a532c0a5..ab7c96ed336 100644 --- a/packages/batch-execute/package.json +++ b/packages/batch-execute/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/delegate/package.json b/packages/delegate/package.json index 3d0278c765c..0ac50f816da 100644 --- a/packages/delegate/package.json +++ b/packages/delegate/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/delegate/tests/errors.test.ts b/packages/delegate/tests/errors.test.ts index dae85c6e209..8bcf0cb8df7 100644 --- a/packages/delegate/tests/errors.test.ts +++ b/packages/delegate/tests/errors.test.ts @@ -1,7 +1,7 @@ import { GraphQLError, GraphQLResolveInfo, locatedError, graphql, OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; -import { ExecutionResult } from '@graphql-tools/utils'; +import { createGraphQLError, ExecutionResult } from '@graphql-tools/utils'; import { stitchSchemas } from '@graphql-tools/stitch'; import { checkResultAndHandleErrors } from '../src/checkResultAndHandleErrors'; @@ -9,12 +9,6 @@ import { UNPATHED_ERRORS_SYMBOL } from '../src/symbols'; import { getUnpathedErrors } from '../src/mergeFields'; import { delegateToSchema, defaultMergedResolver, DelegationContext } from '../src'; -class ErrorWithExtensions extends GraphQLError { - constructor(message: string, code: string) { - super(message, null as any, null, null, null, null, { code }); - } -} - describe('Errors', () => { describe('getUnpathedErrors', () => { test('should return all unpathed errors', () => { @@ -61,7 +55,13 @@ describe('Errors', () => { test('persists single error with extensions', () => { const result = { - errors: [new ErrorWithExtensions('Test error', 'UNAUTHENTICATED')], + errors: [ + createGraphQLError('Test error', { + extensions: { + code: 'UNAUTHENTICATED', + }, + }), + ], }; try { checkResultAndHandleErrors(result, { diff --git a/packages/graphql-tag-pluck/package.json b/packages/graphql-tag-pluck/package.json index 65787cb4765..b897cefa8e3 100644 --- a/packages/graphql-tag-pluck/package.json +++ b/packages/graphql-tag-pluck/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@babel/parser": "^7.16.8", diff --git a/packages/graphql-tools/package.json b/packages/graphql-tools/package.json index 60b97e8316e..48bf78ad1e5 100644 --- a/packages/graphql-tools/package.json +++ b/packages/graphql-tools/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "optionalDependencies": { "@apollo/client": "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0" diff --git a/packages/import/package.json b/packages/import/package.json index 48f1f575b8f..3580f767523 100644 --- a/packages/import/package.json +++ b/packages/import/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "publishConfig": { "access": "public", diff --git a/packages/jest-transform/package.json b/packages/jest-transform/package.json index 856d6fedbae..0932f99ad87 100644 --- a/packages/jest-transform/package.json +++ b/packages/jest-transform/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/links/package.json b/packages/links/package.json index d82104f4465..d4e2385c796 100644 --- a/packages/links/package.json +++ b/packages/links/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0", + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0", "@apollo/client": "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0" }, "buildOptions": { diff --git a/packages/links/src/GraphQLUpload.ts b/packages/links/src/GraphQLUpload.ts index f293bbe4f48..9e72b136f5e 100644 --- a/packages/links/src/GraphQLUpload.ts +++ b/packages/links/src/GraphQLUpload.ts @@ -1,4 +1,5 @@ -import { GraphQLScalarType, GraphQLError } from 'graphql'; +import { GraphQLScalarType } from 'graphql'; +import { createGraphQLError } from '@graphql-tools/utils'; const GraphQLUpload = new GraphQLScalarType({ name: 'Upload', @@ -15,7 +16,9 @@ const GraphQLUpload = new GraphQLScalarType({ // serialization requires to support schema stitching serialize: value => value, parseLiteral: ast => { - throw new GraphQLError('Upload literal unsupported.', ast); + throw createGraphQLError('Upload scalar literal unsupported', { + nodes: ast, + }); }, }); diff --git a/packages/load-files/package.json b/packages/load-files/package.json index b8a14adb58c..9373ccc302c 100644 --- a/packages/load-files/package.json +++ b/packages/load-files/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "globby": "11.1.0", diff --git a/packages/load/package.json b/packages/load/package.json index cfa980b32cb..08f24abe87a 100644 --- a/packages/load/package.json +++ b/packages/load/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "devDependencies": { "graphql-tag": "2.12.6", diff --git a/packages/loaders/apollo-engine/package.json b/packages/loaders/apollo-engine/package.json index d236d3b56ef..471351cde4b 100644 --- a/packages/loaders/apollo-engine/package.json +++ b/packages/loaders/apollo-engine/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/loaders/code-file/package.json b/packages/loaders/code-file/package.json index a3641f952d7..31d1c8cf289 100644 --- a/packages/loaders/code-file/package.json +++ b/packages/loaders/code-file/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/loaders/git/package.json b/packages/loaders/git/package.json index e3899a42de5..6683231a8d6 100644 --- a/packages/loaders/git/package.json +++ b/packages/loaders/git/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/graphql-tag-pluck": "7.2.8", diff --git a/packages/loaders/github/package.json b/packages/loaders/github/package.json index 47477a5856b..f42a2f22f35 100644 --- a/packages/loaders/github/package.json +++ b/packages/loaders/github/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/loaders/graphql-file/package.json b/packages/loaders/graphql-file/package.json index df969ddef83..ebd8e007ff5 100644 --- a/packages/loaders/graphql-file/package.json +++ b/packages/loaders/graphql-file/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/loaders/json-file/package.json b/packages/loaders/json-file/package.json index 4d71b072ebc..587ad4ffd57 100644 --- a/packages/loaders/json-file/package.json +++ b/packages/loaders/json-file/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/loaders/module/package.json b/packages/loaders/module/package.json index 766456b0261..48f3f2f6123 100644 --- a/packages/loaders/module/package.json +++ b/packages/loaders/module/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/loaders/prisma/package.json b/packages/loaders/prisma/package.json index 5ebc3d94398..16d9f84d67d 100644 --- a/packages/loaders/prisma/package.json +++ b/packages/loaders/prisma/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/url-loader": "7.9.22", diff --git a/packages/loaders/url/package.json b/packages/loaders/url/package.json index 19ed0a48746..39bba445cb9 100644 --- a/packages/loaders/url/package.json +++ b/packages/loaders/url/package.json @@ -32,7 +32,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "devDependencies": { "@envelop/live-query": "3.3.2", diff --git a/packages/merge/package.json b/packages/merge/package.json index 13d2c4b2690..36769b6ddde 100644 --- a/packages/merge/package.json +++ b/packages/merge/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/mock/package.json b/packages/mock/package.json index e8ed2fbc2df..240b54256d6 100644 --- a/packages/mock/package.json +++ b/packages/mock/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/node-require/package.json b/packages/node-require/package.json index 52a502f0607..2a5449fdcda 100644 --- a/packages/node-require/package.json +++ b/packages/node-require/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/optimize/package.json b/packages/optimize/package.json index 265311204c1..9587d81bcbf 100644 --- a/packages/optimize/package.json +++ b/packages/optimize/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/relay-operation-optimizer/package.json b/packages/relay-operation-optimizer/package.json index 74ec0d9ed2a..3fbc24b1446 100644 --- a/packages/relay-operation-optimizer/package.json +++ b/packages/relay-operation-optimizer/package.json @@ -38,7 +38,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "dependencies": { "@graphql-tools/utils": "8.6.11", diff --git a/packages/resolvers-composition/package.json b/packages/resolvers-composition/package.json index 7513a2e8131..61751c953b2 100644 --- a/packages/resolvers-composition/package.json +++ b/packages/resolvers-composition/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "devDependencies": { "@types/lodash": "4.14.182", diff --git a/packages/schema/package.json b/packages/schema/package.json index 063f15c3456..4317a5be4d4 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "devDependencies": { "graphql-scalars": "1.17.0" diff --git a/packages/stitch/package.json b/packages/stitch/package.json index b6db22d2dcc..a5b3edb82a5 100644 --- a/packages/stitch/package.json +++ b/packages/stitch/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/stitch/src/typeFromAST.ts b/packages/stitch/src/typeFromAST.ts index 356d91a776d..4edde716393 100644 --- a/packages/stitch/src/typeFromAST.ts +++ b/packages/stitch/src/typeFromAST.ts @@ -26,10 +26,9 @@ import { getDirectiveValues, GraphQLDeprecatedDirective, TypeDefinitionNode, - DirectiveLocationEnum, } from 'graphql'; -import { createStub, createNamedStub, Maybe, getDescription } from '@graphql-tools/utils'; +import { createStub, createNamedStub, Maybe, getDescription, DirectiveLocationEnum } from '@graphql-tools/utils'; const backcompatOptions = { commentDescriptions: true }; diff --git a/packages/stitch/tests/alternateStitchSchemas.test.ts b/packages/stitch/tests/alternateStitchSchemas.test.ts index daf2641c859..f97f3a09024 100644 --- a/packages/stitch/tests/alternateStitchSchemas.test.ts +++ b/packages/stitch/tests/alternateStitchSchemas.test.ts @@ -14,7 +14,6 @@ import { Kind, execute, OperationTypeNode, - GraphQLError, } from 'graphql'; import { @@ -36,7 +35,7 @@ import { import { delegateToSchema, SubschemaConfig } from '@graphql-tools/delegate'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { addMocksToSchema } from '@graphql-tools/mock'; -import { filterSchema, ExecutionResult, assertSome } from '@graphql-tools/utils'; +import { filterSchema, ExecutionResult, assertSome, createGraphQLError } from '@graphql-tools/utils'; import { stitchSchemas } from '../src/stitchSchemas'; @@ -728,7 +727,11 @@ describe('transform object fields', () => { }); const expectedResult: ExecutionResult = { - errors: [new GraphQLError('Cannot query field "id" on type "Item".', undefined, undefined, [17, 6])], + errors: [ + createGraphQLError('Cannot query field "id" on type "Item".', { + positions: [17, 6], + }), + ], }; expect(result).toEqual(expectedResult); @@ -816,15 +819,13 @@ type Query { }, }, errors: [ - new GraphQLError( - 'Property.error error', - undefined, - undefined, - [13, 9], - ['propertyById, new_error'], - undefined, - { code: 'SOME_CUSTOM_CODE' } - ), + createGraphQLError('Property.error error', { + positions: [13, 9], + path: ['propertyById', 'new_error'], + extensions: { + code: 'SOME_CUSTOM_CODE', + }, + }), ], }; @@ -980,7 +981,10 @@ describe('WrapType', () => { }, }, errors: [ - new GraphQLError('Booking.error error', undefined, undefined, [15, 8], ['namespace', 'bookingById, error']), + createGraphQLError('Booking.error error', { + positions: [15, 8], + path: ['namespace', 'bookingById', 'error'], + }), ], }; @@ -1030,7 +1034,10 @@ describe('WrapType', () => { }, }, errors: [ - new GraphQLError('Booking.error error', undefined, undefined, [15, 9], ['namespace', 'addBooking', 'error']), + createGraphQLError('Booking.error error', { + positions: [15, 9], + path: ['namespace', 'addBooking', 'error'], + }), ], }; @@ -1289,15 +1296,13 @@ describe('schema transformation with wrapping of object fields', () => { }, }, errors: [ - new GraphQLError( - 'Property.error error', - undefined, - undefined, - [13, 14], - ['propertyById', 'test1', 'two'], - undefined, - { code: 'SOME_CUSTOM_CODE' } - ), + createGraphQLError('Property.error error', { + positions: [13, 14], + path: ['propertyById', 'test1', 'two'], + extensions: { + code: 'SOME_CUSTOM_CODE', + }, + }), ], }; @@ -1359,15 +1364,13 @@ describe('schema transformation with wrapping of object fields', () => { }, }, errors: [ - new GraphQLError( - 'Property.error error', - undefined, - undefined, - [13, 18], - ['propertyById', 'test1', 'innerWrap', 'two'], - undefined, - { code: 'SOME_CUSTOM_CODE' } - ), + createGraphQLError('Property.error error', { + positions: [13, 18], + path: ['propertyById', 'test1', 'innerWrap', 'two'], + extensions: { + code: 'SOME_CUSTOM_CODE', + }, + }), ], }; diff --git a/packages/stitch/tests/errors.test.ts b/packages/stitch/tests/errors.test.ts index 07cce8eba63..0fdcff2bfd6 100644 --- a/packages/stitch/tests/errors.test.ts +++ b/packages/stitch/tests/errors.test.ts @@ -2,7 +2,7 @@ import { graphql, GraphQLError, buildSchema } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { stitchSchemas } from '@graphql-tools/stitch'; -import { assertSome, ExecutionResult, Executor } from '@graphql-tools/utils'; +import { assertSome, createGraphQLError, ExecutionResult, Executor } from '@graphql-tools/utils'; describe('passes along errors for missing fields on list', () => { test('if non-null', async () => { @@ -227,7 +227,11 @@ describe('passes along errors for remote schemas', () => { const expectedResult: ExecutionResult = { data: null, - errors: [new GraphQLError('INVALID_CREDENTIALS', undefined, undefined, undefined, ['test'])], + errors: [ + createGraphQLError('INVALID_CREDENTIALS', { + path: ['test'], + }), + ], }; const query = /* GraphQL */ ` diff --git a/packages/stitch/tests/stitchSchemas.test.ts b/packages/stitch/tests/stitchSchemas.test.ts index 0633a765fa7..ed022e21c81 100644 --- a/packages/stitch/tests/stitchSchemas.test.ts +++ b/packages/stitch/tests/stitchSchemas.test.ts @@ -8,13 +8,18 @@ import { printSchema, GraphQLResolveInfo, OperationTypeNode, - GraphQLError, } from 'graphql'; import { delegateToSchema, SubschemaConfig } from '@graphql-tools/delegate'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { stitchSchemas } from '../src/stitchSchemas'; -import { getResolversFromSchema, IResolvers, ExecutionResult, assertSome } from '@graphql-tools/utils'; +import { + getResolversFromSchema, + IResolvers, + ExecutionResult, + assertSome, + createGraphQLError, +} from '@graphql-tools/utils'; import { addMocksToSchema } from '@graphql-tools/mock'; @@ -843,13 +848,10 @@ bookingById(id: "b1") { }, } as any, errors: [ - new GraphQLError( - 'subscription field error', - undefined, - undefined, - [4, 15], - ['notifications', 'throwError'] - ), + createGraphQLError('subscription field error', { + positions: [4, 15], + path: ['notifications', 'throwError'], + }), ], }; @@ -2504,9 +2506,11 @@ bookingById(id: "b1") { expect(stitchedResult2.data).toBe(null); assertSome(stitchedResult2.errors); expect(stitchedResult2.errors.map(removeLocations)).toEqual( - [new GraphQLError('Sample error non-null!', undefined, undefined, undefined, ['errorTestNonNull'])].map( - removeLocations - ) + [ + createGraphQLError('Sample error non-null!', { + path: ['errorTestNonNull'], + }), + ].map(removeLocations) ); }); @@ -2556,60 +2560,36 @@ bookingById(id: "b1") { const errorsWithoutLocations = result.errors.map(removeLocations); const expectedErrors = [ - new GraphQLError( - 'Property.error error', - undefined, - undefined, - undefined, - ['propertyById', 'error'], - undefined, - { code: 'SOME_CUSTOM_CODE' } - ), - new GraphQLError( - 'Property.error error', - undefined, - undefined, - undefined, - ['propertyById', 'errorAlias'], - undefined, - { code: 'SOME_CUSTOM_CODE' } - ), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 0, - 'error', - ]), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 0, - 'bookingErrorAlias', - ]), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 1, - 'error', - ]), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 1, - 'bookingErrorAlias', - ]), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 2, - 'error', - ]), - new GraphQLError('Booking.error error', undefined, undefined, undefined, [ - 'propertyById', - 'bookings', - 2, - 'bookingErrorAlias', - ]), + createGraphQLError('Property.error error', { + path: ['propertyById', 'error'], + extensions: { + code: 'SOME_CUSTOM_CODE', + }, + }), + createGraphQLError('Property.error error', { + path: ['propertyById', 'errorAlias'], + extensions: { + code: 'SOME_CUSTOM_CODE', + }, + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 0, 'error'], + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 0, 'bookingErrorAlias'], + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 1, 'error'], + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 1, 'bookingErrorAlias'], + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 2, 'error'], + }), + createGraphQLError('Booking.error error', { + path: ['propertyById', 'bookings', 2, 'bookingErrorAlias'], + }), ].map(removeLocations); expect(errorsWithoutLocations).toEqual(expectedErrors.map(removeLocations)); diff --git a/packages/stitching-directives/package.json b/packages/stitching-directives/package.json index 61b7cd6d83d..7400ea81290 100644 --- a/packages/stitching-directives/package.json +++ b/packages/stitching-directives/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/testing/fixtures/schemas.ts b/packages/testing/fixtures/schemas.ts index c5c654acfc2..43adaaaa056 100644 --- a/packages/testing/fixtures/schemas.ts +++ b/packages/testing/fixtures/schemas.ts @@ -1,26 +1,12 @@ import { PubSub } from 'graphql-subscriptions'; -import { - GraphQLSchema, - Kind, - GraphQLScalarType, - ValueNode, - GraphQLResolveInfo, - GraphQLError, - GraphQLInterfaceType, -} from 'graphql'; +import { GraphQLSchema, Kind, GraphQLScalarType, ValueNode, GraphQLResolveInfo, GraphQLInterfaceType } from 'graphql'; import { introspectSchema } from '@graphql-tools/wrap'; -import { AsyncExecutor, IResolvers } from '@graphql-tools/utils'; +import { AsyncExecutor, createGraphQLError, IResolvers } from '@graphql-tools/utils'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { SubschemaConfig, createDefaultExecutor } from '@graphql-tools/delegate'; -export class CustomError extends GraphQLError { - constructor(message: string, extensions: Record) { - super(message, undefined, undefined, undefined, undefined, undefined, extensions); - } -} - export type Location = { name: string; coordinates: string; @@ -403,8 +389,10 @@ const propertyResolvers: IResolvers = { Property: { error() { - throw new CustomError('Property.error error', { - code: 'SOME_CUSTOM_CODE', + throw createGraphQLError('Property.error error', { + extensions: { + code: 'SOME_CUSTOM_CODE', + }, }); }, }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 06e22a088cc..80065277fef 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -27,7 +27,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "devDependencies": { "@types/dateformat": "3.0.1", diff --git a/packages/utils/src/errors.ts b/packages/utils/src/errors.ts index 27693349367..a34771f8bd0 100644 --- a/packages/utils/src/errors.ts +++ b/packages/utils/src/errors.ts @@ -1,13 +1,41 @@ -import { GraphQLError } from 'graphql'; +import { ASTNode, GraphQLError, Source, versionInfo } from 'graphql'; +import { Maybe } from './types'; -export function relocatedError(originalError: GraphQLError, path?: ReadonlyArray): GraphQLError { - return new GraphQLError( - originalError.message, - originalError.nodes, - originalError.source, - originalError.positions, - path === null ? undefined : path === undefined ? originalError.path : path, - originalError.originalError, - originalError.extensions +interface GraphQLErrorOptions { + nodes?: ReadonlyArray | ASTNode | null; + source?: Maybe; + positions?: Maybe>; + path?: Maybe>; + originalError?: Maybe< + Error & { + readonly extensions?: unknown; + } + >; + extensions?: any; +} + +export function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError { + if (versionInfo.major >= 17) { + return new (GraphQLError as any)(message, options); + } + return new (GraphQLError as any)( + message, + options?.nodes, + options?.source, + options?.positions, + options?.path, + options?.originalError, + options?.extensions ); } + +export function relocatedError(originalError: GraphQLError, path?: ReadonlyArray): GraphQLError { + return createGraphQLError(originalError.message, { + nodes: originalError.nodes, + source: originalError.source, + positions: originalError.positions, + path: path == null ? originalError.path : path, + originalError, + extensions: originalError.extensions, + }); +} diff --git a/packages/utils/src/getArgumentValues.ts b/packages/utils/src/getArgumentValues.ts index 260a8c9d40c..b8c5352f833 100644 --- a/packages/utils/src/getArgumentValues.ts +++ b/packages/utils/src/getArgumentValues.ts @@ -5,11 +5,11 @@ import { DirectiveNode, FieldNode, isNonNullType, - GraphQLError, Kind, print, ArgumentNode, } from 'graphql'; +import { createGraphQLError } from './errors'; import { inspect } from './inspect'; @@ -52,10 +52,9 @@ export function getArgumentValues( if (defaultValue !== undefined) { coercedValues[name] = defaultValue; } else if (isNonNullType(argType)) { - throw new GraphQLError( - `Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', - node - ); + throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', { + nodes: [node], + }); } continue; } @@ -69,10 +68,12 @@ export function getArgumentValues( if (defaultValue !== undefined) { coercedValues[name] = defaultValue; } else if (isNonNullType(argType)) { - throw new GraphQLError( + throw createGraphQLError( `Argument "${name}" of required type "${inspect(argType)}" ` + `was provided the variable "$${variableName}" which was not provided a runtime value.`, - valueNode + { + nodes: [valueNode], + } ); } continue; @@ -81,10 +82,9 @@ export function getArgumentValues( } if (isNull && isNonNullType(argType)) { - throw new GraphQLError( - `Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', - valueNode - ); + throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', { + nodes: [valueNode], + }); } const coercedValue = valueFromAST(valueNode, argType, variableValues); @@ -92,7 +92,9 @@ export function getArgumentValues( // Note: ValuesOfCorrectTypeRule validation should catch this before // execution. This is a runtime check to ensure execution does not // continue with an invalid argument value. - throw new GraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, valueNode); + throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, { + nodes: [valueNode], + }); } coercedValues[name] = coercedValue; } diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 74d94b87cad..2d65c4c2dcc 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -62,3 +62,29 @@ export type InputObjectValueTransformer = ( // GraphQL v14 doesn't have it. Remove this once we drop support for v14 export type ASTVisitorKeyMap = Partial[2]>; + +export type DirectiveLocationEnum = typeof DirectiveLocation; + +export enum DirectiveLocation { + /** Request Definitions */ + QUERY = 'QUERY', + MUTATION = 'MUTATION', + SUBSCRIPTION = 'SUBSCRIPTION', + FIELD = 'FIELD', + FRAGMENT_DEFINITION = 'FRAGMENT_DEFINITION', + FRAGMENT_SPREAD = 'FRAGMENT_SPREAD', + INLINE_FRAGMENT = 'INLINE_FRAGMENT', + VARIABLE_DEFINITION = 'VARIABLE_DEFINITION', + /** Type System Definitions */ + SCHEMA = 'SCHEMA', + SCALAR = 'SCALAR', + OBJECT = 'OBJECT', + FIELD_DEFINITION = 'FIELD_DEFINITION', + ARGUMENT_DEFINITION = 'ARGUMENT_DEFINITION', + INTERFACE = 'INTERFACE', + UNION = 'UNION', + ENUM = 'ENUM', + ENUM_VALUE = 'ENUM_VALUE', + INPUT_OBJECT = 'INPUT_OBJECT', + INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION', +} diff --git a/packages/utils/tests/relocatedError.test.ts b/packages/utils/tests/relocatedError.test.ts index 6f9e8a714ee..f19d9f1c2b6 100644 --- a/packages/utils/tests/relocatedError.test.ts +++ b/packages/utils/tests/relocatedError.test.ts @@ -1,12 +1,15 @@ -import { GraphQLError } from 'graphql'; -import { relocatedError } from '../src/errors'; +import { relocatedError, createGraphQLError } from '../src/errors'; describe('Errors', () => { describe('relocatedError', () => { test('should adjust the path of a GraphqlError', () => { - const originalError = new GraphQLError('test', null as any, null, null, ['test']); + const originalError = createGraphQLError('test', { + path: ['test'], + }); const newError = relocatedError(originalError, ['test', 1]); - const expectedError = new GraphQLError('test', null as any, null, null, ['test', 1]); + const expectedError = createGraphQLError('test', { + path: ['test', 1], + }); expect(newError).toEqual(expectedError); }); }); diff --git a/packages/utils/tests/visitResult.test.ts b/packages/utils/tests/visitResult.test.ts index 6afa532b23e..5b292daf62c 100644 --- a/packages/utils/tests/visitResult.test.ts +++ b/packages/utils/tests/visitResult.test.ts @@ -1,6 +1,6 @@ import { buildSchema, parse, GraphQLError } from 'graphql'; -import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils'; +import { createGraphQLError, ExecutionRequest, ExecutionResult } from '@graphql-tools/utils'; import { relocatedError } from '../src/errors'; @@ -376,7 +376,9 @@ describe('visiting errors', () => { }, errors: [ new GraphQLError('unpathed error'), - new GraphQLError('pathed error', undefined, undefined, undefined, ['test', 'field']), + createGraphQLError('pathed error', { + path: ['test', 'field'], + }), ], }; @@ -394,7 +396,9 @@ describe('visiting errors', () => { }, errors: [ new GraphQLError('unpathed error'), - new GraphQLError('pathed error', undefined, undefined, undefined, ['test', 'field']), + createGraphQLError('pathed error', { + path: ['test', 'field'], + }), ], }; diff --git a/packages/webpack-loader-runtime/package.json b/packages/webpack-loader-runtime/package.json index 9ac45966cce..8cbf967d5dc 100644 --- a/packages/webpack-loader-runtime/package.json +++ b/packages/webpack-loader-runtime/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/webpack-loader/package.json b/packages/webpack-loader/package.json index a559cbfa5a6..515d55e3b74 100644 --- a/packages/webpack-loader/package.json +++ b/packages/webpack-loader/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/wrap/package.json b/packages/wrap/package.json index 63835eaa0b3..39ba13b5b9e 100644 --- a/packages/wrap/package.json +++ b/packages/wrap/package.json @@ -26,7 +26,7 @@ "definition": "dist/index.d.ts" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" }, "buildOptions": { "input": "./src/index.ts" diff --git a/packages/wrap/tests/transforms.test.ts b/packages/wrap/tests/transforms.test.ts index c37ac6ad283..5641a237e5c 100644 --- a/packages/wrap/tests/transforms.test.ts +++ b/packages/wrap/tests/transforms.test.ts @@ -1,18 +1,11 @@ -import { - GraphQLSchema, - GraphQLScalarType, - Kind, - SelectionSetNode, - graphql, - OperationTypeNode, - GraphQLError, -} from 'graphql'; +import { GraphQLSchema, GraphQLScalarType, Kind, SelectionSetNode, graphql, OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { wrapSchema, WrapQuery, ExtractField, TransformQuery } from '@graphql-tools/wrap'; import { delegateToSchema, defaultMergedResolver } from '@graphql-tools/delegate'; +import { createGraphQLError } from '@graphql-tools/utils'; function createError(message: string, extra?: T) { const error = new Error(message); @@ -650,7 +643,12 @@ describe('transforms', () => { errorTest: null, }, }, - errors: [new GraphQLError('Test Error!', undefined, undefined, [15, 4], ['addressByUser', 'errorTest'])], + errors: [ + createGraphQLError('Test Error!', { + positions: [15, 4], + path: ['addressByUser', 'errorTest'], + }), + ], }); }); diff --git a/patches/@guild-docs+mdx-remote+2.0.1.patch b/patches/@guild-docs+mdx-remote+2.0.2.patch similarity index 100% rename from patches/@guild-docs+mdx-remote+2.0.1.patch rename to patches/@guild-docs+mdx-remote+2.0.2.patch diff --git a/patches/@n1ru4l+in-memory-live-query-store+0.9.0.patch b/patches/@n1ru4l+in-memory-live-query-store+0.9.0.patch new file mode 100644 index 00000000000..0701989aa72 --- /dev/null +++ b/patches/@n1ru4l+in-memory-live-query-store+0.9.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/@n1ru4l/in-memory-live-query-store/index.js b/node_modules/@n1ru4l/in-memory-live-query-store/index.js +index 92f82df..a2cdd2b 100644 +--- a/node_modules/@n1ru4l/in-memory-live-query-store/index.js ++++ b/node_modules/@n1ru4l/in-memory-live-query-store/index.js +@@ -6,7 +6,7 @@ const graphql = require('graphql'); + const utils = require('@graphql-tools/utils'); + const repeater = require('@repeaterjs/repeater'); + const graphqlLiveQuery = require('@n1ru4l/graphql-live-query'); +-const values_js = require('graphql/execution/values.js'); ++const values_js = require('graphql/execution/values'); + + const isSome = (input) => input != null; + const isNone = (input) => input == null;