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

fix: Fix input object field introspection with missing defaultValue properties #101

Merged
merged 5 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/strange-nails-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gql.tada': patch
---

Handle inference of input object fields with missing `defaultValue` properties in introspection.
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/simpleIntrospection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export type simpleIntrospection = {
},
defaultValue: null,
},
{
name: 'description',
type: {
kind: 'NON_NULL',
ofType: {
kind: 'SCALAR',
name: 'String',
ofType: null,
},
},
},
{
name: 'complete',
type: {
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/simpleSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ export type simpleSchema = {
};
defaultValue: null;
},
{
name: 'description';
type: {
kind: 'NON_NULL';
ofType: {
kind: 'SCALAR';
name: 'String';
ofType: null;
};
};
},
{
name: 'complete';
type: {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/variables.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('getVariablesType', () => {

expectTypeOf<variables>().toEqualTypeOf<{
id: string | number;
input: { title: string; complete?: boolean | null };
input: { title: string; complete?: boolean | null; description: string };
}>();
});

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('getScalarType', () => {
});

it('gets the type of an input object', () => {
type expected = { title: string; complete?: boolean | null };
type expected = { title: string; complete?: boolean | null; description: string };
expectTypeOf<getScalarType<'TodoPayload', schema>>().toEqualTypeOf<expected>();
});
});
2 changes: 1 addition & 1 deletion src/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type getInputObjectTypeRec<
Rest,
Introspection,
(InputField extends { name: any; type: any }
? InputField extends { defaultValue: undefined | null; type: { kind: 'NON_NULL' } }
? InputField extends { defaultValue?: undefined | null; type: { kind: 'NON_NULL' } }
? { [Name in InputField['name']]: unwrapType<InputField['type'], Introspection> }
: { [Name in InputField['name']]?: unwrapType<InputField['type'], Introspection> | null }
: {}) &
Expand Down
Loading