|
1 |
| ---- |
2 |
| -id: spring |
3 |
| -title: Spring |
4 |
| ---- |
5 |
| -[graphql-kotlin-spring-server](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/graphql-kotlin-spring-server) |
6 |
| -is a Spring Boot auto-configuration library that automatically configures beans required to start up reactive GraphQL |
7 |
| -web server. |
8 |
| - |
9 |
| -At a minimum, in order for `graphql-kotlin-spring-server` to automatically configure your GraphQL web server you need to |
10 |
| -specify list of supported packages that can be scanned for exposing your schema objects through reflections. |
11 |
| - |
12 |
| -You can do this through the spring application config or by overriding the `SchemaGeneratorConfig` bean. See customization below. |
13 |
| - |
14 |
| -```yaml |
15 |
| -graphql: |
16 |
| - packages: |
17 |
| - - "com.your.package" |
18 |
| -``` |
19 |
| -
|
20 |
| -
|
21 |
| -In order to expose your queries, mutations and/or subscriptions in the GraphQL schema you simply need to implement |
22 |
| -corresponding marker interface and they will be automatically picked up by `graphql-kotlin-spring-server` |
23 |
| -auto-configuration library. |
24 |
| - |
25 |
| -```kotlin |
26 |
| -class MyAwesomeQuery : Query { |
27 |
| - fun myAwesomeQuery(): Widget { ... } |
28 |
| -} |
29 |
| -
|
30 |
| -class MyAwesomeMutation : Mutation { |
31 |
| - fun myAwesomeMutation(widget: Widget): Widget { ... } |
32 |
| -} |
33 |
| -
|
34 |
| -data class Widget(val id: Int, val value: String) |
35 |
| -``` |
36 |
| - |
37 |
| -will result in a Spring Boot reactive GraphQL web application with following schema. |
38 |
| - |
39 |
| -```graphql |
40 |
| -schema { |
41 |
| - query: Query |
42 |
| - mutation: Mutation |
43 |
| -} |
44 |
| -
|
45 |
| -type Query { |
46 |
| - myAwesomeQuery(): Widget! |
47 |
| -} |
48 |
| -
|
49 |
| -type Mutation { |
50 |
| - myAwesomeMutation(widget: Widget!): Widget! |
51 |
| -} |
52 |
| -
|
53 |
| -type Widget { |
54 |
| - id: Int! |
55 |
| - value: String! |
56 |
| -} |
57 |
| -``` |
58 |
| - |
59 |
| -## Customization |
60 |
| - |
61 |
| -All beans created by `graphql-kotlin-spring-server` are conditionally created. If any of the target beans are created in |
62 |
| -the application context, auto-configuration will back off. |
63 |
| - |
64 |
| -Conditionally generated beans: |
65 |
| - |
66 |
| -* **SchemaGeneratorConfig** - schema generation configuration information, see |
67 |
| - [Spring Configuration](spring-config) for details. _You should |
68 |
| - register custom configuration bean if you want to specify custom schema generator hooks._ |
69 |
| -* **FederatedTypeRegistry** - default type registry without any resolvers, created only if generating federated GraphQL |
70 |
| - schema. _You should register your custom type registry bean whenever implementing federated GraphQL schema with |
71 |
| - extended types_. |
72 |
| -* **GraphQLSchema** - GraphQL schema generated based on the schema generator configuration and `Query`, `Mutation` and |
73 |
| - `Subscription` objects available in the application context |
74 |
| -* **DataFetcherExceptionHandler** - GraphQL exception handler used from the various execution strategies, defaults to |
75 |
| - [KotlinDataFetcherExceptionHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/exception/KotlinDataFetcherExceptionHandler.kt) |
76 |
| - |
77 |
| -* **GraphQL** - `graphql-java` GraphQL query execution engine generated using `GraphQLSchema` with default async |
78 |
| - execution strategies. GraphQL engine can be customized by optionally providing |
79 |
| - [Instrumentation](https://www.graphql-java.com/documentation/v13/instrumentation/), |
80 |
| - [ExecutionIdProvider](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/ExecutionIdProvider.java) |
81 |
| - and |
82 |
| - [PreparsedDocumentProvider](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/preparsed/PreparsedDocumentProvider.java) |
83 |
| - in the application context. |
84 |
| -* **QueryHandler** - handler invoked from GraphQL query route that executes the incoming request, defaults to |
85 |
| - [SimpleQueryHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/QueryHandler.kt) |
86 |
| -* **GraphQLContextFactory** - factory used by context WebFilter to generate GraphQL context based on the incoming |
87 |
| - request. GraphQL context can be any object. Defaults to empty |
88 |
| - [GraphQLContext](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/GraphQLContext.java) |
89 |
| -* **SubscriptionHandler** - Web socket handler for executing GraphQL subscriptions, defaults to |
90 |
| - [SimpleSubscriptionHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/SubscriptionHandler.kt#L49), |
91 |
| - created only if `Subscription` bean is available in the context |
92 |
| -* **WebSocketHandlerAdapter** - [see Spring |
93 |
| - documentation](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.html), |
94 |
| - created only if `Subscription` bean is available in the context |
95 |
| - |
96 |
| -The following beans are currently automatically created and cannot be disabled: |
97 |
| - |
98 |
| -* Web filter for generating and populating GraphQL context |
99 |
| -* Default routes for GraphQL queries/mutations and SDL endpoint |
100 |
| -* Default subscription handler mapping, created only if `Subscription` bean is available in the context |
| 1 | +--- |
| 2 | +id: spring-beans |
| 3 | +title: Automatically Created Beans |
| 4 | +--- |
| 5 | + |
| 6 | +All beans created by `graphql-kotlin-spring-server` are conditionally created. If any of the target beans are created in |
| 7 | +the application context, auto-configuration will back off. |
| 8 | + |
| 9 | +Conditionally generated beans: |
| 10 | + |
| 11 | +* **SchemaGeneratorConfig/FederatedSchemaGeneratorConfig** - schema generation configuration information, see |
| 12 | + [Spring Configuration](spring-config) for details. _You should |
| 13 | + register custom configuration bean if you want to specify custom schema generator hooks._ |
| 14 | +* **FederatedTypeRegistry** - default type registry without any resolvers, created only if generating federated GraphQL |
| 15 | + schema. _You should register your custom type registry bean whenever implementing federated GraphQL schema with |
| 16 | + extended types_. |
| 17 | +* **GraphQLSchema** - GraphQL schema generated based on the schema generator configuration and `Query`, `Mutation` and |
| 18 | + `Subscription` objects available in the application context |
| 19 | +* **DataFetcherExceptionHandler** - GraphQL exception handler used from the various execution strategies, defaults to |
| 20 | + [KotlinDataFetcherExceptionHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/exception/KotlinDataFetcherExceptionHandler.kt) |
| 21 | +* **GraphQL** - `graphql-java` GraphQL query execution engine generated using `GraphQLSchema` with default async |
| 22 | + execution strategies. GraphQL engine can be customized by optionally providing a list of |
| 23 | + [Instrumentation](https://www.graphql-java.com/documentation/v13/instrumentation/) beans (which can be ordered by implementing Spring |
| 24 | + Ordered interface), [ExecutionIdProvider](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/ExecutionIdProvider.java) |
| 25 | + and |
| 26 | + [PreparsedDocumentProvider](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/preparsed/PreparsedDocumentProvider.java) |
| 27 | + in the application context. |
| 28 | +* **DataLoaderRegistryFactory** - factory used to create DataLoaderRegistry instance per query execution. See [graphql-java documentation](https://www.graphql-java.com/documentation/v13/batching/) |
| 29 | + for more details |
| 30 | +* **QueryHandler** - handler invoked from GraphQL query route that executes the incoming request, defaults to |
| 31 | + [SimpleQueryHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/QueryHandler.kt) |
| 32 | +* **GraphQLContextFactory** - factory used by context WebFilter to generate GraphQL context based on the incoming |
| 33 | + request. GraphQL context can be any object. Defaults to empty |
| 34 | + [GraphQLContext](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/GraphQLContext.java) |
| 35 | +* **SubscriptionHandler** - Web socket handler for executing GraphQL subscriptions, defaults to |
| 36 | + [SimpleSubscriptionHandler](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/SubscriptionHandler.kt#L49), |
| 37 | + created only if `Subscription` bean is available in the context |
| 38 | +* **WebSocketHandlerAdapter** - [see Spring |
| 39 | + documentation](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/socket/server/support/WebSocketHandlerAdapter.html), |
| 40 | + created only if `Subscription` bean is available in the context |
| 41 | + |
| 42 | +The following beans are currently automatically created and cannot be disabled: |
| 43 | + |
| 44 | +* Web filter for generating and populating GraphQL context |
| 45 | +* Default routes for GraphQL queries/mutations and SDL endpoint |
| 46 | +* Default route for Prisma Labs Playground, created only if playground is enabled |
| 47 | +* Default `ApolloSubscriptionProtocolHandler` for handling GraphQL subscriptions, created only if `Subscription` bean is available in the context |
| 48 | +* Default `SubscriptionWebSocketHandler` that utilizes above subscription protocol handler, created only if `Subscription` bean is available in the context |
| 49 | +* Default subscription handler mapping, created only if `Subscription` bean is available in the context |
0 commit comments