Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.03k stars 286 forks source link

bug: DataFetchingEnvironment::localContext overwritten by Spring Actuator for Nested Data Fetchers #1780

Closed kevinlee2198 closed 5 months ago

kevinlee2198 commented 5 months ago

Please read our contributor guide before creating an issue.

Expected behavior

When Spring boot actuator is present, values passed to child data fetcher via localContext should be accessible following the documentation.

Actual behavior

Values are overridden to instead be a Map containing a SimpleObservation value.
Class cast exception then occurs follows:

"message": "java.lang.ClassCastException: class graphql.GraphQLContext cannot be cast to class java.util.Map (graphql.GraphQLContext is in unnamed module of loader 'app'; java.util.Map is in module java.base of loader 'bootstrap')",

Steps to reproduce

  1. Create Spring boot project with web, graphql, actuator, and dgs dependencies
  2. Create nested data fetcher like the preload example in the documentation
  3. Run a graphql query, querying for the child attribute of the parent

Minimal Reproducible Example: https://github.com/kevinlee2198/dgs-local-context-demo

Note: Remove the actuator dependency and the query works as expected

Note: A test case would be highly appreciated, but we understand that's not always possible

kilink commented 5 months ago

In your example app, you are including the dependency spring-boot-starter-graphql, which is causing this issue (see this code). If you remove that dependency, your example app works fine.

kilink commented 4 months ago

Here is the related issue in spring-graphl.

kevinlee2198 commented 3 months ago

Got it, thanks for being on top of this.