Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatible logic for graphql@16 #2534

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
m1heng marked this conversation as resolved.
Show resolved Hide resolved
// 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