You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix QP bug querying some fields with @interfaceObject (#2362)
When an interface field is requested only for some implementation, and
the query "transit" through a subgraph using `@interfaceObject`, then
the query planning code was not recognizing early enough that the field
was queried on an implementation type and not the interface itself, and
this lead to a later assertion error.
This commit adds a reproduction test, and fix the issue by simply making
sure, when we build the query plan "paths", to not use an interface field
when it's an implementation field that is queried.
Fix assertion errors thrown by the query planner when querying fields for a specific interface implementation in some cases where `@interfaceObject` is involved
expect(rewrite.path).toEqual(['... on A','__typename']);
313
313
expect(rewrite.setValueTo).toBe('I');
314
314
});
315
+
316
+
test('handles query of an interface field (that is not on the `@interfaceObject`) for a specific implementation when query starts on the @interfaceObject',()=>{
317
+
// Here, we start on S2, but `x` is only in S1. Further, while `x` is on the `I` interface, we only query it for `A`.
318
+
constoperation=operationFromDocument(api,gql`
319
+
{
320
+
iFromS2 {
321
+
... on A {
322
+
x
323
+
}
324
+
}
325
+
}
326
+
`);
327
+
328
+
constplan=queryPlanner.buildQueryPlan(operation);
329
+
expect(plan).toMatchInlineSnapshot(`
330
+
QueryPlan {
331
+
Sequence {
332
+
Fetch(service: "S2") {
333
+
{
334
+
iFromS2 {
335
+
__typename
336
+
id
337
+
}
338
+
}
339
+
},
340
+
Flatten(path: "iFromS2") {
341
+
Fetch(service: "S1") {
342
+
{
343
+
... on I {
344
+
__typename
345
+
id
346
+
}
347
+
} =>
348
+
{
349
+
... on I {
350
+
... on A {
351
+
x
352
+
}
353
+
}
354
+
}
355
+
},
356
+
},
357
+
},
358
+
}
359
+
`);
360
+
});
315
361
});
316
362
317
363
it('avoids buffering @interfaceObject results that may have to filtered with lists',()=>{
0 commit comments