In a nutshell, there is an issue with resolving interface entity in this specific scenario which I'm about to show. I'm sure there are other cases but this is how we figured it out.
In order to make this showcase a bit more interesting, I added the Product key as resolveInMs which resolves the Product in variable amount of time. Please note that all data resolved are static. Variant entity is resolved in 3 milliseconds, Inventory is resolved in 5 milliseconds and Product is resolved with the resolveInMs argument time. Here are some results from some queries. With all data being static, one would expect the same result for queries independent of the resolve time. But here are results for some queries:
When __typename is not queried from Product , then everything goes ok.
When Variant.Inventory nested entity is not queried, then everything goes ok.
When both above is queried, and Product entity is resolved after Variant.Inventory, everything goes ok.
When both above is queried and Product entity is resolved before Variant.Inventory , then Product resolved to null.
I tested Product as regular entity as well and there is no issue with that. So, the issue happens with only interface entities and requesting __typename while a nested entity is resolved next to it.
Additional Context
In all the scenarios, subgraph responses are the same. So, it is not subgraph issue.
In all the scenarios, query plan is fine, so it is not a query planner issue.
Thanks for the detailed write up @aliosmanisikk , quite helpful. It now requires our project to write quite a cumbersome, far from ideal workaround. Any help from Apollo? 🙏
Describe the bug
It is hard to describe this issue since we don't know the exact issue but I'll try to explain our use case where I created a showcase here https://github.com/aliosmanisikk/apollo-router-entity-error-showcase
In a nutshell, there is an issue with resolving interface entity in this specific scenario which I'm about to show. I'm sure there are other cases but this is how we figured it out.
To Reproduce
Setup 2 subgraphs
SubgraphA schema
Subgraph B schema
In order to make this showcase a bit more interesting, I added the
Product
key asresolveInMs
which resolves the Product in variable amount of time. Please note that all data resolved are static.Variant
entity is resolved in 3 milliseconds,Inventory
is resolved in 5 milliseconds andProduct
is resolved with theresolveInMs
argument time. Here are some results from some queries. With all data being static, one would expect the same result for queries independent of the resolve time. But here are results for some queries:Summary
__typename
is not queried fromProduct
, then everything goes ok.Variant.Inventory
nested entity is not queried, then everything goes ok.Product
entity is resolved afterVariant.Inventory
, everything goes ok.Product
entity is resolved beforeVariant.Inventory
, thenProduct
resolved tonull
.I tested
Product
as regular entity as well and there is no issue with that. So, the issue happens with only interface entities and requesting__typename
while a nested entity is resolved next to it.Additional Context