Skip to content

Commit

Permalink
Fix bugs with non-resolvable keys (and related bugs with interface ob…
Browse files Browse the repository at this point in the history
…jects)
  • Loading branch information
sachindshinde committed Sep 18, 2024
1 parent a7a74c5 commit d38faf4
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions query-graphs-js/src/graphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,9 @@ export function getLocallySatisfiableKey(graph: QueryGraph, typeVertex: Vertex):
assert(metadata, () => `Could not find federation metadata for source ${typeVertex.source}`);
const keyDirective = metadata.keyDirective();
for (const key of type.appliedDirectivesOf(keyDirective)) {
if (!(key.arguments().resolvable ?? true)) {
continue;
}
const selection = parseFieldSetArgument({ parentType: type, directive: key });
if (!metadata.selectionSelectsAnyExternalField(selection)) {
return selection;
Expand Down Expand Up @@ -2055,10 +2058,10 @@ function canSatisfyConditions<TTrigger, V extends Vertex, TNullEdge extends null
}
const pathTree = resolution.pathTree;
const lastEdge = path.lastEdge();
if (edge.transition.kind === 'FieldCollection'
if ((edge.transition.kind === 'FieldCollection' || edge.transition.kind === 'InterfaceObjectFakeDownCast')
&& lastEdge !== null
&& lastEdge?.transition.kind !== 'KeyResolution'
&& (!pathTree || pathTree.isAllInSameSubgraph())) {
&& (!pathTree || !pathTree.isAllInSameSubgraph())) {

debug.log('@requires conditions are satisfied, but validating post-require key.');
const postRequireKeyCondition = getLocallySatisfiableKey(path.graph, edge.head);
Expand Down Expand Up @@ -2325,6 +2328,25 @@ export function advanceSimultaneousPathsWithOperation<V extends Vertex>(
}
debug.groupEnd();
}
} else if (operation.kind === 'FragmentElement' && path.tailIsInterfaceObject()) {
const pathsWithNonCollecting = subgraphSimultaneousPaths.indirectOptions(updatedContext, i);
for (const pathWithNonCollecting of pathsWithNonCollecting.paths) {
// if (!isInterfaceType(pathWithNonCollecting.tail.type)) {
// continue;
// }
const { options: pathWithOperation } = advanceWithOperation(
supergraphSchema,
pathWithNonCollecting,
operation,
updatedContext,
subgraphSimultaneousPaths.conditionResolver,
overrideConditions,
);
if (!pathWithOperation) {
continue;
}
options = options.concat(pathWithOperation);
}
}

// If we were entering a @defer, we've skipped the potential "direct" options because we need an "indirect" one (a key/root query)
Expand Down

0 comments on commit d38faf4

Please sign in to comment.