0

I'm using @nestjs/graphql to build graphql API. I have the following object

@ObjectType('Round')
export class RoundDto {
  @Field(() => GraphQLInt)
  round: number;

  @Field(() => [[GraphQLString]])
  teams: Nullable<[string, string]>[];
}

How Can I declare the teams field to return mixed values of string and null? Do I need to write own scalar for it?

I'm expecting to receive teams like

teams: [[1, 2], null, [3, 4], null]

But getting the error Cannot return null for non-nullable field Round.teams.

Pavlo Naumenko
  • 561
  • 5
  • 15

1 Answers1

0

Regarding this Answer to this question, the decision is returning a tuple or empty array

@ObjectType('Round')
export class RoundDto {
  @Field(() => GraphQLInt)
  round: number;

  @Field(() => [[GraphQLString]])
  teams: ([string, string] | [])[];
}

The answer will be teams: [[1, 2],[], [3, 4],[]]

Pavlo Naumenko
  • 561
  • 5
  • 15