feat : GraphQL Context 추가

This commit is contained in:
banjjoknim
2022-08-02 14:47:31 +09:00
parent 5bb45cc2e6
commit f46c2178c0
2 changed files with 32 additions and 0 deletions

View File

@@ -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/)

View File

@@ -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")
)
}