Skip to content

Commit

Permalink
Add fallback to unknown for missing selection sets
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jan 11, 2024
1 parent 88ef160 commit 616a2ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/__tests__/selection.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ test('infers unknown fields as `unknown`', () => {
expectTypeOf<expected>().toEqualTypeOf<actual>();
});

test('infers object fields with missing selection set as `unknown`', () => {
type query = parseDocument</* GraphQL */ `
query { latestTodo }
`>;

type actual = getDocumentType<query, schema>;
type expected = { latestTodo: unknown };

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

test('infers adjacent inline fragments', () => {
type query = parseDocument</* GraphQL */ `
query { todos { id ... on Todo { text } ... on Todo { complete } } }
Expand Down
2 changes: 1 addition & 1 deletion src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type _unwrapTypeRec<
Introspection,
Fragments
>
: {}
: unknown
: Introspection['types'][Type['name']]['type']
: unknown;

Expand Down

0 comments on commit 616a2ab

Please sign in to comment.