Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return different value for GraphQL enum in GraphQL-java

I am having following enum in the application.

public enum State {
    Started("newly started"),
    Hold("hold on"),
    Running("still running"),
    Stop("just stopped");

    private String value;

    State(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

I have GraphQL schema as well for the same. I am using GraphQL-java library not GraphQL-spqr or GraphQL-java-tools. When I am returning this enum, it's name is being returned but I want to return it's assigned value i.e. "still running" for Running enum, "just stopped" for Stop enum etc. Is there any way in GraphQL-java?

Thanks in advance

like image 775
rishi Avatar asked Dec 05 '25 05:12

rishi


1 Answers

it's name is being returned but I want to return it's assigned value

This is by design. From the spec:

Enums are not references for a numeric value, but are unique values in their own right. They may serialize as a string: the name of the represented value.

Enum values are serialized as their names. You may be able to provide an additional value that can be used internally during execution, but this value will not be used in the response.

like image 67
Daniel Rearden Avatar answered Dec 07 '25 19:12

Daniel Rearden