From eca59d457e89c0a4f296f41f82a1176f139ee2a3 Mon Sep 17 00:00:00 2001 From: "$(git --no-pager log --format=format:'%an' -n 1)" Date: Tue, 5 Nov 2024 11:07:26 -0800 Subject: [PATCH 1/2] Improve handling of spring.graphql.schema.introspection.enabled and dgs.graphql.introspection.enabled properties --- .../dgs/autoconfig/DgsAutoConfiguration.kt | 2 ++ .../DgsSpringGraphQLEnvironmentPostProcessor.kt | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/graphql-dgs-spring-boot-oss-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.kt b/graphql-dgs-spring-boot-oss-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.kt index 7d8d6f1e6..6c1f29aab 100644 --- a/graphql-dgs-spring-boot-oss-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.kt +++ b/graphql-dgs-spring-boot-oss-autoconfigure/src/main/kotlin/com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.kt @@ -289,7 +289,9 @@ open class DgsAutoConfiguration( Duration.parse(configProps.preparsedDocumentProvider.cacheValidityDuration), ) + // TODO: Remove when legacy modules are removed. This is also handled in DgsSpringGraphQLAutoConfiguration @Bean + @ConditionalOnMissingBean @ConditionalOnProperty( prefix = "$AUTO_CONF_PREFIX.introspection", name = ["enabled"], diff --git a/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt b/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt index 0fd682947..71f0df636 100644 --- a/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt +++ b/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt @@ -20,6 +20,7 @@ import org.springframework.boot.SpringApplication import org.springframework.boot.env.EnvironmentPostProcessor import org.springframework.core.env.ConfigurableEnvironment import org.springframework.core.env.MapPropertySource +import org.springframework.core.env.get class DgsSpringGraphQLEnvironmentPostProcessor : EnvironmentPostProcessor { override fun postProcessEnvironment( @@ -28,7 +29,19 @@ class DgsSpringGraphQLEnvironmentPostProcessor : EnvironmentPostProcessor { ) { val properties = mutableMapOf() - properties["spring.graphql.schema.introspection.enabled"] = environment.getProperty("dgs.graphql.introspection.enabled") ?: true + if (environment.getProperty("spring.graphql.schema.introspection.enabled") != null && + environment.getProperty("dgs.graphql.introspection.enabled") != null + ) { + throw RuntimeException( + "Both properties `spring.graphql.schema.introspection.enabled` and `dgs.graphql.introspection.enabled` are explicitly set. Use `dgs.graphql.introspection.enabled` only", + ) + } else if (environment.getProperty("dgs.graphql.introspection.enabled") != null) { + properties["spring.graphql.schema.introspection.enabled"] = environment.getProperty("dgs.graphql.introspection.enabled") ?: true + } else { + properties["spring.graphql.schema.introspection.enabled"] = + environment["spring.graphql.schema.introspection.enabled"] ?: true + } + properties["spring.graphql.graphiql.enabled"] = environment.getProperty("dgs.graphql.graphiql.enabled") ?: true properties["spring.graphql.graphiql.path"] = environment.getProperty("dgs.graphql.graphiql.path") ?: "/graphiql" properties["spring.graphql.path"] = environment.getProperty("dgs.graphql.path") ?: "/graphql" From 9784ce65c9e16c42cea90d75c30dd3c6bef1aef5 Mon Sep 17 00:00:00 2001 From: "$(git --no-pager log --format=format:'%an' -n 1)" Date: Wed, 6 Nov 2024 13:20:38 -0800 Subject: [PATCH 2/2] Use constants for property --- ...gsSpringGraphQLEnvironmentPostProcessor.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt b/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt index 71f0df636..5eb13764e 100644 --- a/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt +++ b/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLEnvironmentPostProcessor.kt @@ -23,23 +23,30 @@ import org.springframework.core.env.MapPropertySource import org.springframework.core.env.get class DgsSpringGraphQLEnvironmentPostProcessor : EnvironmentPostProcessor { + companion object { + private const val SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED = "spring.graphql.schema.introspection.enabled" + private const val DGS_GRAPHQL_INTROSPECTION_ENABLED = "dgs.graphql.introspection.enabled" + } + override fun postProcessEnvironment( environment: ConfigurableEnvironment, application: SpringApplication, ) { val properties = mutableMapOf() - if (environment.getProperty("spring.graphql.schema.introspection.enabled") != null && - environment.getProperty("dgs.graphql.introspection.enabled") != null + if (environment.getProperty(SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED) != null && + environment.getProperty(DGS_GRAPHQL_INTROSPECTION_ENABLED) != null ) { throw RuntimeException( - "Both properties `spring.graphql.schema.introspection.enabled` and `dgs.graphql.introspection.enabled` are explicitly set. Use `dgs.graphql.introspection.enabled` only", + "Both properties `$SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED` and `$DGS_GRAPHQL_INTROSPECTION_ENABLED` are explicitly set. Use `$DGS_GRAPHQL_INTROSPECTION_ENABLED` only", ) - } else if (environment.getProperty("dgs.graphql.introspection.enabled") != null) { - properties["spring.graphql.schema.introspection.enabled"] = environment.getProperty("dgs.graphql.introspection.enabled") ?: true + } else if (environment.getProperty(DGS_GRAPHQL_INTROSPECTION_ENABLED) != null) { + properties[SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED] = environment.getProperty( + DGS_GRAPHQL_INTROSPECTION_ENABLED, + ) ?: true } else { - properties["spring.graphql.schema.introspection.enabled"] = - environment["spring.graphql.schema.introspection.enabled"] ?: true + properties[SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED] = + environment[SPRING_GRAPHQL_SCHEMA_INTROSPECTION_ENABLED] ?: true } properties["spring.graphql.graphiql.enabled"] = environment.getProperty("dgs.graphql.graphiql.enabled") ?: true