简体   繁体   中英

TypeGraphql InputType Field with enum value doesn't let in string (quoted text)

Created a project with TypeGraphql in typescript. Trying to make a field to be an enum with string values. If I send these values , or names to the mutation endpoint they throw me an error:

"errors": [
        {
            "message": "Expected type Tipe!, found \"Contract\"; Did you mean the enum value Contract?",
            "locations": [
                {

Following DTO:

import { Tipe } from "../validators/enums/ContactEnums";

@ObjectType()
@Entity()
export class Contact extends BaseEntity {
  @Field(() => ID)
  @PrimaryColumn("uuid")
  id: string;

  @Field()
  @Column("enum", { enum: Tipe })
  tipe: Tipe;

Enum type:

export enum Tipe {
    "Contract" = "CONTRACT",
    "Person" = "PERSON"
}

Inputtype:

@InputType()
export class ContactInput {
  @Field()
  id: string;

  @Field(() => Tipe)
  tipe: string;

You have to use variables if you want to send enum values as strings:

query SampleQuery($sampleArg: Tipe!) {
  sample(sampleArg: $sampleArg) {
    field 
  }
}
{
  sampleArg: "Contract"
}

If you make your query static and provide the enum inline, you can't wrap it in quotes:

query {
  sample(sampleArg: Contract) {
    field 
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM