Skip to content

Commit 25b5071

Browse files
Copilotdondonz
andcommitted
Update to GraphQL Java version 25.0
Co-authored-by: dondonz <13839920+dondonz@users.noreply.github.com>
1 parent 067ab5d commit 25b5071

23 files changed

Lines changed: 189 additions & 9 deletions

documentation/getting-started.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repositories {
2525
}
2626
2727
dependencies {
28-
implementation 'com.graphql-java:graphql-java:24.3'
28+
implementation 'com.graphql-java:graphql-java:25.0'
2929
}
3030
```
3131
</TabItem>
@@ -38,7 +38,7 @@ repositories {
3838
}
3939

4040
dependencies {
41-
implementation("com.graphql-java:graphql-java:24.3")
41+
implementation("com.graphql-java:graphql-java:25.0")
4242
}
4343
```
4444
</TabItem>
@@ -51,7 +51,7 @@ Dependency:
5151
<dependency>
5252
<groupId>com.graphql-java</groupId>
5353
<artifactId>graphql-java</artifactId>
54-
<version>24.3</version>
54+
<version>25.0</version>
5555
</dependency>
5656
```
5757

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config = {
2525
routeBasePath: 'documentation',
2626
sidebarPath: require.resolve('./sidebars.js'),
2727
editUrl: 'https://github.com/graphql-java/graphql-java-page/edit/master/',
28-
lastVersion: "v24",
28+
lastVersion: "v25",
2929
versions: {
3030
current: {
3131
label: "master",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,67 @@ DataFetcher<?> dataFetcherThatCallsTheDataLoader = new DataFetcher<Object>() {
370370
}
371371
};
372372
```
373+
374+
## Chained DataLoaders
375+
376+
The automatic dispatching of Chained DataLoaders is a new feature included in GraphQL Java 25.0 onwards. Before this version, DataLoaders in chains needed to be manually dispatched.
377+
378+
A Chained DataLoader is where one DataLoader depends on another, within the same DataFetcher.
379+
380+
For example in code:
381+
```java
382+
DataFetcher<CompletableFuture<Object>> df1 = env -> {
383+
return env.getDataLoader("name").load("Key1").thenCompose(result -> {
384+
return env.getDataLoader("email").load(result);
385+
});
386+
};
387+
```
388+
389+
### How do I enable Chained DataLoaders?
390+
You must opt-in to Chained DataLoaders via `GraphQLUnusualConfiguration.DataloaderConfig`, as this may change order of dispatching.
391+
392+
Set `enableDataLoaderChaining(true)` to enable Chained DataLoaders.
393+
394+
For example, to set `enableDataLoaderChaining`:
395+
```java
396+
GraphQL graphQL = GraphQL.unusualConfiguration(graphqlContext)
397+
.dataloaderConfig()
398+
.enableDataLoaderChaining(true);
399+
```
400+
401+
### What changed in GraphQL Java 25.0?
402+
The DataFetcher in the example above, before version 25.0 would have caused execution to hang, because the second DataLoader ("email") was never dispatched.
403+
404+
Prior to version 25.0, users of GraphQL Java needed to manually dispatch DataLoaders to ensure execution completed. From version 25.0, the GraphQL Java engine will automatically dispatch Chained DataLoaders.
405+
406+
If you're looking for more examples, and the technical details, please see [our tests](https://github.com/graphql-java/graphql-java/blob/master/src/test/groovy/graphql/ChainedDataLoaderTest.groovy).
407+
408+
Note: The GraphQL Java engine can only optimally calculate DataLoader dispatches on a per-level basis. It does not calculate optimal DataLoader dispatching across different levels of an operation's field tree.
409+
410+
### A special case: Delayed DataLoaders
411+
412+
In a previous code snippet, we demonstrated one DataLoader depending on another DataLoader.
413+
414+
Another special case is a "delayed" DataLoader, where a DataLoader depends on a slow async task instead. For example, here are two DataFetchers from [a test example](https://github.com/graphql-java/graphql-java/blob/master/src/test/groovy/graphql/ChainedDataLoaderTest.groovy):
415+
416+
```groovy
417+
def fooDF = { env ->
418+
return supplyAsync {
419+
Thread.sleep(1000)
420+
return "fooFirstValue"
421+
}.thenCompose {
422+
return env.getDataLoader("dl").load(it)
423+
}
424+
} as DataFetcher
425+
426+
def barDF = { env ->
427+
return supplyAsync {
428+
Thread.sleep(1000)
429+
return "barFirstValue"
430+
}.thenCompose {
431+
return env.getDataLoader("dl").load(it)
432+
}
433+
} as DataFetcher
434+
```
435+
436+
By opting in to Chained DataLoaders, GraphQL Java will also calculate when to dispatch "delayed" DataLoaders. These "delayed" DataLoaders will be enqueued for dispatch after the async task completes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)