From ad07cca5e870445c007f7c28c2ede4bd4c33812e Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Wed, 24 Jan 2024 17:51:26 -0800 Subject: [PATCH 1/3] feat: pass ExecutionInput to getOrElse method --- .../graphql/apq/cache/AutomaticPersistedQueriesCache.kt | 5 +++-- .../apq/cache/DefaultAutomaticPersistedQueriesCache.kt | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt index d18c315bce..c75b0d3fb2 100644 --- a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt +++ b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt @@ -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. @@ -40,7 +40,7 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache { executionInput: ExecutionInput, onCacheMiss: PersistedQueryCacheMiss ): CompletableFuture = - getOrElse(persistedQueryId.toString()) { + getOrElse(persistedQueryId.toString(), executionInput) { onCacheMiss.apply(executionInput.query) } @@ -55,6 +55,7 @@ interface AutomaticPersistedQueriesCache : PersistedQueryCache { */ fun getOrElse( key: String, + executionInput: ExecutionInput, supplier: () -> PreparsedDocumentEntry ): CompletableFuture } diff --git a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/DefaultAutomaticPersistedQueriesCache.kt b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/DefaultAutomaticPersistedQueriesCache.kt index 78551b9f49..84ffae4d36 100644 --- a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/DefaultAutomaticPersistedQueriesCache.kt +++ b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/DefaultAutomaticPersistedQueriesCache.kt @@ -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. @@ -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 @@ -26,6 +27,7 @@ class DefaultAutomaticPersistedQueriesCache : AutomaticPersistedQueriesCache { override fun getOrElse( key: String, + executionInput: ExecutionInput, supplier: () -> PreparsedDocumentEntry ): CompletableFuture = cache[key]?.let { entry -> From 660fc55b51675bc84e768076b0c0eb356f0570f2 Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Wed, 24 Jan 2024 17:56:52 -0800 Subject: [PATCH 2/3] feat: pass ExecutionInput to getOrElse method --- .../graphql/apq/provider/AutomaticPersistedQueriesProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt index c9a693f245..6b66447eb6 100644 --- a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt +++ b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt @@ -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) } } From e04c277f201d129faff6c43676c9edce666cc559 Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Wed, 24 Jan 2024 18:11:31 -0800 Subject: [PATCH 3/3] feat: update kdocs --- .../graphql/apq/cache/AutomaticPersistedQueriesCache.kt | 1 + .../graphql/apq/provider/AutomaticPersistedQueriesProvider.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt index c75b0d3fb2..0ba92960dd 100644 --- a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt +++ b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/cache/AutomaticPersistedQueriesCache.kt @@ -51,6 +51,7 @@ 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( diff --git a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt index 6b66447eb6..ca67806bfa 100644 --- a/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt +++ b/executions/graphql-kotlin-automatic-persisted-queries/src/main/kotlin/com/expediagroup/graphql/apq/provider/AutomaticPersistedQueriesProvider.kt @@ -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.