spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.53k stars 306 forks source link

Service becomes null when using private @SchemaMapping #1084

Open sydneyhenrard opened 2 weeks ago

sydneyhenrard commented 2 weeks ago

I faced a strange behavior. It might not be a bug, or it's something specific to my application but I figured it could help.

The query has 2 @SchemaMapping one is public and the other is private. No reason just inconsistency on my side. When running the query locally it works fine, but when deployed in dev, the facets part throws a NPE because productService is null. When switching the method from private to public it works.

JDK 21 SB 3.3.4

@Controller
public class ProductGraphQlController {

    private final ProductService productService;

    public ProductGraphQlController(ProductService productService) {
        this.productService = productService;
    }

    @QueryMapping
    public ProductSearch allProductsWithFacets(
        @Argument String tenant,
        ScrollSubrange subrange,
        GraphQLContext graphQLContext
    ) {...}   

    @SchemaMapping(field = "content")
    public Window<Product> content(
        ProductSearch productSearch,
        @ContextValue String tenant,
        @ContextValue ScrollSubrange subrange
    ) {...}   

    @SchemaMapping(field = "facets")
    private List<Facet> facets(
        ProductSearch productSearch,
        @ContextValue String tenant
    ) {...}   
}
bclozel commented 2 weeks ago

I think there is more to this as the behavior you're describing doesn't make sense to me. Can you share a minimal sample application that we can take a look at?

spring-projects-issues commented 1 week ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 3 hours ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.