-
Notifications
You must be signed in to change notification settings - Fork 41
Compatibility with graphql ^15.0.0 #30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dff4047
Switch to new ValidationContext API, use `onError`, remove `getErrors`
robhogan 38aafdc
Bump graphql dev dependency to ^15.0.0. Bump peer dependency to ^14.5…
robhogan 5444e27
Replace fieldConfigEstimator usage in tests with fieldExtensionsEstim…
robhogan ed7cf16
Remove fieldConfigEstimator and legacyEstimator from README
robhogan a1e3b7b
Dev graphql dependency => same as peer dependency
robhogan 48a6a6c
Make QueryComplexityOptions.estimators mandatory, remove default
robhogan cf5fc12
Merge remote-tracking branch 'slicknode/master' into feature/graphql-…
robhogan 90d39f4
Add graphql@~15.0 to CI matrix
robhogan 29df455
Add CompatibleValidationContext for use in tests to continue to suppo…
robhogan bffa43f
Restore peerDepedencies compatibility with graphql <14.5.0
robhogan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { GraphQLError, TypeInfo, ValidationContext } from "graphql"; | ||
import { GraphQLSchema } from "graphql/type/schema"; | ||
import { DocumentNode } from "graphql/language/ast"; | ||
|
||
/** | ||
* This class is used to test that validation errors are raised correctly | ||
* | ||
* A compatibility layer is necessary to support graphql versions since 15.0.0 | ||
* *as well as* versions prior to 14.5.0 with the same test, because older | ||
* versions of `ValidationContext` only expose a `getErrors` API and newer | ||
* versions only expose the `onError` API via a fourth constructor argument. | ||
* | ||
* Once we drop support for versions older than 14.5.0 this layer will no | ||
* longer be necessary and tests may use `ValidationContext` directly using the | ||
* `onError` API. | ||
*/ | ||
export class CompatibleValidationContext extends ValidationContext { | ||
private errors: GraphQLError[] = [] | ||
|
||
constructor(schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo) { | ||
super(schema, ast, typeInfo, err => this.errors.push(err)); | ||
} | ||
|
||
getErrors(): ReadonlyArray<GraphQLError> { | ||
// @ts-ignore | ||
return super.getErrors ? super.getErrors() : this.errors | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to drop support for 0.13 and 14.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of... The issue here is that
onError
was only added to the constructor args ofValidationContext
in 14.5.0.We don't strictly need that argument outside of tests, and we only pass a dummy function through anyway (since it's now mandatory), so theoretically we still have runtime compatibility with
^0.13.0 || ^14.0.0
because the extra argument we pass will simply be ignored. But, there'd be a typescript error trying to build against those versions, and the tests wouldn't work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for merging the CI PR - I've just pulled that into this branch to demonstrate the problem here - as you can see the 0.13 and 14.0 tests fail, but this is only because the tests themselves now rely on the new
onError
API instead of the previousgetErrors
.It would be possible to fix this by adding a compatibility shim for use within tests only, which will work with any version of
graphql
since 0.13:So I see three options:
^0.13.0 || ^14.0.0 || ^15.0.0
at the cost of carrying a bit of legacy.Your call sir!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed info here! I'd say let's add this compatibility layer (just for the tests) for now with a little note to remove this once we drop support for older GraphQL versions. That should give people time to upgrade their codebases and once we drop support for the old versions, we can remove that temporary compatibility layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, done. I wasn't sure what to call
CompatibleValidationLayer
or exactly where to put it - let me know if you'd like any of that changing.Otherwise, all tests now green, and I think we're done?