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

repro bug with repeated fragments spreads and generate query fragments #3042

Closed
Closed
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
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(`
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore this expectation, the test fails due to validation errors before this.

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