Closed karl-run closed 4 years ago
I have exactly this same question! Any ideas yet?
This seems very related: https://github.com/graphql-java/graphql-java-tools/issues/123
Aha. @karl-run Add one of these to your Spring config:
@Bean
public ExecutionStrategy executionStrategy() {
return new BatchedExecutionStrategy();
}
Although, this does beg the question about deprecation, since BatchedExecutionStrategy
is marked as @deprecated
. Is there a better way to do it, I wonder?
The javadoc states that it has been deprecated in favour of AsyncExecutionStrategy.
BatchedExecutionStrategy has been deprecated in favour of graphql.execution.AsyncExecutionStrategy and graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation. BatchedExecutionStrategy does not properly implement the graphql runtime specification. Specifically it does not correctly handle non null fields and how they are to cascade up their parent fields. It has proven an intractable problem to make this code handle these cases. See http://facebook.github.io/graphql/October2016/#sec-Errors-and-Non-Nullability We will remove it once we are sure the alternative is as least good as the BatchedExecutionStrategy.
I'll see if AsyncExecutionStrategy
can be provided with like BatchedExecutionStrategy, and if that fixes the issue.
Just straight out replacing BatchedExecutionStrategy
with AsyncExecutionStrategy
does not work. :man_shrugging:
Yes, those docs call out that you have to use it in conjunction with DataLoader
s. Unfortunately, it doesn't look like the Spring/tools integration with the DataLoader
system is very simple or elegant right now. I'm hoping that will happen before the BatchedExecutionStrategy
gets removed!
This issue has plenty of discussion on using DataLoader
s: https://github.com/graphql-java/graphql-java-tools/issues/58
@Batched
and BatchedExecutionStrategy
is deprecated. Please use https://github.com/graphql-java/java-dataloader instead.
Using
graphql-spring-boot-starter
,graphql-java-servlet
andgraphql-java-tools
.I have this resolver:
In my case resolving all somethings on a something group creates a lot of individual database queries so I would like to batch these requests.
My understanding of
@Batched
is to use it as following:When running this the schema and resolvers validate fine, however at runtime I get this error:
Debugging a bit shows that
SomethingGroupResolver.getSomethings
that when batched expectsList<SomethingGroup> somethingGroups
, only receives a singleSomethingGroup
.Is there something about batching and
@Batched
I'm not understanding? :smile_cat: