diff --git a/packages/graphqlgen/src/generators/common.ts b/packages/graphqlgen/src/generators/common.ts index 3038f3ce..9a044467 100644 --- a/packages/graphqlgen/src/generators/common.ts +++ b/packages/graphqlgen/src/generators/common.ts @@ -261,10 +261,10 @@ export const printFieldLikeType = ( if (field.type.isArray) { rendering = array(rendering, { innerUnion: false }) - } - if (!field.type.isArrayRequired) { - rendering = nullable(rendering) + if (!field.type.isArrayRequired) { + rendering = nullable(rendering) + } } // We do not have to handle defaults becuase graphql only diff --git a/packages/graphqlgen/tests/fixtures/interface/schema.graphql b/packages/graphqlgen/tests/fixtures/interface/schema.graphql index faf187e7..ad08ab70 100644 --- a/packages/graphqlgen/tests/fixtures/interface/schema.graphql +++ b/packages/graphqlgen/tests/fixtures/interface/schema.graphql @@ -1,5 +1,6 @@ type Query { media(first: Int): [Media] + mediaItem(id: Int!): Media } interface Unused { diff --git a/packages/graphqlgen/tests/typescript/__snapshots__/basic.test.ts.snap b/packages/graphqlgen/tests/typescript/__snapshots__/basic.test.ts.snap index 03b859c2..bb909ee0 100644 --- a/packages/graphqlgen/tests/typescript/__snapshots__/basic.test.ts.snap +++ b/packages/graphqlgen/tests/typescript/__snapshots__/basic.test.ts.snap @@ -350,6 +350,10 @@ export namespace QueryResolvers { first?: number | null; } + export interface ArgsMediaItem { + id: number; + } + export type MediaResolver = ( parent: undefined, args: ArgsMedia, @@ -360,6 +364,13 @@ export namespace QueryResolvers { | null | Promise | null>; + export type MediaItemResolver = ( + parent: undefined, + args: ArgsMediaItem, + ctx: Context, + info: GraphQLResolveInfo + ) => Image | Video | null | Promise; + export interface Type { media: ( parent: undefined, @@ -370,6 +381,13 @@ export namespace QueryResolvers { | Array | null | Promise | null>; + + mediaItem: ( + parent: undefined, + args: ArgsMediaItem, + ctx: Context, + info: GraphQLResolveInfo + ) => Image | Video | null | Promise; } } @@ -615,6 +633,9 @@ export const Query: QueryResolvers.Type = { ...QueryResolvers.defaultResolvers, media: (parent, args, ctx) => { throw new Error(\\"Resolver not implemented\\"); + }, + mediaItem: (parent, args, ctx) => { + throw new Error(\\"Resolver not implemented\\"); } }; ",