#Nested object in Args()

7 messages · Page 1 of 1 (latest)

brazen roost
#

Hello, how to make a nested object in my ArgsType()

vocal moss
#

I think it’s just ArgsType on the root one and InputType on the nested one

vagrant crystal
#

@ArgsType is for queries. @InputType is for mutations. Are you sending those objects off to a query or a mutation @brazen roost ?

brazen roost
#

query

vagrant crystal
#

Then you should be using ArgType.

vocal moss
# vagrant crystal `@ArgsType` is for queries. `@InputType` is for mutations. Are you sending those...

That I know, but when you want to nest an object within Args object, you have to use InputType as of now. Maybe it's a bug and ArgsType should work on all levels?

import {
  Args,
  ArgsType,
  Field,
  InputType,
  Query,
  Resolver,
} from '@nestjs/graphql';
import GraphQLJSON from 'graphql-type-json';

@InputType() // Doesn't work with @ArgsType
export class Filter {
  @Field(() => String) field!: string;
  @Field(() => GraphQLJSON) value!: any;
}

@ArgsType()
export class GetCompaniesArgs {
  @Field(() => Filter, { nullable: true }) filter?: Filter | null;
  @Field(() => String, { nullable: true }) orderBy?: string | null;
  // and other get companies arguments
}

@Resolver()
export class StatusResolver {
  @Query(() => String)
  status(@Args() args: GetCompaniesArgs): string {
    return 'ok';
  }
}

I was helping with that recently: #1038034977213915206 message

vagrant crystal
#

I'd say it is a bug.