Description
I submitted a stackoverflow question with the spring graphql tag that you can find here.
Given a GraphQL schema that contains data like the following
type Person {
name: String!
age: Int!
friends(filter: FriendsFilter): [Person!]!
hobbies(filter: HobbiesFilter): [Hobby!]!
}
I can create a schema mapping in my controller which looks like the following
@SchemaMapping
public List<Person> friends(
@Arugment FriendsFilter filter,
Person person){
// Fetch and return friends
}
However, this runs us into the N+1 problem. So to solve that, we need to batch. What I would expect to be able to do is modify my code to the following
@BatchMapping
public Map<Person, List<Person>> friends(
@Arugment FriendsFilter filter,
List<Person> people){
// Fetch and return friends in bulk
}
I have found that spring graphql does not support this kind of thing. While this kind of support would be ideal, I'm willing to work around it, but all the other answers I'm finding lose the type information and attempt to register a mapper for the pair Person.class, List.class which is insufficient as I have two fields that are both lists. What exactly is the simplest and most correct way forward here? I have to solve the N+1 problem and I have to preserve the filtering functionality of my API.
I've tried reading through the closed issues asking for this feature and I still haven't quite found the answer I'm looking for. I could really just use some help finding the right thing to do in this case where a filter is required and we can't sacrifice the typing of List.