Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using enum as argument #208

Closed
tiagonuneslx opened this issue Jan 30, 2023 · 1 comment
Closed

Using enum as argument #208

tiagonuneslx opened this issue Jan 30, 2023 · 1 comment

Comments

@tiagonuneslx
Copy link

tiagonuneslx commented Jan 30, 2023

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
Copy link
Author

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.

@tiagonuneslx tiagonuneslx closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant