Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Batches #997

Open
Segelente opened this issue Jun 14, 2024 · 8 comments
Open

Nested Batches #997

Segelente opened this issue Jun 14, 2024 · 8 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@Segelente
Copy link

Segelente commented Jun 14, 2024

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
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2024
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jul 3, 2024

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?

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Jul 3, 2024
@Segelente
Copy link
Author

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?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 9, 2024
@bclozel
Copy link
Member

bclozel commented Jul 9, 2024

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.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 9, 2024
@Segelente
Copy link
Author

Segelente commented Jul 9, 2024

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 9, 2024
@mheidt
Copy link

mheidt commented Jul 10, 2024

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> being possible....

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jul 11, 2024

@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.

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 15, 2024
@spring-projects-issues
Copy link
Collaborator

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.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jul 22, 2024
@Segelente
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

5 participants