Skip to content

Asynchronous execution strategy#283

Closed
dminkovsky wants to merge 13 commits intographql-java:masterfrom
dminkovsky:async
Closed

Asynchronous execution strategy#283
dminkovsky wants to merge 13 commits intographql-java:masterfrom
dminkovsky:async

Conversation

@dminkovsky
Copy link
Contributor

@dminkovsky dminkovsky commented Dec 20, 2016

Following up with #242 and #202, this is a working asynchronous execution strategy:

GraphQLAsync graphql = new GraphQLAsync(
  schema,
  AsyncExecutionStrategy.serial(),
  AsyncExecutionStrategy.parallel()
);

String query = "{ name }";
CompletionStage<ExecutionResult> result = graphql.executeAsync(query);
result.thenAccept(executionResult -> {
  // use result //
})

Calls are made through GraphQLAsync, which extends GraphQL and provides an executeAsync method that returns CompletionStage<ExecutionResult>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This for loop needs to be replaced with a construct that properly closes over the vars passed to resolveFieldAsync

Copy link

Choose a reason for hiding this comment

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

could make use of java8's stream.map.collect thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Thank you. What do you think otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hepin1989 replaced this with .collect(toMap()). Thanks again.

@oexza
Copy link

oexza commented Dec 30, 2016

Good work! I think the last missing piece is a way to pass in a custom Executor in which the CompletableFuture's will execute.

Edit: On a second look, i see that DataFetchers would be allowed to return a CompletionStage, therefore an Executor can be used by the user in their DataFetcher implementations. So i think this PR is good to go.

@crazyfrozenpenguin
Copy link

@dminkovsky, I have just browsed through the code but will soon test it.

One feature that it would be great to have would be the concept of DataFetcher dependencies when executing in parallel.

A DataFetcher can depend on other DataFetchers or, a DataFetcher could unlock other DataFetchers.

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Dec 31, 2016 via email

@dminkovsky dminkovsky force-pushed the async branch 4 times, most recently from da0b587 to 0b2d9d3 Compare January 1, 2017 00:36
@dminkovsky
Copy link
Contributor Author

@crazyfrozenpenguin identified and fixed the above-mentioned bug. Also fixed another issue. The update is forced pushed to this PR. Happy New Year.

@dminkovsky dminkovsky force-pushed the async branch 3 times, most recently from 70174b3 to 9ed6aee Compare January 1, 2017 00:53
@dminkovsky
Copy link
Contributor Author

By the way, I also updated the SNAPSHOT version. It was 2.3.0-SNAPSHOT, but 2.3.0 is now released so I just set it to 3.0.0-SNAPSHOT which should work until this is merged or otherwise closed.

@oexza
Copy link

oexza commented Jan 5, 2017

How do you intend to release this? will the project move to java 8? or will you release this as a seperate project?

@bmsantos
Copy link

bmsantos commented Jan 5, 2017

What's the reason for Java 6? The only release with public updates is Java 8:
http://www.oracle.com/technetwork/java/eol-135779.html

@andimarek
Copy link
Member

@bmsantos The reason we still support Java 6 is that a lot of companies are still using it, even if there are no updates for it.

@dminkovsky
Copy link
Contributor Author

@oexza yeah the plan is for a separate artifact. I have this PR here now to aid in peer review.

As @andimarek says, there are still people on Java 6 using this, which I think is really cool. It would be nice to somehow isolate a 1.6 and 1.7 compatible core that they can keep using.

What do you think? cc/ @bmsantos

@bmsantos
Copy link

bmsantos commented Jan 5, 2017

@dminkovsky and @andimarek, if you really want to keep offering support for 1.6, then yes, I don't think that there's any other option other than extract async code into its own jar - maybe graphql-java-async?

@dminkovsky
Copy link
Contributor Author

@bmsantos Yeah that's the name I was thinking.

@bmsantos
Copy link

bmsantos commented Jan 5, 2017

Breaking this on its own jar might actually be a much better approach since async related releases/updates will be easier to do.

Let me know if you need any help on this.

@dminkovsky
Copy link
Contributor Author

That would be greatly appreciated!

Breaking this on its own jar might actually be a much better approach since async related releases/updates will be easier to do.

Yeah, that's what I am thinking too. For example, fixing #268 is a bit difficult because the maintainers need to verify that the problem does not exist in all of the execution strategies (simple, executor service, and batched). #284 is related: with a clearer demarcation of API vs SPI, I think this would be much easier.

@Cafeinoman
Copy link

Is there a plan a plan / date to release this? It would be really helpful on an actual project...

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Jan 20, 2017

Hi @Cafeinoman. Thanks for posting.

I've had to take a few weeks away from this while I launch a project. I am using this in this project, so I will need to get back to it soon.

I think this PR is in okay shape except for correct handling of null non-nullable field (#268). That issue needs to be fixed in the other execution strategies as well. I don't think it makes sense to "release" this until those issues are addressed.

In the mean time, have you played with this branch? If you use it, please report any issues or PR improvements.

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Jan 20, 2017

Regarding #268, if anyone wants to tackle it:

As you will see, graphql-js execution tracks ResponsePath during execution, which aids in producing good errors. To me it appeared that to make our implementation work to spec and like graphql-js, we should not create and add errors during field resolution, but later during completion. We should also keep a response path, so that the errors we create can have that path in the error!

@bmsantos
Copy link

bmsantos commented Jan 20, 2017

I'm trying to get some free cycles to put out a small version of a project that exercises graphql with Vert.x. This will help me (and maybe others) to quickly exercise and test the async move to a jar. I'll try to put a first sample by the end of this weekend.

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Feb 22, 2017 via email

@bmsantos
Copy link

Thanks, will get to it ASAP.

@bmsantos
Copy link

@dminkovsky, I've created the graphql-java-async project here. In addition, a PR has been placed against your fork of graphql-java async branch.

Let me know if you find any issues and/or have any questions.

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Feb 24, 2017 via email

super(graphQLSchema, queryStrategy, mutationStrategy);
}

public CompletionStage<ExecutionResult> executeAsync(String requestString) {
Copy link

Choose a reason for hiding this comment

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

It would be more convenient if it returned CompletableFuture here.

@dminkovsky
Copy link
Contributor Author

dminkovsky commented Mar 16, 2017 via email

@andimarek
Copy link
Member

FYI: We are discussing an upgrade to Java 8: #338

@dminkovsky
Copy link
Contributor Author

@andimarek yeah I've kind of been following that. Just still trying to finish my project which is woefully overdue :(. Looking forward to crawling out of my hole and rejoining the world.

@andimarek
Copy link
Member

fyi: we will look at that topic for version 4

@andimarek andimarek added this to the 4.0.0 milestone May 6, 2017
@andimarek
Copy link
Member

Please have a look at #324 for the overall disucssion

@andimarek
Copy link
Member

closing it, it will not get merged: we solved the different aspects of this PR in the meantime and we we just merged #380 as a first step in supporting async execution.

Thanks a lot @dminkovsky

@andimarek andimarek closed this Jul 5, 2017
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.

9 participants