Type-graphql: Typed property on InputType

Created on 26 Jun 2018  路  2Comments  路  Source: MichalLytek/type-graphql

How do I add a typed property to an input type?

Using the following code, I get the following error:

Error:

{
    errorMessage: "Error while loading api",
    errorType: "Error",
    stackTrace: [
        "Error: Cannot determine GraphQL input type for name",
        ...
    ]
}

Code:

import { Field, ObjectType, InputType, Int } from 'type-graphql';

@ObjectType()
export class Name {
    @Field()
    given: string;

    @Field()
    family: string;
}

@ObjectType()
export class PersonResult {
    @Field()
    id: string;

    @Field(type => Name)
    name: Name;

    @Field()
    email_address: string;
}

@InputType()
export class PersonInput implements Partial<PersonResult> {
    @Field(type => Name)
    name: Name;

    @Field()
    email_address: string;
}
Question Solved

Most helpful comment

My bad. I hadn't specified InputType on the Name class.

@ObjectType()
@InputType('NameInput')
export class Name {
    @Field() given: string;

    @Field() family: string;
}

All 2 comments

My bad. I hadn't specified InputType on the Name class.

@ObjectType()
@InputType('NameInput')
export class Name {
    @Field() given: string;

    @Field() family: string;
}

Same error here, same solution as well.
Add @InputType()
Thanks~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avkonst picture avkonst  路  3Comments

MichalLytek picture MichalLytek  路  3Comments

Asim13se picture Asim13se  路  3Comments

Janushan picture Janushan  路  3Comments

robertchung97 picture robertchung97  路  3Comments