Skip to content

Commit 6239b2f

Browse files
authored
Merge pull request #572 from graphql-java-kickstart/default-value-literal-fix
Replace usage of deprecated defaultValue with defaultValueLiteral when building fields
2 parents 51d9e88 + 913d771 commit 6239b2f

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

+2-16
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class SchemaParser internal constructor(
174174
.name(inputDefinition.name)
175175
.definition(inputDefinition)
176176
.description(getDocumentation(inputDefinition, options))
177-
.defaultValue(buildDefaultValue(inputDefinition.defaultValue))
177+
.apply { inputDefinition.defaultValue?.let { v -> defaultValueLiteral(v) } }
178178
.type(determineInputType(inputDefinition.type, inputObjects, referencingInputObjects))
179179
.withDirectives(*buildDirectives(inputDefinition.directives, Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
180180
builder.field(fieldBuilder.build())
@@ -288,7 +288,7 @@ class SchemaParser internal constructor(
288288
.definition(argumentDefinition)
289289
.description(getDocumentation(argumentDefinition, options))
290290
.type(determineInputType(argumentDefinition.type, inputObjects, setOf()))
291-
.apply { buildDefaultValue(argumentDefinition.defaultValue)?.let { defaultValue(it) } }
291+
.apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } }
292292
.withDirectives(*buildDirectives(argumentDefinition.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION))
293293

294294
field.argument(argumentBuilder.build())
@@ -364,20 +364,6 @@ class SchemaParser internal constructor(
364364
return nonNullValueList[0]
365365
}
366366

367-
private fun buildDefaultValue(value: Value<*>?): Any? {
368-
return when (value) {
369-
null -> null
370-
is IntValue -> value.value.toInt()
371-
is FloatValue -> value.value.toDouble()
372-
is StringValue -> value.value
373-
is EnumValue -> value.name
374-
is BooleanValue -> value.isValue
375-
is ArrayValue -> value.values.map { buildDefaultValue(it) }
376-
is ObjectValue -> value.objectFields.associate { it.name to buildDefaultValue(it.value) }
377-
else -> throw SchemaError("Unrecognized default value: $value")
378-
}
379-
}
380-
381367
private fun determineOutputType(typeDefinition: Type<*>, inputObjects: List<GraphQLInputObjectType>) =
382368
determineType(GraphQLOutputType::class, typeDefinition, permittedTypesForObject, inputObjects) as GraphQLOutputType
383369

0 commit comments

Comments
 (0)