Skip to content

Commit b2b1e2d

Browse files
committed
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
1 parent 9102bdb commit b2b1e2d

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

spring-graphql-docs/src/docs/asciidoc/index.adoc

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,25 @@ the following:
201201
- Detect <<execution-graphqlsource-runtimewiring-configurer>> beans.
202202
- Detect https://www.graphql-java.com/documentation/instrumentation[Instrumentation] beans for
203203
{spring-boot-ref-docs}/actuator.html#actuator.metrics.supported.spring-graphql[GraphQL metrics].
204-
- Detect `DataFetcherExceptionResolver` beans for
205-
<<execution-exceptions, exception resolution>>.
206-
- Detect `GraphQlSourceBuilderCustomizer` beans for any other customizations.
204+
- Detect `DataFetcherExceptionResolver` beans for <<execution-exceptions, exception resolution>>.
205+
206+
For further customizations, you can declare your own `GraphQlSourceBuilderCustomizer` beans;
207+
for example, for configuring your own `ExecutionIdProvider`:
208+
209+
[source,java,indent=0,subs="verbatim,quotes"]
210+
----
211+
@Configuration(proxyBeanMethods = false)
212+
class GraphQlConfig {
213+
214+
@Bean
215+
public GraphQlSourceBuilderCustomizer sourceBuilderCustomizer() {
216+
return (builder) -> {
217+
builder.configureGraphQl(graphQlBuilder ->
218+
graphQlBuilder.executionIdProvider(new CustomExecutionIdProvider()));
219+
};
220+
}
221+
}
222+
----
207223

208224

209225

@@ -230,18 +246,18 @@ necessary, you can hook into the schema creation through the builder:
230246

231247
[source,java,indent=0,subs="verbatim,quotes"]
232248
----
233-
// Typically, accessed through Spring Boot's GraphQlSourceBuilderCustomizer
234249
GraphQlSource.Builder builder = ...
235250
236251
builder.schemaResources(..)
237252
.configureRuntimeWiring(..)
238253
.schemaFactory((typeDefinitionRegistry, runtimeWiring) -> {
239-
// create `GraphQLSchema`
254+
// create GraphQLSchema
240255
})
241256
----
242257

243258
The primary reason for this is to create the schema through a federation library.
244259

260+
The <<execution-graphqlsource, GraphQlSource section>> explains how to configure that with Spring Boot.
245261

246262
[[execution-graphqlsource-runtimewiring-configurer]]
247263
==== `RuntimeWiringConfigurer`
@@ -302,8 +318,19 @@ returned from the `DataFetcher` for a GraphQL Interface or Union field.
302318
Object Type and if it is not successful, it also navigates its super types including
303319
base classes and interfaces, looking for a match. `ClassNameTypeResolver` provides an
304320
option to configure a name extracting function along with `Class` to GraphQL Object type
305-
name mappings that should help to cover more corner cases.
321+
name mappings that should help to cover more corner cases:
322+
323+
[source,java,indent=0,subs="verbatim,quotes"]
324+
----
325+
GraphQlSource.Builder builder = ...
326+
ClassNameTypeResolver classNameTypeResolver = new ClassNameTypeResolver();
327+
classNameTypeResolver.setClassNameExtractor((klass) -> {
328+
// Implement Custom ClassName Extractor here
329+
});
330+
builder.defaultTypeResolver(classNameTypeResolver);
331+
----
306332

333+
The <<execution-graphqlsource, GraphQlSource section>> explains how to configure that with Spring Boot.
307334

308335
[[execution-graphqlsource-operation-caching]]
309336
==== Operation Caching
@@ -331,6 +358,7 @@ builder.schemaResources(..)
331358
.configureGraphQl(graphQLBuilder -> graphQLBuilder.preparsedDocumentProvider(provider))
332359
----
333360

361+
The <<execution-graphqlsource, GraphQlSource section>> explains how to configure that with Spring Boot.
334362

335363
[[execution-graphqlsource-directives]]
336364
==== Directives

0 commit comments

Comments
 (0)