Skip to content

Commit 4e8472c

Browse files
authored
Merge branch 'master' into fix/graphqlcontext
2 parents 00f4e67 + 0317b08 commit 4e8472c

File tree

16 files changed

+440
-31
lines changed

16 files changed

+440
-31
lines changed

build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ plugins {
3636
id("me.champeau.jmh") version "0.7.2"
3737

3838
kotlin("jvm") version Versions.KOTLIN_VERSION
39-
kotlin("kapt") version Versions.KOTLIN_VERSION
4039
idea
4140
eclipse
4241
}
@@ -88,10 +87,6 @@ configure(subprojects.filterNot { it in internalBomModules }) {
8887
dependencies {
8988
// Apply the BOM to applicable subprojects.
9089
api(platform(project(":graphql-dgs-platform")))
91-
// Speed up processing of AutoConfig's produced by Spring Boot
92-
annotationProcessor("org.springframework.boot:spring-boot-autoconfigure-processor")
93-
// Produce Config Metadata for properties used in Spring Boot
94-
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
9590

9691
// Sets the JMH version to use across modules.
9792
// Please refer to the following links for further reference.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
3+
distributionSha256Sum=8d97a97984f6cbd2b85fe4c60a743440a347544bf18818048e611f5288d46c94
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME

graphql-dgs-extended-scalars/src/main/resources/META-INF/additional-spring-configuration-metadata.json renamed to graphql-dgs-extended-scalars/src/main/resources/META-INF/spring-configuration-metadata.json

File renamed without changes.

graphql-dgs-extended-validation/src/main/resources/META-INF/additional-spring-configuration-metadata.json renamed to graphql-dgs-extended-validation/src/main/resources/META-INF/spring-configuration-metadata.json

File renamed without changes.

graphql-dgs-spring-boot-micrometer/src/main/kotlin/com/netflix/graphql/dgs/metrics/micrometer/DgsGraphQLMicrometerAutoConfiguration.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
2121
import org.springframework.cache.CacheManager
2222
import org.springframework.context.annotation.Bean
2323
import org.springframework.context.annotation.Configuration
24+
import org.springframework.core.Ordered
25+
import org.springframework.core.annotation.Order
2426
import java.util.Optional
2527

2628
/**
@@ -38,6 +40,7 @@ open class DgsGraphQLMicrometerAutoConfiguration {
3840
}
3941

4042
@Bean
43+
@Order(Ordered.LOWEST_PRECEDENCE)
4144
@ConditionalOnProperty(
4245
prefix = "$AUTO_CONF_PREFIX.instrumentation",
4346
name = ["enabled"],

graphql-dgs-spring-boot-micrometer/src/main/resources/META-INF/additional-spring-configuration-metadata.json renamed to graphql-dgs-spring-boot-micrometer/src/main/resources/META-INF/spring-configuration-metadata.json

File renamed without changes.

graphql-dgs-spring-boot-micrometer/src/test/kotlin/com/netflix/graphql/dgs/metrics/micrometer/MicrometerServletSmokeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class MicrometerServletSmokeTest {
387387
.and("gql.operation.name", "anonymous")
388388
.and("gql.query.complexity", "none")
389389
.and("gql.query.sig.hash", "none")
390-
.and("gql.errorDetail", "none")
390+
.and("gql.errorDetail", "INVALID_ARGUMENT")
391391
.and("gql.errorCode", "BAD_REQUEST")
392392
.and("gql.path", "[hello]")
393393
.and("outcome", "failure"),

graphql-dgs-spring-graphql-example-java/src/main/resources/application.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ management:
2020
exposure:
2121
include:
2222
- metrics
23-
debug: true
23+
debug: true
24+
dgs:
25+
graphql:
26+
apq:
27+
enabled: true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.netflix.graphql.dgs.apq
18+
19+
import graphql.ExecutionInput
20+
import graphql.execution.preparsed.PreparsedDocumentEntry
21+
import graphql.execution.preparsed.PreparsedDocumentProvider
22+
import graphql.execution.preparsed.persisted.ApolloPersistedQuerySupport
23+
import graphql.execution.preparsed.persisted.PersistedQueryCache
24+
import java.util.*
25+
import java.util.concurrent.CompletableFuture
26+
import java.util.function.Function
27+
28+
class DgsAPQPreParsedDocumentProviderWrapper(
29+
persistedQueryCache: PersistedQueryCache,
30+
private val preparsedDocumentProvider: Optional<PreparsedDocumentProvider>,
31+
) : ApolloPersistedQuerySupport(persistedQueryCache) {
32+
override fun getDocumentAsync(
33+
executionInput: ExecutionInput,
34+
parseAndValidateFunction: Function<ExecutionInput, PreparsedDocumentEntry>,
35+
): CompletableFuture<PreparsedDocumentEntry> {
36+
val queryId = getPersistedQueryId(executionInput)
37+
if (queryId.isPresent) {
38+
return super.getDocumentAsync(executionInput, parseAndValidateFunction)
39+
}
40+
41+
if (preparsedDocumentProvider.isPresent) {
42+
return preparsedDocumentProvider.get().getDocumentAsync(executionInput, parseAndValidateFunction)
43+
}
44+
45+
return CompletableFuture.completedFuture(parseAndValidateFunction.apply(executionInput))
46+
}
47+
}

graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/apq/DgsAPQSupportAutoConfiguration.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@ package com.netflix.graphql.dgs.apq
1919
import com.github.benmanes.caffeine.cache.Cache
2020
import com.github.benmanes.caffeine.cache.Caffeine
2121
import com.github.benmanes.caffeine.cache.CaffeineSpec
22-
import com.netflix.graphql.dgs.internal.QueryValueCustomizer
22+
import com.netflix.graphql.dgs.springgraphql.autoconfig.DgsSpringGraphQLAutoConfiguration
2323
import graphql.execution.preparsed.PreparsedDocumentEntry
24-
import graphql.execution.preparsed.persisted.ApolloPersistedQuerySupport
24+
import graphql.execution.preparsed.PreparsedDocumentProvider
2525
import graphql.execution.preparsed.persisted.PersistedQueryCache
2626
import io.micrometer.core.instrument.MeterRegistry
2727
import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics
2828
import org.springframework.beans.factory.annotation.Qualifier
2929
import org.springframework.boot.autoconfigure.AutoConfiguration
30+
import org.springframework.boot.autoconfigure.AutoConfigureAfter
3031
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
3132
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
3233
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
3334
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
35+
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer
3436
import org.springframework.boot.context.properties.EnableConfigurationProperties
3537
import org.springframework.context.annotation.Bean
3638
import org.springframework.context.annotation.Configuration
3739
import java.time.Duration
40+
import java.util.*
3841

3942
@AutoConfiguration
43+
@AutoConfigureAfter(DgsSpringGraphQLAutoConfiguration::class)
4044
@ConditionalOnProperty(
4145
prefix = DgsAPQSupportProperties.PREFIX,
4246
name = ["enabled"],
@@ -46,18 +50,17 @@ import java.time.Duration
4650
@EnableConfigurationProperties(DgsAPQSupportProperties::class)
4751
open class DgsAPQSupportAutoConfiguration {
4852
@Bean
49-
@ConditionalOnBean(PersistedQueryCache::class)
50-
open fun apolloPersistedQuerySupport(persistedQueryCache: PersistedQueryCache): ApolloPersistedQuerySupport =
51-
ApolloPersistedQuerySupport(persistedQueryCache)
52-
53-
@Bean
54-
@ConditionalOnBean(ApolloPersistedQuerySupport::class)
55-
open fun apolloAPQQueryValueCustomizer(): QueryValueCustomizer =
56-
QueryValueCustomizer { query ->
57-
if (query.isNullOrBlank()) {
58-
ApolloPersistedQuerySupport.PERSISTED_QUERY_MARKER
59-
} else {
60-
query
53+
open fun apqSourceBuilderCustomizer(
54+
preparsedDocumentProvider: Optional<PreparsedDocumentProvider>,
55+
persistedQueryCache: Optional<PersistedQueryCache>,
56+
): GraphQlSourceBuilderCustomizer =
57+
GraphQlSourceBuilderCustomizer { builder ->
58+
builder.configureGraphQl { graphQlBuilder ->
59+
// For non-APQ queries, the user specified PreparsedDocumentProvider should be used, so we configure the DgsAPQPreparsedDocumentProvider to
60+
// wrap the user specified one and delegate appropriately since we can only have one PreParsedDocumentProvider bean
61+
val apqPreParsedDocumentProvider =
62+
DgsAPQPreParsedDocumentProviderWrapper(persistedQueryCache.get(), preparsedDocumentProvider)
63+
graphQlBuilder.preparsedDocumentProvider(apqPreParsedDocumentProvider)
6164
}
6265
}
6366

0 commit comments

Comments
 (0)