Skip to content

Commit

Permalink
Merge pull request #2056 from Netflix/fix/#2024
Browse files Browse the repository at this point in the history
Improve handling of introspection properties.
  • Loading branch information
paulbakker authored Nov 6, 2024
2 parents b4513c6 + 06dac26 commit 8a08df7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,35 @@ 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 {
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<String, Any>()

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"
Expand Down

0 comments on commit 8a08df7

Please sign in to comment.