Skip to content

Replace usage of deprecated defaultValue with defaultValueLiteral when building fields #572

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

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SchemaParser internal constructor(
.name(inputDefinition.name)
.definition(inputDefinition)
.description(getDocumentation(inputDefinition, options))
.defaultValue(buildDefaultValue(inputDefinition.defaultValue))
.apply { inputDefinition.defaultValue?.let { v -> defaultValueLiteral(v) } }
.type(determineInputType(inputDefinition.type, inputObjects, referencingInputObjects))
.withDirectives(*buildDirectives(inputDefinition.directives, Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
builder.field(fieldBuilder.build())
Expand Down Expand Up @@ -288,7 +288,7 @@ class SchemaParser internal constructor(
.definition(argumentDefinition)
.description(getDocumentation(argumentDefinition, options))
.type(determineInputType(argumentDefinition.type, inputObjects, setOf()))
.apply { buildDefaultValue(argumentDefinition.defaultValue)?.let { defaultValue(it) } }
.apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } }
.withDirectives(*buildDirectives(argumentDefinition.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION))

field.argument(argumentBuilder.build())
Expand Down Expand Up @@ -364,20 +364,6 @@ class SchemaParser internal constructor(
return nonNullValueList[0]
}

private fun buildDefaultValue(value: Value<*>?): Any? {
return when (value) {
null -> null
is IntValue -> value.value.toInt()
is FloatValue -> value.value.toDouble()
is StringValue -> value.value
is EnumValue -> value.name
is BooleanValue -> value.isValue
is ArrayValue -> value.values.map { buildDefaultValue(it) }
is ObjectValue -> value.objectFields.associate { it.name to buildDefaultValue(it.value) }
else -> throw SchemaError("Unrecognized default value: $value")
}
}

private fun determineOutputType(typeDefinition: Type<*>, inputObjects: List<GraphQLInputObjectType>) =
determineType(GraphQLOutputType::class, typeDefinition, permittedTypesForObject, inputObjects) as GraphQLOutputType

Expand Down