Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateQueryFragments generates invalid plans with missing fragment definitions #2993

Merged
merged 5 commits into from
May 2, 2024
Merged
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions query-planner-js/src/__tests__/buildPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5215,6 +5215,7 @@ describe('Fragment autogeneration', () => {
type A {
x: Int
y: Int
z: Int
t: T
}

Expand Down Expand Up @@ -5425,6 +5426,60 @@ describe('Fragment autogeneration', () => {
}
`);
});

it("handles fragments that are identical except for aliases", () => {
const [api, queryPlanner] = composeAndCreatePlannerWithOptions([subgraph], {
generateQueryFragments: true,
});
const operation = operationFromDocument(
api,
gql`
query {
t {
... on A {
x
y
}
}
t2 {
... on A {
y
z
}
}
}
`,
);

const plan = queryPlanner.buildQueryPlan(operation);

expect(plan).toMatchInlineSnapshot(`
QueryPlan {
Fetch(service: "Subgraph1") {
{
t {
__typename
..._generated_onA2_0
}
t2 {
__typename
..._generated_onA2_1
}
}

fragment _generated_onA2_0 on A {
x
y
}

fragment _generated_onA2_1 on A {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fragment is missing in practice.

y
z
}
},
}
`);
});
});

test('works with key chains', () => {
Expand Down