Enum not converted to Enum type when fetched from DataFetchingEvironment arguments when Query Default Value is used · Issue #444 · graphql-java-kickstart/graphql-java-tools · GitHub
Skip to content

Enum not converted to Enum type when fetched from DataFetchingEvironment arguments when Query Default Value is used #444

Closed

Description

@jcromp

I'd like to preface this by saying I am new to GraphQL and this could easily be an issue in my Query.

I have recreated the issue with unit tests here: https://github.com/jcromp/graphql-enum-error-example
mvn test should do the trick.

The query should take a list of Enum's and if no values are provided it should default to a list of ALL the possible enum values:

type Query {
     foos(fooStatus: [StatusEnum!] = [GOOD, BAD, UGLY]): [Foo]
}

enum StatusEnum {
    GOOD,
    BAD,
    UGLY
}

This works perfectly fine if I am providing the values to the query. However, when I don't provide value(s) and the default value is used, when the resolver gets the arguments from the DataFetchingEnvironment they come out as Strings and not their Enum type, this causes a ClassCastException: class java.lang.String cannot be cast to class com.example.enumerrorexample.StatusEnum

If this is me not understanding something could someone please let me know what I am doing wrong.

Thanks.

Activity

  1. kumartheashwani commented on Jan 25, 2021

    @kumartheashwani

    @vojtapol Is this issue resolved? Can I take this bug if no one is working on it.

  2. oryan-block commented on Oct 3, 2026

    @oryan-block
    Collaborator

    Fixed in 11.1.1 by #572: default values are now passed to graphql-java with defaultValueLiteral, so enum defaults are coerced to enum values instead of Strings. env.getArgument("fooStatus") returns StatusEnum values when the default is used. A regression test for list-of-enum defaults was added in 349d56a (EnumDefaultValueTest).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions