Skip to content

Commit 59bb973

Browse files
committedDec 29, 2021
Add compatible logic for graphql@16
1 parent 4f3ac25 commit 59bb973

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎packages/apollo-graphql/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"sha.js": "^2.4.11"
1717
},
1818
"peerDependencies": {
19-
"graphql": "^14.2.1 || ^15.0.0"
19+
"graphql": "^14.2.1 || ^15.0.0 || ^16.0.0"
2020
},
2121
"jest": {
2222
"preset": "ts-jest",

‎packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts

+16
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const skippedSDLRules: ValidationRule[] = [
5656
try {
5757
const PossibleTypeExtensions: typeof import("graphql/validation/rules/PossibleTypeExtensions").PossibleTypeExtensions = require("graphql/validation/rules/PossibleTypeExtensions")
5858
.PossibleTypeExtensions;
59+
5960
if (PossibleTypeExtensions) {
6061
skippedSDLRules.push(PossibleTypeExtensions);
6162
}
@@ -64,6 +65,21 @@ try {
6465
// by the version of `graphql` that is available to us.
6566
}
6667

68+
// BREAKING AGAIN: PossibleTypeExtensions is finilized into PossibleTypeExtensionsRule in
69+
// graphql 16. For compatible reason, try catch logic for 15 is kept with extra logic for 16.
70+
try {
71+
// Compatible for graphql-js@16
72+
const PossibleTypeExtensionsRule = require("graphql")
73+
.PossibleTypeExtensionsRule;
74+
75+
if (PossibleTypeExtensionsRule) {
76+
skippedSDLRules.push(PossibleTypeExtensionsRule);
77+
}
78+
} catch (e) {
79+
// No need to fail in this case. Instead, if this validation rule is missing, we will assume its not used
80+
// by the version of `graphql` that is available to us.
81+
}
82+
6783
const sdlRules = specifiedSDLRules.filter(
6884
rule => !skippedSDLRules.includes(rule)
6985
);

0 commit comments

Comments
 (0)