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 a8efd47
Show file tree
Hide file tree
Showing 2 changed files with 12 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
11 changes: 11 additions & 0 deletions packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8efd47

Please sign in to comment.