Skip to content

enum coercion in mutation argument from string does not work... #122

@johanatan

Description

@johanatan

... however coercion from int does (arguably coercion from string is more useful than coercion from int).

Schema:

enum Color { blue, orange, green } // mapped to 1, 2, 3

type Favorite {
  id: ID!
  color: Color
}

Client:

curl -XPOST -H 'Content-Type:application/graphql' -d '{"query":"mutation createFavorite($color: Color!) { createFavorite(color:$color) { color } }", "params":{"color":2}}' http://localhost:3000/graphql    
{
  "data": {
    "createFavorite": null  // Server is returning null at the moment but server logs are pasted below.
  }
}

Server:

Received insert request: uid: c4e1dd90-9b89-4fcf-8b6b-c32e9f63dccb, entity: Favorite, params: {"color" "{\"orange\" {
Returning: null

Bad request:

curl -XPOST -H 'Content-Type:application/graphql' -d '{"query":"mutation createFavorite($color: Color!) { createFavorite(color:$color) { color } }", "params":{"color":"orange"}}' http://localhost:3000/graphql    
{
  "errors": [
    {
      "message": "Variable $color expected value of type Color! but got: \"orange\".",
      "stack": "Variable $color expected value of type Color! but got: \"orange\".",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions