I am trying to setup my graphql resover to handle an array of objects but cant get the @Args decorator configured.
I created my own ArgsType
import { ArgsType, Field, Int, ObjectType } from '@nestjs/graphql';
@ArgsType() // to be used as type in the resolver
@ObjectType() // for schema generation
export class Club {
@Field(type => String)
president: string;
@Field(type => Int)
members?: number;
}
Resolver with adding a single Club works just fine!
@Query(() => Int)
async addClub(@Args() club: Club) {
// handle stuff
}
but if I want to give an array of Club like this
@Query(() => Int)
async addClubs(@Args({name: 'clubs', type: () => [Club]}) clubs: Array<Club>) {
// handle stuff
}
this thows an error when nest is starting up
UnhandledPromiseRejectionWarning: Error: Cannot determine a GraphQL input type for the "clubs". Make sure your class is decorated with an appropriate decorator.
although I am able to use an array of Strings like this
@Query(() => [String])
async addStrings(@Args({ name: 'clubs', type: () => [String], }) clubs: Array<string>) {
// handle stuff
}
I am pretty sure there should be an easy solution, but cant figure out where to go from here.