Skip to content

Commit

Permalink
repro bug with repeated fragments spreads and generate query fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Andre Giroux committed Jun 19, 2024
1 parent 0d8a885 commit 9238c8b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions internals-js/src/__tests__/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,72 @@ function astSSet(...selections: SelectionNode[]): SelectionSetNode {
};
}

describe('generate query fragments', () => {
test('generateQueryFragments handles repeated fragment spreads', () => {
const schema = parseSchema(`
type Query {
entities: [Entity]
}
union Entity = A | B
type A {
a: Int
}
type B {
b: Int
}
`);

const operation = parseOperation(schema, `
query {
entities {
... on B {
... on B {
... on B {
... on B {
b
}
}
}
}
}
}
`);

const withGeneratedFragments = operation.generateQueryFragments();
expect(withGeneratedFragments.toString()).toMatchString(`
{
t {
... on T1 {
a
b
}
... on T2 {
x
y
}
b
u {
... on I {
b
}
... on T1 {
a
b
}
... on T2 {
x
y
}
}
}
}
`);
});
});

describe('fragments optimization', () => {
// Takes a query with fragments as inputs, expand all those fragments, and ensures that all the
// fragments gets optimized back, and that we get back the exact same query.
Expand Down

0 comments on commit 9238c8b

Please sign in to comment.