Skip to content

Commit

Permalink
Add compatible logic for graphql@16
Browse files Browse the repository at this point in the history
  • Loading branch information
m1heng committed Dec 29, 2021
1 parent 4f3ac25 commit 59bb973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/apollo-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
);
Expand Down

0 comments on commit 59bb973

Please sign in to comment.