Skip to content

Commit 2fb8447

Browse files
feat: pass ExecutionInput to getOrElse method (#1918) (#1919)
### 📝 Description trying to implement a distributed cache mechanism for parsed and validated operations, in the `getOrElse` method is where we would be setting the operation into an external cache, for that, we need access to the actual operation, which is included in the `ExecutionInput`. No more changes are needed given that the action of storing the parsed and validated operation is potentially async, but we don't care about the result. ### 📝 Description ### 🔗 Related Issues
1 parent ca81612 commit 2fb8447

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache {
4040
executionInput: ExecutionInput,
4141
onCacheMiss: PersistedQueryCacheMiss
4242
): CompletableFuture<PreparsedDocumentEntry> =
43-
getOrElse(persistedQueryId.toString()) {
43+
getOrElse(persistedQueryId.toString(), executionInput) {
4444
onCacheMiss.apply(executionInput.query)
4545
}
4646

@@ -51,10 +51,12 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache {
5151
* and then it should be added to the cache.
5252
*
5353
* @param key The hash of the requested query.
54+
* @param executionInput the resource that GraphQL operation.
5455
* @param supplier that will provide the document in case there is a cache miss.
5556
*/
5657
fun getOrElse(
5758
key: String,
59+
executionInput: ExecutionInput,
5860
supplier: () -> PreparsedDocumentEntry
5961
): CompletableFuture<PreparsedDocumentEntry>
6062
}

executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/DefaultAutomaticPersistedQueriesCache.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package com.expediagroup.graphql.apq.cache
1818

19+
import graphql.ExecutionInput
1920
import graphql.execution.preparsed.PreparsedDocumentEntry
2021
import java.util.concurrent.CompletableFuture
2122
import java.util.concurrent.ConcurrentHashMap
@@ -26,6 +27,7 @@ class DefaultAutomaticPersistedQueriesCache : AutomaticPersistedQueriesCache {
2627

2728
override fun getOrElse(
2829
key: String,
30+
executionInput: ExecutionInput,
2931
supplier: () -> PreparsedDocumentEntry
3032
): CompletableFuture<PreparsedDocumentEntry> =
3133
cache[key]?.let { entry ->

executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,7 +71,7 @@ class AutomaticPersistedQueriesProvider(
7171
} ?: run {
7272
// no apqExtension, not a persisted query,
7373
// but we still want to cache the parsed and validated document
74-
cache.getOrElse(executionInput.getQueryId()) {
74+
cache.getOrElse(executionInput.getQueryId(), executionInput) {
7575
parseAndValidateFunction.apply(executionInput)
7676
}
7777
}

0 commit comments

Comments
 (0)