Skip to content

Commit

Permalink
Expand test for more optional fragment spreads (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jan 17, 2024
1 parent d51c841 commit 5ec067e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/__tests__/selection.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,64 @@ test('infers optional properties for @skip/@include', () => {
expectTypeOf<expected>().toEqualTypeOf<actual>();
});

test('infers optional fragment for @defer', () => {
type query = parseDocument</* GraphQL */ `
query {
todos {
...TodoFields @defer
}
}

fragment TodoFields on Todo {
id
}
`>;

type actual = getDocumentType<query, schema>;

type expected = {
todos: Array<
| {
id: string | number;
}
| {}
| null
> | null;
};

expectTypeOf<expected>().toEqualTypeOf<actual>();
});

test('infers optional inline fragment for @defer', () => {
type query = parseDocument</* GraphQL */ `
query {
todos {
...TodoFields
}
}

fragment TodoFields on Todo {
... on Todo @defer {
id
}
}
`>;

type actual = getDocumentType<query, schema>;

type expected = {
todos: Array<
| {
id: string | number;
}
| {}
| null
> | null;
};

expectTypeOf<expected>().toEqualTypeOf<actual>();
});

test('infers enum values', () => {
type query = parseDocument</* GraphQL */ `
query { todos { id test } }
Expand Down Expand Up @@ -372,3 +430,23 @@ test('creates a type for a given fragment', () => {

expectTypeOf<expected>().toEqualTypeOf<actual>();
});

test('creates a type for a given fragment with optional inline spread', () => {
type fragment = parseDocument<`
fragment Fields on Todo {
... on Todo @defer {
id
}
}
`>;

type actual = getDocumentType<fragment, schema>;

type expected =
| {}
| {
id: number | string;
};

expectTypeOf<expected>().toEqualTypeOf<actual>();
});

0 comments on commit 5ec067e

Please sign in to comment.