graphql-java-generator / graphql-maven-plugin-project

graphql-maven-plugin is a Maven Plugin for GraphQL, based on graphql-java. It accelerates the development for both the client and the server, by generating the Java code. It allows a quicker development when in contract-first approach, by avoiding to code the boilerplate code.
https://graphql-maven-plugin-project.graphql-java-generator.com
MIT License
115 stars 47 forks source link

Error with subscriptions returning enums #209

Closed amalfatti closed 3 months ago

amalfatti commented 5 months ago

Hi, it seems that there is something not working when you define a Subscription returning an enum.

This is my Subscription:

featureStatus(feature: Feature): FeatureStatus!

where

enum FeatureStatus {
    HIDDEN
    ERROR
    ALERT
    SUCCESSFULL
    WARNING
    PENDING
    UPDATE_AVAILABLE
}

The generated controller:

public Object featureStatus(DataFetchingEnvironment dataFetchingEnvironment, 
    @Argument("feature") String feature) {
    return graphqlServerUtils.enumValueToString( this.dataFetchersDelegateSubscription.featureStatus(dataFetchingEnvironment , (com.telenia.system.webapi.graphql.generated.Feature)GraphqlUtils.graphqlUtils.stringToEnumValue(feature, com.telenia.system.webapi.graphql.generated.Feature.class)));
}

The method enumValueToString try to convert the enum to string searching for the graphQlValue method on a Publisher<T> object (which is the result of this.dataFetchersDelegateSubscription.featureStatus(...)) and I get the error message "The given value may be either null, an Optional, a List or an enum that has the 'graphQlValue' method'.

Am I missing something?

P.S. I'm using version 2.4 of the plugin to generate a server.

Thank you

etienne-sf commented 3 months ago

Grrr ... I missed some email notification from time to time. Sorry for the response delay.

I have integration tests the checks subscription that returns enum and [enum]. Both are Ok.

In the enumValueToString method, there is this case that makes the integration tests work:

        } else if (enumValue instanceof Flux) {
            // For a flux, we must transform each returned item
            return ((Flux<?>) enumValue).map(v -> enumValueToString(v));

And the server implementation used in the integration tests actually returns Flux. So everything is ok.

But I guess your server implementation doesn't return a Flux. Is that correct ?

If yes, then I just commited the correction (with an updated integration test to check that, and actually repeat this issue)

Etienne

amalfatti commented 3 months ago

Yes you are right, my implementation actually returns a Publisher and not a Flux. I'll wait for the next release then to try your fix, thanks!

Alex

etienne-sf commented 3 months ago

Solved in the 2.5 release