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: pass ExecutionInput to getOrElse method #1918

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2024 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,7 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache {
executionInput: ExecutionInput,
onCacheMiss: PersistedQueryCacheMiss
): CompletableFuture<PreparsedDocumentEntry> =
getOrElse(persistedQueryId.toString()) {
getOrElse(persistedQueryId.toString(), executionInput) {
onCacheMiss.apply(executionInput.query)
}

Expand All @@ -51,10 +51,12 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache {
* and then it should be added to the cache.
*
* @param key The hash of the requested query.
* @param executionInput the resource that GraphQL operation.
* @param supplier that will provide the document in case there is a cache miss.
*/
fun getOrElse(
key: String,
executionInput: ExecutionInput,
supplier: () -> PreparsedDocumentEntry
): CompletableFuture<PreparsedDocumentEntry>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2024 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package com.expediagroup.graphql.apq.cache

import graphql.ExecutionInput
import graphql.execution.preparsed.PreparsedDocumentEntry
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
Expand All @@ -26,6 +27,7 @@ class DefaultAutomaticPersistedQueriesCache : AutomaticPersistedQueriesCache {

override fun getOrElse(
key: String,
executionInput: ExecutionInput,
supplier: () -> PreparsedDocumentEntry
): CompletableFuture<PreparsedDocumentEntry> =
cache[key]?.let { entry ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2024 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,7 +71,7 @@ class AutomaticPersistedQueriesProvider(
} ?: run {
// no apqExtension, not a persisted query,
// but we still want to cache the parsed and validated document
cache.getOrElse(executionInput.getQueryId()) {
cache.getOrElse(executionInput.getQueryId(), executionInput) {
parseAndValidateFunction.apply(executionInput)
}
}
Expand Down
Loading