Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: batchLoaderContext to access to dataFetchingEnvironment #1490

Conversation

samuelAndalon
Copy link
Contributor

@samuelAndalon samuelAndalon commented Jul 27, 2022

📝 Description

extension function to allow BatchLoaderContext to access to a GraphQL Execution DataFetchingEnvironment,
specially useful if in your dataLoader you need to access to the DataFetchingEnvironment or the GraphQLContext inside of it to run batch logic, example: auth context, coroutines scope, etc.

DataLoaderFactory.newDataLoader { requests, environment: BatchLoaderEnvironment ->
  val coroutineScope = environment.getGraphQLContext()?.get<CoroutineScope>()
   coroutineScope.async {
     // your batch logic for fetching data
   }.asCompletableFuture()
 }

@dariuszkuc dariuszkuc merged commit 26ec987 into ExpediaGroup:master Jul 27, 2022
@samuelAndalon samuelAndalon deleted the feat/batch-loader-env-datafetching-env branch July 27, 2022 22:07
@dariuszkuc dariuszkuc added the changes: minor Changes require a minor version label Aug 2, 2022
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…aGroup#1490)

### 📝 Description
extension function to allow BatchLoaderContext to access to a GraphQL Execution DataFetchingEnvironment,
specially useful if in your dataLoader you need to access to the DataFetchingEnvironment or the GraphQLContext inside of it to run batch logic, example: auth context, coroutines scope, etc.

```kotlin
DataLoaderFactory.newDataLoader { requests, environment: BatchLoaderEnvironment ->
  val coroutineScope = environment.getGraphQLContext()?.get<CoroutineScope>()
   coroutineScope.async {
     // your batch logic for fetching data
   }.asCompletableFuture()
 }
```

Co-authored-by: samvazquez <samvazquez@expedia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: minor Changes require a minor version
Development

Successfully merging this pull request may close these issues.

2 participants