spring-graphql
spring-graphql copied to clipboard
Nested Batches
Hello there, I wanted to know if and how it is currently possible to use the BatchMapping with only one request for this situation: Basically currently when mapping on type extension and field data it requested data from my server twice. Is it possible in this situation to avoid a second call and call everything in one go?
type Query{
query: ReturnObject
}
type ReturnObject{
id: ID
header: [Header]
}
interface Header{
id: ID
description: String
}
interface Extension{
id: ID
data: String
}
type ObjectA implements Header & Extension{
id: ID
description: String
data: String
}
type ObjectB implements Header {
id: ID
description: String
objectC : [ObjectC ]
}
type ObjectC implements Extension{
id: ID
data: String
}
There were improvements for interface mappings in 1.3, but overall it's not clear what you mean with one vs two requests. Could you provide more information, what version you're trying this with, maybe a sample query and explain what the two requests are?
Thank you for your reply. The situation is as follows: I am returning two types of objects, both of which implement the Header interface (Object A and Object B). Object B contains a list of Object C. Now Object A and Object C (the one in Object B) both share a field data from the shared Interface Extension which I address with @Batchmapping(typeName= Extension, field= data) in my code. When the header is addressed, the function handles both objects at the same time and the function is only active once. For the interface Extension, the function is called twice. Once for object A and once for object C. Is there a way to avoid this?
Rather than explaining that in plain text, could you show a sample schema, a request and a controller method signature? I'm afraid I don't understand the current description. Code snippets would be clearer.
This is my Schema:
type Query{
query: ReturnObject
}
type ReturnObject{
id: ID
header: [Header]
}
interface Header{
id: ID
description: String
}
interface Extension{
id: ID
data: String
}
type ObjectA implements Header & Extension{
id: ID
description: String
data: String
}
type ObjectB implements Header {
id: ID
description: String
objectC : [ObjectC ]
}
type ObjectC implements Extension{
id: ID
data: String
}
This is my BatchMapping for the Extension
@Batchmapping(typeName= Extension, field= data)
fun getExtensionData(extensionObjects: List<Extension>, context: GraphQLContext): Map<Extension, Data>{
return requestToAPI() // not relevant
}
A query would be like:
query {
query {
header {
... on ObjectA {
data
}
... on ObjectB {
objectC {
data
}
}
}
}
}
Hope this helps. It's a really confusing situation for me too, unfortunately.
I am having a similar issue and don't know if I should open a new ticket. @Segelente, You mean, that aliasing and passing arguments to the graphql query doesn't work?
I figured, that I can get the BatchLoaderEnvironment, GraphQLContext, Principle. But I don't see the information that I found in the DataFetchingEnvironment in the past. Does it mean, that BatchMapping is only for very simple use cases (almost none in my case)?
I would expect something like @Argument("filter") Map<FilterClass, List<OriginClass>> being possible....
@Segelente could you please use https://start.spring.io to create a starter project with the relevant versions, and then add minimal code that helps to demonstrate the issue. As I said in my previous comment, the behavior depends on the version you're using and a number of other things, so it's best if you iterate over something until you can demonstrate the issue. If that's easy then it shouldn't take long. If it is not, then you can try different things and compare to your code until you can demonstrate it.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Hello everyone, Thanks for your patience. I really appreciate your help. I have created a project: https://github.com/Segelente/demo-nested-batches I hope this helps. Unfortunately, I am not responsible for the design choices and cannot just change the way the schema is set up. If you can't help, I fully understand. Have a nice day.