aPureBase/KGraphQL

Using enum as argument

tiagonuneslx opened this issue · 1 comments

I'm following the tutorial from the GraphQL official documentation .
I'm trying to implement this feature.

But I'm running into this issue:
When I try to pass an enum value as argument (e.g. height(unit: FEET)), it says it's an invalid value.
I wasn't able to find documentation on how to customise enum deserialisation logic.

Code:

query("human") {
    resolver { -> luke }
}
type<Human> {
    transformation(Human::height) { height: Double, unit: DimUnit ->
        height * unit.factor
    }
}
enum<DimUnit>()

enum class DimUnit(val factor: Double) {
    METER(1.0),
    FOOT(3.28084)
}

GraphQL query:

{
  human(id: "2000") {
    name
    height(unit: FEET)
  }
}

Response:

{
  "errors": [
    {
      "message": "Invalid enum DimUnit value. Expected one of [com.apurebase.kgraphql.schema.structure.EnumValue@e748a72, com.apurebase.kgraphql.schema.structure.EnumValue@e322e05]",
      "locations": [
        {
          "line": 8,
          "column": 18
        }
      ],
      "path": []
    }
  ]
}

Nevermind, this is working correctly and documented.

The problem was that I was writing unit: FEET instead of unit: FOOT.

I'm closing this issue.