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

spring-graphql and reactive feign #216

Open mheidt opened 6 days ago

mheidt commented 6 days ago

Hello @etienne-sf

Now that I had to switch from webmvc to webflux, I ended up shifting from open-feign to reactivefeign. I have some issues with the following code which is a kind of migrated snippet using Mono

`@Override public List customers(DataFetchingEnvironment dataFetchingEnvironment, DashboardConfig origin, Long customerTypeId, Long customerShortnameTypeId, Long customerGroupId) { SecurityContext securityContext = SecurityContextHolder.getContext(); //only needed for caching dashboardConfigService.loadCustomers(getDashboardFilter(dataFetchingEnvironment), customerTypeId, customerShortnameTypeId, customerGroupId, securityContext.toString()) .map(idNameMapper::toMM) // Transform each IdNameDTO to IdName .collectList() // Collect into a List .subscribe(origin::setCustomers); // Set the customers once the list is available

  return origin.getCustomers();

}`

But the function will return too early returning empty. calling block() won't work at runtime...some exception, that blocking is not allowed. I would rather see something, that the customers function returns a Mono.

but I override one of the generated functions. Do you have experience with that?

mheidt commented 6 days ago

But I can solve it with toFuture().get() But in case the feign service might return real Flux, we might have a problem

etienne-sf commented 5 days ago

Hum, hum, You're right : the Spring GraphQL controllers don't expect a precise return type. They actually expect an Object, and will manage these kind of return:

The current generated code force the return type to be the first line, which is not reactive at all. :(

I missed that point, when migrating to Spring GraphQL.

I'll add this change in the next version.

Etienne