graphqllaravel-lighthouse

Can I use enum value in /graphql-playground for update mutation?


Adding enums in laravel 9 / lighthouse 6 app as I read this https://lighthouse-php.com/6/the-basics/types.html#enum

I have in graphql/vote.graphql :

enum VoteStatus {
    NEW @enum(value: "N")
    ACTIVE @enum(value: "A")
    INACTIVE @enum(value: "I")
}

"Vote entity."
type Vote {
    "Unique primary key."
    id: ID!
   ...
    "Enum(N=>New,  A=>Active, I=>Inactive) status."
    status: VoteStatus!
   ...

But I failed to use it in /graphql-playground as :

mutation {
  updateVote(
     id: 2
     name:"Updated vote98"
     status: VoteStatus::ACTIVE
     description:"Updated vote description text lorem"
     vote_category_id:2
     ordering: 987 

It looks like syntax error and I can not run request : https://prnt.sc/Qw6J9En6Ch6u

If to replace VoteStatus::ACTIVE with “ACTIVE” string (as I defined in VoteStatus) I got error : https://prnt.sc/5zywKOr1xsln

Can I use VoteStatus::ACTIVE in /graphql-playground somewhay ?


Solution

  • You need to pass enum values as the unquoted key, in your example:

    mutation {
      updateVote(
         status: ACTIVE