-
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
Changes from 5 commits
dff4047
38aafdc
5444e27
ed7cf16
a1e3b7b
48a6a6c
cf5fc12
90d39f4
29df455
bffa43f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,7 @@ import { | |
GraphQLError | ||
} from 'graphql'; | ||
import { | ||
simpleEstimator, | ||
legacyEstimator | ||
simpleEstimator | ||
} from './estimators'; | ||
|
||
declare module 'graphql/type/definition' { | ||
|
@@ -91,7 +90,7 @@ export function getComplexity(options: { | |
}): number { | ||
const typeInfo = new TypeInfo(options.schema); | ||
|
||
const context = new ValidationContext(options.schema, options.query, typeInfo); | ||
const context = new ValidationContext(options.schema, options.query, typeInfo, () => null); | ||
const visitor = new QueryComplexity(context, { | ||
// Maximum complexity does not matter since we're only interested in the calculated complexity. | ||
maximumComplexity: Infinity, | ||
|
@@ -135,7 +134,6 @@ export default class QueryComplexity { | |
} | ||
|
||
this.estimators = options.estimators || [ | ||
legacyEstimator(), | ||
simpleEstimator() | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ivome this might be a good time to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, let's make this required now with all the breaking changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
|
@@ -178,7 +176,7 @@ export default class QueryComplexity { | |
if (typeof this.options.operationName === 'string' && this.options.operationName !== operation.name.value) { | ||
return; | ||
} | ||
|
||
if (this.options.onComplete) { | ||
this.options.onComplete(this.complexity); | ||
} | ||
|
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?
Uh oh!
There was an error while loading. Please reload this page.
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.Uh oh!
There was an error while loading. Please reload this page.
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?