-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support null query when running APQ request #4049
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 all commits
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import graphql.execution.instrumentation.InstrumentationState | |
| import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters | ||
| import graphql.execution.instrumentation.parameters.InstrumentationFieldCompleteParameters | ||
| import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters | ||
| import graphql.execution.preparsed.persisted.PersistedQuerySupport | ||
| import graphql.schema.DataFetcher | ||
| import graphql.schema.DataFetchingEnvironment | ||
| import org.dataloader.DataLoaderRegistry | ||
|
|
@@ -45,6 +46,21 @@ class ExecutionInputTest extends Specification { | |
| executionInput.query == query | ||
| executionInput.locale == Locale.GERMAN | ||
| executionInput.extensions == [some: "map"] | ||
| executionInput.toString() != null | ||
| } | ||
|
|
||
| def "build without locale"() { | ||
| when: | ||
| def executionInput = ExecutionInput.newExecutionInput().query(query) | ||
| .dataLoaderRegistry(registry) | ||
| .variables(variables) | ||
| .root(root) | ||
| .graphQLContext({ it.of(["a": "b"]) }) | ||
| .locale(null) | ||
| .extensions([some: "map"]) | ||
| .build() | ||
| then: | ||
| executionInput.locale == Locale.getDefault() | ||
| } | ||
|
|
||
| def "map context build works"() { | ||
|
|
@@ -314,6 +330,33 @@ class ExecutionInputTest extends Specification { | |
| "1000 ms" | plusOrMinus(1000) | ||
| } | ||
|
|
||
| def "uses persisted query marker when query is null"() { | ||
| when: | ||
| ExecutionInput.newExecutionInput().query(null).build() | ||
| then: | ||
| thrown(AssertException) | ||
| } | ||
|
|
||
| def "uses persisted query marker when query is null and extensions contains persistedQuery"() { | ||
| when: | ||
| def executionInput = ExecutionInput.newExecutionInput() | ||
| .extensions([persistedQuery: "any"]) | ||
| .query(null) | ||
| .build() | ||
| then: | ||
| executionInput.query == PersistedQuerySupport.PERSISTED_QUERY_MARKER | ||
| } | ||
|
|
||
| def "uses persisted query marker when query is empty and extensions contains persistedQuery"() { | ||
| when: | ||
| def executionInput = ExecutionInput.newExecutionInput() | ||
| .extensions([persistedQuery: "any"]) | ||
|
Member
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. So the question then is should we provide a helper builder method (that sets the query for you to the magic value) or use a "map entry" in extentions. I feel like the former is better but would love to why you chose "extensions" - was there a client reason ?
Contributor
Author
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. This fix was originally from a colleague to unblock our production usage. The idea behind making it implicit in Looking into it further it seems that GraphQL-Java abstracts Persisted Queries which makes sense given there are a few implementations in practice (Apollo APQ, etc). This makes this change not ideal as it is tailored specifially for Apollo APQ implementation. Based on that I think we some how need to incorporate the check to leverage the PersistedQuerySupport implementation, for example: If that was implemented as of today, then we would need to remove the assertions in the
Member
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. Sorry for the late reply - I have been away and havent had time to reply. I think I now understand better - basically this fix allows people who use Apollo PQ (marker value in input extensions) https://www.apollographql.com/docs/apollo-server/performance/apq if we take this fix it makes it a smidge easier to use APQ - fair enough - but it only works for APQ At Atlassian for example we used path paramaeter eg And hence we still needed code to make the "query non null" which I dont mind because this ensures that its not accidental opt in to some empty query and blow up later. And you are right - PQ do not work outn of box from graphql-java - some one must put in a
Member
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. And hence to this code - leave it as it is |
||
| .query("") | ||
| .build() | ||
| then: | ||
| executionInput.query == PersistedQuerySupport.PERSISTED_QUERY_MARKER | ||
| } | ||
|
|
||
| def "can cancel at specific places"() { | ||
| def sdl = ''' | ||
| type Query { | ||
|
|
||
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.
Nice code