springspring-bootgraphqlgraphql-javaspring-graphql

Default strategy for discovering data fetchers in spring for graphql?


After reading the docs for Spring for GraphQL, I understand how to annotate methods and controllers to expose data fetchers for items in my schema. My question is.. do I need to do that for every field in my schema? An example: Say I have a type like this: type Client { id: ID!, name: String!, user: User! }

Client is fetched from the database from another DataFetcher, and makes it to the ClientController. Id and Name are already fetched as part of the ClientDTO. Do I need to define a DataFetcher for those in the stock stuff provided from Spring?

For a little context: we are migrating from GraphQL Kickstarter which did recognition by Resolver or by the DataClass supplied as part of the resolver.


Solution

  • No, you don't have to register data fetchers for all existing fields, this would be really tedious. GraphQL Java automatically detects properties/getters and sets up PropertyDataFetcher for that.

    When creating your GraphQL application, you can look at the schema inspection report during startup: this will point to the parts of your schema that are not yet covered by a data fetcher.