1

I use graphql-codegen + graphql-request to mutate some data like this:

export const updateRoomQuery = graphql(/* GraphQL */ `
  mutation UpdateRoomInOffice($cmd: UpdateRoomInOfficeInput!) {
    updateRoomInOffice(cmd: $cmd) {
      roomId
      roomType
    }
  }
`);

roomType is this:

enum RoomType {
  CHECKIN
  CHECKOUT
  DOCSOFFICE
  EXAM
  OTHER
}

input UpdateRoomInOfficeInput {
  roomId: UUID!
  roomType: RoomType!
}

In JS I call:

GQLClient.request(updateRoomQuery, { cmd: { roomType: "EXAM", roomId: '123' } });

And get this error:

The specified value type of field `roomType` does not match the field type.

I get that in the quotes are the problem, but how do I tell graphql-request that roomType should be treated as enum?

Spadar Shut
  • 15,111
  • 5
  • 47
  • 54
  • What exactly is `GQLClient`? – Bergi Apr 28 '23 at 16:56
  • No, the quotes are not a problem, it is valid to pass a string in the JSON value for a variable. Assuming `GQLClient.request` does send the argument as a separate variables object, that is. – Bergi Apr 28 '23 at 16:58
  • 1
    Can you show the actual request that is arriving at the server? – Bergi Apr 28 '23 at 16:58
  • @Bergi thanks for replies. The problem was that I was sending some extra fields in the request. – Spadar Shut Apr 30 '23 at 14:17
  • @SpadarShut then please add this as an answer. Other people have had the same problem and your solution may be useful to them. (That's the whole point of StackOverflow, after all). – MGOwen Aug 25 '23 at 09:40

0 Answers0