graphql-resolve-batch icon indicating copy to clipboard operation
graphql-resolve-batch copied to clipboard

Batching interface types

Open trickleup opened this issue 5 years ago • 1 comments

Hi, I'm seeing an issue when batching interface types. I have a query that returns an interface, that resolves to a few different types. Then, on each of those types, I query an interface field. In this case, it seems that the resolutions are batched by type. I wonder if this is intentional, if there's a known way to override it, or work around it?

For example, in the following query, the lookup query returns an array of MyInterface types, that all have a name property. However, the object with id abc123 is of TypeA and abc456 of TypeB (both implementing MyInterface).

# Write your query or mutation here
{
  lookup(
    ids: [
      "abc123"
      "abc456"
    ]
  ) {
    meta {
      name
    }
  }
}

In this case, the batch resolver creates two batches, and I would like it to create one. E.g. is it possible to group based on interface instead of concrete type?

trickleup avatar Mar 14 '19 18:03 trickleup

This library uses two heuristics for batching:

  1. All resolvers that are run before the next event-loop run are batched.
  2. All resolvers that are run with the same query AST node are batched.

I doubt it’s the second heuristic that’s broken here. Is there any reason why your two interfaces would resolve on different event-loop ticks? Can you make a minimal viable reproducing case?

calebmer avatar Mar 14 '19 23:03 calebmer