aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
298 stars 58 forks source link

Using enum as argument #208

Closed tiagonuneslx closed 1 year ago

tiagonuneslx commented 1 year ago

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": []
    }
  ]
}
tiagonuneslx commented 1 year ago

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.