From a8efd479584776668ddf5b71036c597894febd96 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] Add compatible logic for graphql@16 --- packages/apollo-graphql/package.json | 2 +- .../apollo-graphql/src/schema/buildSchemaFromSDL.ts | 11 +++++++++++ 2 files changed, 12 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..4e6530fbac 100644 --- a/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts +++ b/packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts @@ -53,11 +53,22 @@ const skippedSDLRules: ValidationRule[] = [ // Currently, this PossibleTypeExtensions rule is experimental and thus not // exposed directly from the rules module above. This may change in the future! // Additionally, it does not exist in prior graphql versions. Thus this try/catch. +// +// 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@15 const PossibleTypeExtensions: typeof import("graphql/validation/rules/PossibleTypeExtensions").PossibleTypeExtensions = require("graphql/validation/rules/PossibleTypeExtensions") .PossibleTypeExtensions; + + // Compatible for graphql@16 + const PossibleTypeExtensionsRule = require("graphql") + .PossibleTypeExtensionsRule; + if (PossibleTypeExtensions) { skippedSDLRules.push(PossibleTypeExtensions); + } else 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