Closed
Description
Hello,
I was trying to use the @Batched annotation interface to improve the speed of some of my resolvers but i don't seem to get around the error message that tells me that my source-type isn't an iterable. I have a resolver which has non-batched fields and batched fields. I added the annotation to the method of a batched field and wrapped the original return type in a list. I also wrapped the first argument (source) in a list.
The error occurs on query time:
Exception while fetching data (/getFoos/edges[0]/node/Bar) : Source type (my.package.Foo) is not expected type (java.lang.Iterable)!
The last part of stack trace is:
at com.coxautodev.graphql.tools.MethodFieldResolver$createDataFetcher$1.invoke(MethodFieldResolver.kt:57) ~[graphql-java-tools-5.6.1.jar:?]
at com.coxautodev.graphql.tools.MethodFieldResolver$createDataFetcher$1.invoke(MethodFieldResolver.kt:23) ~[graphql-java-tools-5.6.1.jar:?]
at com.coxautodev.graphql.tools.MethodFieldResolverDataFetcher.get(MethodFieldResolver.kt:160) ~[graphql-java-tools-5.6.1.jar:?]
at com.coxautodev.graphql.tools.BatchedMethodFieldResolverDataFetcher.get(MethodFieldResolver.kt:198) ~[graphql-java-tools-5.6.1.jar:?]
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:270) ~[graphql-java-13.0.jar:?]
The original (resolver) code (without batching) was:
public class FooResolver implements GraphQLResolver<Foo> {
private final BarRetriever barRetriever;
public int getId(Foo f) {
return f.getFooId()
}
public List<Bar> getBars(Foo foo) {
return barRetriever.getBarsForFooId(foo.getId)
}
}
public class FooResolver implements GraphQLResolver<Foo> {
private final BarRetriever barRetriever;
public int getId(Foo f) {
return f.getFooId()
}
@Batched
public List<List<Bar>> getBars(List<Foo> foos) {
Set<Integer> ids = foos.stream().map(Foo::getFooId).collect(Collectors.toList());
return barRetriever.getBarsForFooIds(ids)
}
}
The GraphQL schema is:
type Query {
getFoos: FooConnection @connection(for: "Foo")
}
type Foo {
id: Int!
bars: [Bar!]!
}
What am i doing wrong?
Metadata
Metadata
Assignees
Labels
No labels