DragonBobZ
DragonBobZ

Reputation: 2444

Enum $EnumName cannot represent non-enum value: "$EnumValue". Did you mean the enum value "$EnumValue"

I am trying to create an optional filter on a resolver for my toy GraphQL API, which uses [email protected] and [email protected]. I am getting this error message when I run my query that seems contradictory. I've followed the enum example in the documentation pretty closely, but I'm sure I'm missing something.

Here is the query:

{
  authors(
    field: "name",
    op: "CONTAINS",
    value: "Jones"
  ) {
    id,
    name
  }
}

And the result:

{
  "error": {
    "errors": [
      {
        "message": "Enum \"FilterType\" cannot represent non-enum value: \"CONTAINS\". Did you mean the enum value \"CONTAINS\"?"
      }
    ]
  }
}

And the enum

enum FilterType {
    EQ = "=",
    // . . .
    CONTAINS = "CONTAINS",
    IN = "in"
}

registerEnumType(FilterType, {
    name: "FilterType",
    description: "Type of comparison operation to perform during the filter",
});

export {
    FilterType
}

And my Resolver/ArgsType.


@ArgsType()
class FilterAuthorArgs {
    @Field(() => String, {nullable: true})
    field?: string;

    @Field(() => FilterType, {nullable: true})
    op?: FilterType;

    @Field(() => String, {nullable: true})
    value?: string;

    // . . .

    get _field(): string|undefined {
        this.validate();
        return this.field
    }

    get _op(): FilterType|undefined {
        this.validate();
        return this.op
    }

    get _value(): string|undefined {
        this.validate();
        return this.value
    }
}

@Resolver()
export class AuthorResolver {
    @Query(()=> [Author])
    authors(@Args() {_field, _op, _value}: FilterAuthorArgs) {
        // use filters
        return authors;
    }
}

Upvotes: 2

Views: 7265

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

Double quotation marks in GraphQL indicate a string literal. If your query takes an enum value, you should omit the quotation marks:

{
  authors(
    field: "name",
    op: CONTAINS,
    value: "Jones"
  ) {
    id,
    name
  }
}

Upvotes: 9

Related Questions