You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to graphql-java
Hi,
It would be nice to have specific unit tests showing how to use batched data-fetcher. I have seen few of them along with tests for other data-fetchers (in GraphqlExecutionSpec.groovy) but I couldn't grasp from them how to support the following use-case. Apologies in advance if it's trivial, which I thought it would be in the beginning.
So the use-case is looking up Objects using primary-key ids. But each field of the object comes from a different source over the network so we would like to batch load each field. An example would be "Person" object with two fields "address" and "name" where each of them needs a dataloader to fetch data from a remote service using personId. And a single query might want to load many personIds.
Following could be the schema for loading information of one person but am not sure how to implement batch-loading when multiple personIds are involved.
public static final GraphQLObjectType PersonQueryType = newObject() .name("PersonQueryType") .field(newFieldDefinition() .name("name") .type(Scalars.GraphQLString) .argument(newArgument() .name("personId") .type(new GraphQLNonNull(Scalars.GraphQLBigInteger)) .build()) .dataFetcher(new DataFetcher() { @Override @Batched public Object get(DataFetchingEnvironment environment) { // call a remote service return environment.getArgument("input"); } }) .build()) .field(newFieldDefinition() .name("address") .type(Scalars.GraphQLString) .argument(newArgument() .name("personId") .type(new GraphQLNonNull(Scalars.GraphQLBigInteger)) .build()) .dataFetcher(new DataFetcher() { @Override @Batched public Object get(DataFetchingEnvironment environment) { // call a remote service return environment.getArgument("input"); } }) .build()) .build();