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

Batching between mesh and a gql handler does not work for mutations #3454

Open
angelsvirkov opened this issue Jan 10, 2022 · 1 comment
Open

Comments

@angelsvirkov
Copy link
Contributor

Describe the bug
We cannot batch mutations between the mesh and a GraphQL Handler.

To Reproduce

Here is an example repository with example code and steps to reproduce - https://github.com/angelsvirkov/graphql-mesh-batch-mutations.

  1. Start the apollo gql server with yarn start
  2. Open a new terminal and run yarn start-mesh
  3. A new browser tab should open the GraphiQL Editor on port 4001
  4. Use the following query
mutation Test {
  A: changeName(name: "A")
  B: changeName(name: "B")
  C: changeName(name: "C")
  D: changeName(name: "D")
}
  1. Go to the terminal output of the apollo gql server and check the req.body. There are 4 requests instead of 1.

Expected behavior

The apollo gql server, which is a handler of the GQL Mesh, receives 1 request with all mutations inside of it.

Environment:

  • OS: macOS (but I think it doesn't matter)
  • @graphql-mesh/cli: latest
  • @graphql-mesh/graphql: latest
  • NodeJS: 12 LTS (but I think it doesn't matter)

Reason why it does not work

The default graphql-js execute function calls executeFieldsSerially which breaks down the concept behind the batch-executor of graphql-tools

https://github.com/graphql/graphql-js/blob/main/src/execution/execute.ts#L379

https://www.graphql-tools.com/docs/batch-execution#batch-the-executor

Additional thoughts:
I am not quite sure if graphql-mesh or graphql-tools is a better place for this issue. I could easily move it if needed it.

Regarding a potential solution. I could not come up with a very simple one. The only thing that comes to me is to somehow fake mutations execution as a query execution, but this is more a workaround than a solution and could have other side effects I am not aware of.

@milindsingh
Copy link

Hi @angelsvirkov
Did you find any fix ?

Also, how would we fake mutations execution as a query execution, any suggession?

Thanks

@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants