From 59bb97373f1aaa41ed580ea4bb7de6e7aafb9ba0 Mon Sep 17 00:00:00 2001 From: m1heng <18018422+m1heng@users.noreply.github.com> Date: Wed, 29 Dec 2021 14:20:30 +0800 Subject: [PATCH 1/3] Add compatible logic for graphql@16 --- packages/apollo-graphql/package.json | 2 +- .../src/schema/buildSchemaFromSDL.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/apollo-graphql/package.json b/packages/apollo-graphql/package.json index 92d8c9d748..2162dce47b 100644 --- a/packages/apollo-graphql/package.json +++ b/packages/apollo-graphql/package.json @@ -16,7 +16,7 @@ "sha.js": "^2.4.11" }, "peerDependencies": { - "graphql": "^14.2.1 || ^15.0.0" + "graphql": "^14.2.1 || ^15.0.0 || ^16.0.0" }, "jest": { "preset": "ts-jest", diff --git a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts index 8f0a93a8b8..7e03219f19 100644 --- a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts +++ b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts @@ -56,6 +56,7 @@ const skippedSDLRules: ValidationRule[] = [ try { const PossibleTypeExtensions: typeof import("graphql/validation/rules/PossibleTypeExtensions").PossibleTypeExtensions = require("graphql/validation/rules/PossibleTypeExtensions") .PossibleTypeExtensions; + if (PossibleTypeExtensions) { skippedSDLRules.push(PossibleTypeExtensions); } @@ -64,6 +65,21 @@ try { // by the version of `graphql` that is available to us. } +// BREAKING AGAIN: PossibleTypeExtensions is finilized into PossibleTypeExtensionsRule in +// graphql 16. For compatible reason, try catch logic for 15 is kept with extra logic for 16. +try { + // Compatible for graphql-js@16 + const PossibleTypeExtensionsRule = require("graphql") + .PossibleTypeExtensionsRule; + + if (PossibleTypeExtensionsRule) { + skippedSDLRules.push(PossibleTypeExtensionsRule); + } +} catch (e) { + // No need to fail in this case. Instead, if this validation rule is missing, we will assume its not used + // by the version of `graphql` that is available to us. +} + const sdlRules = specifiedSDLRules.filter( rule => !skippedSDLRules.includes(rule) ); From cbc83e69066e3637e197a2da27d9dad5e8bd7416 Mon Sep 17 00:00:00 2001 From: m1heng <18018422+m1heng@users.noreply.github.com> Date: Tue, 18 Jan 2022 19:01:48 +0800 Subject: [PATCH 2/3] Update packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts Co-authored-by: Jiri Spac --- packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts index 7e03219f19..320c649492 100644 --- a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts +++ b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts @@ -65,7 +65,7 @@ try { // by the version of `graphql` that is available to us. } -// BREAKING AGAIN: PossibleTypeExtensions is finilized into PossibleTypeExtensionsRule in +// BREAKING AGAIN: PossibleTypeExtensions is finalized into PossibleTypeExtensionsRule in // graphql 16. For compatible reason, try catch logic for 15 is kept with extra logic for 16. try { // Compatible for graphql-js@16 From 3a2cf2880319494b7bb58149281c3d278278afa0 Mon Sep 17 00:00:00 2001 From: hwillson Date: Wed, 13 Jul 2022 12:12:51 -0400 Subject: [PATCH 3/3] Prettier tweaks --- packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts index 29544d2f0e..6ff3f26d04 100644 --- a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts +++ b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts @@ -68,8 +68,8 @@ try { // graphql 16. For compatible reason, try catch logic for 15 is kept with extra logic for 16. try { // Compatible for graphql-js@16 - const PossibleTypeExtensionsRule = require("graphql") - .PossibleTypeExtensionsRule; + const PossibleTypeExtensionsRule = + require("graphql").PossibleTypeExtensionsRule; if (PossibleTypeExtensionsRule) { skippedSDLRules.push(PossibleTypeExtensionsRule);