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

Support for DataFetcherResult values in subscriptions and better instrumentation. #1804

Merged
merged 5 commits into from
May 21, 2020

Conversation

bbakerman
Copy link
Member

@bbakerman bbakerman commented Feb 28, 2020

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"

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
@bbakerman bbakerman added this to the 15.0 milestone Feb 28, 2020
@Override
public String toString() {
return message;
}
Copy link
Member Author

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;
}
Copy link
Member Author

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()
);
Copy link
Member Author

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()
Copy link
Member Author

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]]
}
}
Copy link
Member Author

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)
Copy link
Member Author

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) {
Copy link
Member Author

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);

Copy link
Member Author

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);
}
Copy link
Member Author

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)
Copy link
Member Author

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

};
}

}
Copy link
Member Author

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

@bbakerman bbakerman changed the title Support for DataFetcherResult values in subscriptions. Support for DataFetcherResult values in subscriptions and better instrumentation. Feb 29, 2020
@@ -84,6 +85,7 @@ public ExecutionContextBuilder() {
locale = other.getLocale();
errors = new ArrayList<>(other.getErrors());
valueUnboxer = other.getValueUnboxer();
this.executionInput = other.getExecutionInput();
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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
@bbakerman bbakerman merged commit 9eb260e into master May 21, 2020
josephlbarnett added a commit to josephlbarnett/graphql-kotlin that referenced this pull request Jun 3, 2020
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
smyrick pushed a commit to ExpediaGroup/graphql-kotlin that referenced this pull request Jun 4, 2020
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
@andimarek andimarek deleted the 1795-support-datafetcher-result-in-subscription branch June 5, 2020 10:44
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants