Skip to content

Commit 3318773

Browse files
committed
Add test case (#10647)
1 parent 1727493 commit 3318773

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

packages/plugins/typescript/operations/tests/ts-documents.skip-include-directives.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,51 @@ describe('TypeScript Operations Plugin - @include directives', () => {
129129
`);
130130
});
131131

132+
it('#10616 - @include on fragment with inlineFragmentTypes:combine should generate optional fragment', async () => {
133+
const schema = buildSchema(/* GraphQL */ `
134+
type Query {
135+
user: User
136+
}
137+
138+
type User {
139+
name: String
140+
}
141+
`);
142+
143+
const document = parse(/* GraphQL */ `
144+
fragment Name on User {
145+
name
146+
}
147+
query user($withName: Boolean! = false) {
148+
user {
149+
...Name @include(if: $withName)
150+
}
151+
}
152+
`);
153+
154+
const { content } = await plugin(
155+
schema,
156+
[{ location: '', document }],
157+
{ inlineFragmentTypes: 'combine' },
158+
{ outputFile: '' }
159+
);
160+
161+
expect(content).toMatchInlineSnapshot(`
162+
"export type NameFragment = { name: string | null };
163+
164+
export type UserQueryVariables = Exact<{
165+
withName?: boolean;
166+
}>;
167+
168+
169+
export type UserQuery = { user:
170+
| { name?: string | null }
171+
| Record<PropertyKey, never>
172+
| null };
173+
"
174+
`);
175+
});
176+
132177
it('fields with @include should pre resolve into optional', async () => {
133178
const schema = buildSchema(/* GraphQL */ `
134179
type Query {

0 commit comments

Comments
 (0)