Each field exposed through a GraphQL query has a corresponding resolver (aka data fetcher) associated with it.
graphql-kotlin-schema-generator generates GraphQL schema
directly from the source code automatically mapping all the fields either to use
to resolve underlying functions or a PropertyDataFetcher to read a value from an underlying Kotlin property.
While all the fields in a GraphQL query are resolved independently to produce a final result, whether field is backed by a function or a property can have significant performance repercussions. For example, given the following schema:
We can define
If we expose the
reviews field as a property it will always be populated regardless whether or not your client actually asks for it. On the other hand if
reviews is backed
by a function, it will only be called if your client asks for this data. In order to minimize the over-fetching of data from your underlying data sources we recommend to
expose all your GraphQL fields that require some additional computations through functions.
You can provide your own custom data fetchers to resolve functions and properties by providing an instance of
to your SchemaGeneratorConfig.
See our spring example app for an example of