From b2b1e2d506aba402fb07bf7d3b149f439c7f729e Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 17 Mar 2022 17:23:38 +0100 Subject: [PATCH] Document custom className extractor config This commit documents how to configure a custom className Extractor strategy in the `ClassNameTypeResolver`. This also adds an example of a `GraphQlSourceBuilderCustomizer` in Spring Boot. Closes gh-334 --- .../src/docs/asciidoc/index.adoc | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index 2c57026e..22928d1d 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -201,9 +201,25 @@ the following: - Detect <> beans. - Detect https://www.graphql-java.com/documentation/instrumentation[Instrumentation] beans for {spring-boot-ref-docs}/actuator.html#actuator.metrics.supported.spring-graphql[GraphQL metrics]. -- Detect `DataFetcherExceptionResolver` beans for - <>. -- Detect `GraphQlSourceBuilderCustomizer` beans for any other customizations. +- Detect `DataFetcherExceptionResolver` beans for <>. + +For further customizations, you can declare your own `GraphQlSourceBuilderCustomizer` beans; +for example, for configuring your own `ExecutionIdProvider`: + +[source,java,indent=0,subs="verbatim,quotes"] +---- +@Configuration(proxyBeanMethods = false) +class GraphQlConfig { + + @Bean + public GraphQlSourceBuilderCustomizer sourceBuilderCustomizer() { + return (builder) -> { + builder.configureGraphQl(graphQlBuilder -> + graphQlBuilder.executionIdProvider(new CustomExecutionIdProvider())); + }; + } +} +---- @@ -230,18 +246,18 @@ necessary, you can hook into the schema creation through the builder: [source,java,indent=0,subs="verbatim,quotes"] ---- -// Typically, accessed through Spring Boot's GraphQlSourceBuilderCustomizer GraphQlSource.Builder builder = ... builder.schemaResources(..) .configureRuntimeWiring(..) .schemaFactory((typeDefinitionRegistry, runtimeWiring) -> { - // create `GraphQLSchema` + // create GraphQLSchema }) ---- The primary reason for this is to create the schema through a federation library. +The <> explains how to configure that with Spring Boot. [[execution-graphqlsource-runtimewiring-configurer]] ==== `RuntimeWiringConfigurer` @@ -302,8 +318,19 @@ returned from the `DataFetcher` for a GraphQL Interface or Union field. 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. +name mappings that should help to cover more corner cases: +[source,java,indent=0,subs="verbatim,quotes"] +---- +GraphQlSource.Builder builder = ... +ClassNameTypeResolver classNameTypeResolver = new ClassNameTypeResolver(); +classNameTypeResolver.setClassNameExtractor((klass) -> { + // Implement Custom ClassName Extractor here +}); +builder.defaultTypeResolver(classNameTypeResolver); +---- + +The <> explains how to configure that with Spring Boot. [[execution-graphqlsource-operation-caching]] ==== Operation Caching @@ -331,6 +358,7 @@ builder.schemaResources(..) .configureGraphQl(graphQLBuilder -> graphQLBuilder.preparsedDocumentProvider(provider)) ---- +The <> explains how to configure that with Spring Boot. [[execution-graphqlsource-directives]] ==== Directives