Update section on GraphQlSource.Builder

See gh-154, gh-167
This commit is contained in:
Rossen Stoyanchev
2021-10-18 18:47:53 +01:00
parent f05fd3550a
commit 811d32b647

View File

@@ -179,6 +179,48 @@ support for <<execution-reactive-datafetcher>>, <<execution-context>>, and
[[execution-graphqlsource-schema-resources]]
==== Schema Resources
`GraphQlSource.Builder` can be configured with one or more `Resource` instances to be
parsed and merged together. That means schema files can be loaded from just about any
location. By default, the Spring Boot starter <<boot-graphql-schema,loads schema files>>
from a well-known classpath location, but you can change that to a location on the file system
via `FileSystemResource`, to byte content via `ByteArrayResource`, or implement a custom
`Resource` that loads schema files from a remote location or storage.
[[execution-graphqlsource-runtimewiring-configurer]]
==== `RuntimeWiringConfigurer`
You can add a `RuntimeWiringConfigurer` to `GraphQlSource.Builder` to register:
- custom scalar types.
- a `TypeResolver`, if you need to override the
<<execution-graphqlsource-default-type-resolver>> for a type.
- a `DataFetcher` for a field, although most applications will simply configure
`AnnotatedControllerConfigurer`, which detects annotated, `DataFetcher` handler methods.
The Spring Boot starter adds the `AnnotatedControllerConfigurer` by default.
[[execution-graphqlsource-default-type-resolver]]
==== Default `TypeResolver`
`GraphQlSource.Builder` registers `ClassNameTypeResolver` as the default `TypeResolver`
to use for GraphQL Interfaces and Unions that don't already have such a registration
through a <<execution-graphqlsource-runtimewiring-configurer>>. The purpose of
a `TypeResolver` in GraphQL Java is to determine the GraphQL Object type for values
returned from the `DataFetcher` for a GraphQL Interface or Union field.
`ClassNameTypeResolver` tries to match the simple class name of the value to a GraphQL
Object Type and if it is not successful, it also navigates its super types including
base classes and interfaces, looking for a match. `ClassNameTypeResolver` provides an
option to configure a name extracting function along with `Class` to GraphQL Object type
name mappings that should help to cover more corner cases.
[[execution-reactive-datafetcher]]
=== Reactive `DataFetcher`