From f46c2178c0b89a1842ff40525272e7e521e28074 Mon Sep 17 00:00:00 2001 From: banjjoknim Date: Tue, 2 Aug 2022 14:47:31 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20GraphQL=20Context=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graphql-kotlin/README.md | 3 ++ .../banjjoknim/graphqlkotlin/GraphQLContextFactory.kt | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 놀이터(예제 코드 작성)/graphql-kotlin/src/main/kotlin/com/banjjoknim/graphqlkotlin/GraphQLContextFactory.kt diff --git a/놀이터(예제 코드 작성)/graphql-kotlin/README.md b/놀이터(예제 코드 작성)/graphql-kotlin/README.md index 9fb20a7..7b23f91 100644 --- a/놀이터(예제 코드 작성)/graphql-kotlin/README.md +++ b/놀이터(예제 코드 작성)/graphql-kotlin/README.md @@ -9,3 +9,6 @@ - [Configuration Properties](https://opensource.expediagroup.com/graphql-kotlin/docs/server/spring-server/spring-properties) - [Subscriptions](https://opensource.expediagroup.com/graphql-kotlin/docs/server/spring-server/spring-subscriptions) - [MVN Repository - GraphQL Kotlin Spring Server](https://mvnrepository.com/artifact/com.expediagroup/graphql-kotlin-spring-server) +- [Contextual Data](https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/execution/contextual-data/) +- [Federation Tracing](https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/federation/federation-tracing/) +- [Configuration Properties](https://opensource.expediagroup.com/graphql-kotlin/docs/server/spring-server/spring-properties/) diff --git a/놀이터(예제 코드 작성)/graphql-kotlin/src/main/kotlin/com/banjjoknim/graphqlkotlin/GraphQLContextFactory.kt b/놀이터(예제 코드 작성)/graphql-kotlin/src/main/kotlin/com/banjjoknim/graphqlkotlin/GraphQLContextFactory.kt new file mode 100644 index 0000000..cce6a40 --- /dev/null +++ b/놀이터(예제 코드 작성)/graphql-kotlin/src/main/kotlin/com/banjjoknim/graphqlkotlin/GraphQLContextFactory.kt @@ -0,0 +1,29 @@ +package com.banjjoknim.graphqlkotlin + +import com.expediagroup.graphql.server.spring.execution.DefaultSpringGraphQLContextFactory +import org.springframework.stereotype.Component +import org.springframework.web.reactive.function.server.ServerRequest + +/** + * # [Generating GraphQL Context](https://opensource.expediagroup.com/graphql-kotlin/docs/server/spring-server/spring-graphql-context) + * + * graphql-kotlin-spring-server provides a Spring specific implementation of GraphQLContextFactory and the context. + * + * SpringGraphQLContext (deprecated) - Implements the Spring ServerRequest and federation tracing HTTPRequestHeaders + * + * SpringGraphQLContextFactory - Generates GraphQL context map with federated tracing information per request + * + * If you are using graphql-kotlin-spring-server, you should extend DefaultSpringGraphQLContextFactory to automatically support federated tracing. + * + * Once your application is configured to build your custom GraphQL context map, you can then access it through a data fetching environment argument. + * + * While executing the query, data fetching environment will be automatically injected to the function input arguments. + * + * This argument will not appear in the GraphQL schema. + */ +@Component +class GraphQLContextFactory : DefaultSpringGraphQLContextFactory() { + override suspend fun generateContextMap(request: ServerRequest): Map<*, Any> = super.generateContextMap(request) + mapOf( + "myCustomValue" to (request.headers().firstHeader("MyHeader") ?: "defaultContext") + ) +}