-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for DataFetcherResult values in subscriptions and better instrumentation. #1804
Support for DataFetcherResult values in subscriptions and better instrumentation. #1804
Conversation
This supports BOTH the Publisher being in a DFR and also any streamed events being in DFRs It also adds error support correctly for sending back a stream of possible errors and data as per spec
@Override | ||
public String toString() { | ||
return message; | ||
} |
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.
helps with debugging
public ExecutionContextBuilder resetErrors() { | ||
this.errors.clear(); | ||
return this; | ||
} |
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.
we need this because in subscroptions we start a new execution per streamed event
ExecutionContext newExecutionContext = executionContext.transform(builder -> builder | ||
.root(eventPayload) | ||
.resetErrors() | ||
); |
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.
We reset errors so that we have errors per streamed event BUT we use the same other execution context
FetchedValue fetchedValue = unboxPossibleDataFetcherResult(newExecutionContext, parameters, eventPayload); | ||
FieldValueInfo fieldValueInfo = completeField(newExecutionContext, newParameters, fetchedValue); | ||
return fieldValueInfo | ||
.getFieldValue() |
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.
The fix here was to called unboxPossibleDataFetcherResult
} | ||
assert message.data == ["newMessage": [sender: "sender" + i, text: "text" + i]] | ||
} | ||
} |
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.
A test of DataFectherResult + errors at the Publisher level and also at each streamed event level and also errors on sub levels
@@ -96,6 +96,7 @@ public Execution(ExecutionStrategy queryStrategy, ExecutionStrategy mutationStra | |||
.cacheControl(executionInput.getCacheControl()) | |||
.locale(executionInput.getLocale()) | |||
.valueUnboxer(valueUnboxer) | |||
.executionInput(executionInput) |
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.
We need this later in subscriptions and the instrumentDataFetcherResult
calls. Its nominally useful as well but execution context unpacks it any way
private final ExecutionInput executionInput; | ||
|
||
@Internal | ||
ExecutionContext(ExecutionContextBuilder builder) { |
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.
After 18 parameters its time for this pattern
Instrumentation instrumentation = executionContext.getInstrumentation(); | ||
InstrumentationExecutionStrategyParameters instrumentationParameters = new InstrumentationExecutionStrategyParameters(executionContext, parameters); | ||
ExecutionStrategyInstrumentationContext executionStrategyCtx = instrumentation.beginExecutionStrategy(instrumentationParameters); | ||
|
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.
Better instrumentation of subscription queries
GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType(); | ||
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, field); | ||
return createExecutionStepInfo(executionContext, parameters, fieldDef, parentType); | ||
} |
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.
This is weird but needed. We want a execution step info here for the instrumentation - the soon to be called completeValue call will do something similar soon but we need this to descrive the "beginSubscribedFieldEvent" in instrumentation terms
.locale(Locale.getDefault()) | ||
.valueUnboxer(ValueUnboxer.DEFAULT) | ||
|
||
new ExecutionContext(builder) |
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.
code fix up of change in constructor
}; | ||
} | ||
|
||
} |
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.
A reactive stream thats a little more generic
@@ -84,6 +85,7 @@ public ExecutionContextBuilder() { | |||
locale = other.getLocale(); | |||
errors = new ArrayList<>(other.getErrors()); | |||
valueUnboxer = other.getValueUnboxer(); | |||
this.executionInput = other.getExecutionInput(); |
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.
nit: use this
on other assignments for consistency
@@ -114,6 +114,17 @@ default InstrumentationState createState(InstrumentationCreateStateParameters pa | |||
*/ | |||
DeferredFieldInstrumentationContext beginDeferredField(InstrumentationDeferredFieldParameters parameters); | |||
|
|||
/** | |||
* This is called each time a subscription field produces a new reactive stream event value and its needs to be mapped over via the graphql field subselection. |
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.
nit: typo "and its needs to be mapped" should be "and it needs to be mapped"
import java.util.function.Function; | ||
|
||
/** | ||
* This example publisher will create count "objects" and then terminate. Its |
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.
typo: "Its uses" should be "It uses"
…tcher-result-in-subscription # Conflicts: # src/main/java/graphql/execution/ExecutionContext.java # src/main/java/graphql/execution/ExecutionContextBuilder.java # src/test/groovy/graphql/execution/ExecutionStrategyTest.groovy
In graphql-java 15, changes were made to SubscriptionExecutionStrategy to allow for DataFetcherResults to be returned, and to instrument the results of a subscription properly. This updates the Flow strategy with the same changes and adds tests for both changes. See graphql-java/graphql-java#1804
In graphql-java 15, changes were made to SubscriptionExecutionStrategy to allow for DataFetcherResults to be returned, and to instrument the results of a subscription properly. This updates the Flow strategy with the same changes and adds tests for both changes. See graphql-java/graphql-java#1804
…oup#742) In graphql-java 15, changes were made to SubscriptionExecutionStrategy to allow for DataFetcherResults to be returned, and to instrument the results of a subscription properly. This updates the Flow strategy with the same changes and adds tests for both changes. See graphql-java/graphql-java#1804
This supports BOTH the Publisher being in a DFR and also any streamed events being in DFRs
It also adds error support correctly for sending back a stream of possible errors and data as per spec
see #1795
It also adds a new
Instrumentation
callback for each "reactive stream event"