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

first class dataloader support #1263

Merged

Conversation

bbakerman
Copy link
Member

@bbakerman bbakerman commented Oct 3, 2018

See #1254

This changes the signature of things so that DataLoaderRegistry's need to be added per execution and not at the schema level.

This will encourage people to do the right thing in creating new DataLoaders per execution.

It also ensure thats DataLoaderInstrumentation is ALWAYS loaded if its not already present and it makes it efficient if you have no data loaders in action.

@bbakerman bbakerman added the Not to be merged spikes or other stuff that should never or not yet to be merged label Oct 3, 2018


public ExecutionInput(String query, String operationName, Object context, Object root, Map<String, Object> variables) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might want to change this to prevent broken API for those who called create direct

instrumentations.add(assertNotNull(instrumentation));
return new ChainedInstrumentation(instrumentations);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to kill this method. Not used

*
* fragment BarFragment on Query {
* bar
* }
*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix 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.

fixed

@bbakerman bbakerman removed the Not to be merged spikes or other stuff that should never or not yet to be merged label Oct 4, 2018
@bbakerman bbakerman added this to the 11.0 milestone Oct 4, 2018
@bbakerman bbakerman added the breaking change requires a new major version to be relased label Oct 4, 2018
Copy link
Member

@andimarek andimarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments.
Also: I would suggest not to add the docs changes here. See #1267

@@ -106,6 +126,7 @@ public static Builder newExecutionInput() {
private Object context;
private Object root;
private Map<String, Object> variables = Collections.emptyMap();
private DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so default is we always have one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we always have one in play

@@ -35,13 +36,14 @@
private final Object context;
private final Instrumentation instrumentation;
private final List<GraphQLError> errors = new CopyOnWriteArrayList<>();
private final DataLoaderRegistry dataLoaderRegistry;
private final DeferSupport deferSupport = new DeferSupport();

public ExecutionContext(Instrumentation instrumentation, ExecutionId executionId, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy, Map<String, FragmentDefinition> fragmentsByName, Document document, OperationDefinition operationDefinition, Map<String, Object> variables, Object context, Object root) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we mark the constructor as Internal and I am not sure we should always create a new DLR here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the extra new DLR here JUST in case some one created it by hand because it was a public method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since this is already a breaking change - I am going to clean this up by removing the old public constructor.

Our code should be the only constructor of these things

private boolean aggressivelyBatching = true;

public DataLoaderDispatcherInstrumentationState(Logger log, DataLoaderRegistry dataLoaderRegistry) {

this.dataLoaderRegistry = dataLoaderRegistry;
this.approach = new FieldLevelTrackingApproach(log, dataLoaderRegistry);
this.state = approach.createState();
hasNoDataLoaders = dataLoaderRegistry.getKeys().isEmpty();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see: so instead a nullalble or Optional DRL we check for content here. DLR is immutable, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right - we always have a DLR in play

.build()

then: "execution shouldn't hang"
List<CompletableFuture<ExecutionResult>> futures = []
for (int i = 0; i < NUM_OF_REPS; i++) {
def result = graphql.executeAsync(ExecutionInput.newExecutionInput()
def result = graphql.executeAsync(newExecutionInput()
.dataLoaderRegistry(dataLoaderRegistry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should always be a new DLR, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - it should always be a new DLR - this pattern is to try and encourage that

@bbakerman bbakerman merged commit 78a6e4e into graphql-java:master Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change requires a new major version to be relased
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants