Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rich-tips-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@apollo/query-planner": patch
"@apollo/query-graphs": patch
---

Ignore non-resolvable keys when adding a subgraph jump for `@requires`/`@fromContext`.
3 changes: 3 additions & 0 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
91 changes: 91 additions & 0 deletions query-planner-js/src/__tests__/buildPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,97 @@ describe('@requires', () => {
}
`);
});

it('ignores non-resolvable keys when inserting self jump for @requires', () => {
const subgraph1 = {
name: 'A',
typeDefs: gql`
type Query {
t: T
}

type T @key(fields: "id1", resolvable: false) @key(fields: "id2 id3") {
id1: ID!
id2: ID!
id3: ID!
req: Int @external
v: Int @requires(fields: "req")
}
`,
};

const subgraph2 = {
name: 'B',
typeDefs: gql`
type T @key(fields: "id1") {
id1: ID!
req: Int
}
`,
};

const [api, queryPlanner] = composeAndCreatePlanner(subgraph1, subgraph2);
const operation = operationFromDocument(
api,
gql`
{
t {
v
}
}
`,
);

const plan = queryPlanner.buildQueryPlan(operation);
expect(plan).toMatchInlineSnapshot(`
QueryPlan {
Sequence {
Fetch(service: "A") {
{
t {
__typename
id1
id2
id3
}
}
},
Flatten(path: "t") {
Fetch(service: "B") {
{
... on T {
__typename
id1
}
} =>
{
... on T {
req
}
}
},
},
Flatten(path: "t") {
Fetch(service: "A") {
{
... on T {
__typename
req
id2
id3
}
} =>
{
... on T {
v
}
}
},
},
},
}
`);
});
});

describe('fetch operation names', () => {
Expand Down