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

Have the ability to turn off the BigDecimal and BigInteger extended scalars #1311

Merged
merged 1 commit into from Nov 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,10 +21,13 @@ import com.netflix.graphql.dgs.DgsRuntimeWiring
import graphql.scalars.ExtendedScalars
import graphql.schema.GraphQLScalarType
import graphql.schema.idl.RuntimeWiring
import org.springframework.boot.autoconfigure.condition.AllNestedConditions
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Conditional
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.ConfigurationCondition

@ConditionalOnClass(graphql.scalars.ExtendedScalars::class)
@ConditionalOnProperty(
Expand Down Expand Up @@ -108,13 +111,78 @@ open class DgsExtendedScalarsAutoConfiguration {
// Others
ExtendedScalars.GraphQLLong,
ExtendedScalars.GraphQLShort,
ExtendedScalars.GraphQLByte,
ExtendedScalars.GraphQLBigDecimal,
ExtendedScalars.GraphQLBigInteger
ExtendedScalars.GraphQLByte
)
}
}
}

@Conditional(OnBigDecimalAndNumbers::class)
@Configuration(proxyBeanMethods = false)
open class BigDecimalAutoConfiguration {
@Bean
open fun bigDecimalExtendedScalarsRegistrar(): ExtendedScalarRegistrar {
return object : AbstractExtendedScalarRegistrar() {
override fun getScalars(): List<GraphQLScalarType> {
return listOf(
// Others
ExtendedScalars.GraphQLBigDecimal
)
}
}
}
}

open class OnBigDecimalAndNumbers :
AllNestedConditions(ConfigurationCondition.ConfigurationPhase.PARSE_CONFIGURATION) {
@ConditionalOnProperty(
prefix = "dgs.graphql.extensions.scalars.numbers.",
name = ["enabled"],
havingValue = "true",
matchIfMissing = true
)
open class OnNumbers

@ConditionalOnProperty(
prefix = "dgs.graphql.extensions.scalars.numbers.bigdecimal",
name = ["enabled"],
havingValue = "true",
matchIfMissing = true
)
open class OnBigDecimal
}

@Conditional(OnBigIntegerAndNumbers::class)
@Configuration(proxyBeanMethods = false)
open class BigIntegerAutoConfiguration {
@Bean
open fun bigIntegerExtendedScalarsRegistrar(): ExtendedScalarRegistrar {
return object : AbstractExtendedScalarRegistrar() {
override fun getScalars(): List<GraphQLScalarType> {
return listOf(ExtendedScalars.GraphQLBigInteger)
}
}
}
}

open class OnBigIntegerAndNumbers :
AllNestedConditions(ConfigurationCondition.ConfigurationPhase.PARSE_CONFIGURATION) {
@ConditionalOnProperty(
prefix = "dgs.graphql.extensions.scalars.numbers.",
name = ["enabled"],
havingValue = "true",
matchIfMissing = true
)
open class OnNumbers

@ConditionalOnProperty(
prefix = "dgs.graphql.extensions.scalars.numbers.biginteger",
name = ["enabled"],
havingValue = "true",
matchIfMissing = true
)
open class OnBigInteger
}
}

@ConditionalOnProperty(
Expand Down
Expand Up @@ -19,7 +19,17 @@
{
"name": "dgs.graphql.extensions.scalars.numbers.enabled",
"type": "java.lang.Boolean",
"description": "Enabled by default, if dgs.graphql.extensions.scalars.enabled is enabled, will register all numeric scalar extensions such as PositiveInt, NegativeInt, etc."
"description": "Enabled by default, will register all numeric scalar extensions such as PositiveInt, NegativeInt, etc."
},
{
"name": "dgs.graphql.extensions.scalars.numbers.bigdecimal.enabled",
"type": "java.lang.Boolean",
"description": "Enabled by default, can be used to disable the BigDecimal scalar; it requires dgs.graphql.extensions.scalars.numbers.enabled to be enabled as well."
},
{
"name": "dgs.graphql.extensions.scalars.numbers.biginteger.enabled",
"type": "java.lang.Boolean",
"description": "Enabled by default, can be used to disable the BigInteger scalar; it requires dgs.graphql.extensions.scalars.numbers.enabled to be enabled as well."
},
{
"name": "dgs.graphql.extensions.scalars.chars.enabled",
Expand Down
Expand Up @@ -35,6 +35,8 @@ internal class DgsExtendedScalarsAutoConfigurationTests {
.hasSingleBean(DgsExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.CharsExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigDecimalAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigIntegerAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.ObjectsExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.TimeExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.IDsExtendedScalarsAutoConfiguration::class.java)
Expand Down Expand Up @@ -84,6 +86,36 @@ internal class DgsExtendedScalarsAutoConfigurationTests {
.hasSingleBean(DgsExtendedScalarsAutoConfiguration::class.java)
assertThat(context)
.doesNotHaveBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration::class.java)
.doesNotHaveBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigDecimalAutoConfiguration::class.java)
.doesNotHaveBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigIntegerAutoConfiguration::class.java)
}
}

@Test
fun `The BigDecimal scalar can be disabled`() {
context.withPropertyValues(
"dgs.graphql.extensions.scalars.numbers.bigdecimal.enabled=false"
).run { context ->
assertThat(context)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigIntegerAutoConfiguration::class.java)
assertThat(context)
.doesNotHaveBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigDecimalAutoConfiguration::class.java)
}
}

@Test
fun `The BigInteger scalar can be disabled`() {
context.withPropertyValues(
"dgs.graphql.extensions.scalars.numbers.biginteger.enabled=false"
).run { context ->
assertThat(context)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration::class.java)
.hasSingleBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigDecimalAutoConfiguration::class.java)
assertThat(context)
.doesNotHaveBean(DgsExtendedScalarsAutoConfiguration.NumbersExtendedScalarsAutoConfiguration.BigIntegerAutoConfiguration::class.java)
}
}

Expand Down