diff --git a/.changeset/strange-nails-ring.md b/.changeset/strange-nails-ring.md new file mode 100644 index 00000000..8e8474f3 --- /dev/null +++ b/.changeset/strange-nails-ring.md @@ -0,0 +1,5 @@ +--- +'gql.tada': patch +--- + +Handle inference of input object fields with missing `defaultValue` properties in introspection. diff --git a/src/__tests__/fixtures/simpleIntrospection.ts b/src/__tests__/fixtures/simpleIntrospection.ts index 6a5cb494..b3c833b9 100644 --- a/src/__tests__/fixtures/simpleIntrospection.ts +++ b/src/__tests__/fixtures/simpleIntrospection.ts @@ -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: { diff --git a/src/__tests__/fixtures/simpleSchema.ts b/src/__tests__/fixtures/simpleSchema.ts index 85c07194..bf772c62 100644 --- a/src/__tests__/fixtures/simpleSchema.ts +++ b/src/__tests__/fixtures/simpleSchema.ts @@ -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: { diff --git a/src/__tests__/variables.test-d.ts b/src/__tests__/variables.test-d.ts index 0b4ea343..8fc6e039 100644 --- a/src/__tests__/variables.test-d.ts +++ b/src/__tests__/variables.test-d.ts @@ -29,7 +29,7 @@ describe('getVariablesType', () => { expectTypeOf().toEqualTypeOf<{ id: string | number; - input: { title: string; complete?: boolean | null }; + input: { title: string; complete?: boolean | null; description: string }; }>(); }); @@ -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>().toEqualTypeOf(); }); }); diff --git a/src/variables.ts b/src/variables.ts index fedbb97c..754ea24f 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -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 } : { [Name in InputField['name']]?: unwrapType | null } : {}) &