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