'Race condition like behavior in Apollo Resolvers
We've been having some strange issues with field resolution using Apollo federation --
We have a type defined in Service A called ObjectA. We extended ObjectA in Service B by adding the localizedName field
ObjectA @key(fields: "id") {
id
name
localizedName @requires(fields: "id name")
}
Generally, everything works fine, however when we use a resolver from Service B which returns data in the form of
{
__typename: "ObjectB",
AList: [{__typename: "ObjectA", id: "someId" }],
... other ObjectB fields
}
Fields from ObjectA such as name are returned properly by the resolveReference function, however the localizedName field is usually, but not always null. When the field is null, we see the error
"message": "Field \"name\" was not found in response.",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Field \"name\" was not found in response.",
" at executeSelectionSet (C:\\Users\\user\\Documents\\workspace\\gateway\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:230:27)",
When this possible race condition does not occur, the service works correctly and the localizedName field is resolved.
Is there something that I can do to resolve this? It seems to stem from the query plan trying to fetch the data from B for the field before the resolveReference has been called in A.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
