Skip to content

Commit 2a33e6b

Browse files
committed
Extract create argument method
1 parent d635957 commit 2a33e6b

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

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

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graphql.kickstart.tools
22

33
import graphql.introspection.Introspection
4+
import graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION
45
import graphql.kickstart.tools.directive.DirectiveWiringHelper
56
import graphql.kickstart.tools.util.getDocumentation
67
import graphql.kickstart.tools.util.getExtendedFieldDefinitions
@@ -176,12 +177,7 @@ class SchemaParser internal constructor(
176177
.apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } }
177178
.type(determineInputType(fieldDefinition.type, inputObjects, referencingInputObjects))
178179
.withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives))
179-
.withDirectives(
180-
*buildDirectives(
181-
definition.directives,
182-
Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION
183-
)
184-
)
180+
.withDirectives(*buildDirectives(definition.directives, INPUT_FIELD_DEFINITION))
185181
.build()
186182
)
187183
}
@@ -293,27 +289,24 @@ class SchemaParser internal constructor(
293289
.withDirectives(*buildDirectives(fieldDefinition.directives, Introspection.DirectiveLocation.FIELD_DEFINITION))
294290
.apply {
295291
fieldDefinition.inputValueDefinitions.forEach { argumentDefinition ->
296-
argument(
297-
GraphQLArgument.newArgument()
298-
.name(argumentDefinition.name)
299-
.definition(argumentDefinition)
300-
.description(getDocumentation(argumentDefinition, options))
301-
.type(determineInputType(argumentDefinition.type, inputObjects, setOf()))
302-
.apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } }
303-
.apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } }
304-
.withAppliedDirectives(*buildAppliedDirectives(argumentDefinition.directives))
305-
.withDirectives(
306-
*buildDirectives(
307-
fieldDefinition.directives,
308-
Introspection.DirectiveLocation.ARGUMENT_DEFINITION
309-
)
310-
)
311-
.build()
312-
)
292+
argument(createArgument(argumentDefinition, inputObjects))
313293
}
314294
}
315295
}
316296

297+
private fun createArgument(definition: InputValueDefinition, inputObjects: List<GraphQLInputObjectType>): GraphQLArgument {
298+
return GraphQLArgument.newArgument()
299+
.name(definition.name)
300+
.definition(definition)
301+
.description(getDocumentation(definition, options))
302+
.type(determineInputType(definition.type, inputObjects, setOf()))
303+
.apply { getDeprecated(definition.directives)?.let { deprecate(it) } }
304+
.apply { definition.defaultValue?.let { defaultValueLiteral(it) } }
305+
.withAppliedDirectives(*buildAppliedDirectives(definition.directives))
306+
.withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION))
307+
.build()
308+
}
309+
317310
private fun createDirective(definition: DirectiveDefinition, inputObjects: List<GraphQLInputObjectType>): GraphQLDirective {
318311
val locations = definition.directiveLocations.map { Introspection.DirectiveLocation.valueOf(it.name) }.toTypedArray()
319312

@@ -325,17 +318,8 @@ class SchemaParser internal constructor(
325318
.validLocations(*locations)
326319
.repeatable(definition.isRepeatable)
327320
.apply {
328-
definition.inputValueDefinitions.forEach { arg ->
329-
argument(GraphQLArgument.newArgument()
330-
.name(arg.name)
331-
.definition(arg)
332-
.description(getDocumentation(arg, options))
333-
.type(determineInputType(arg.type, inputObjects, setOf()))
334-
.apply { getDeprecated(arg.directives)?.let { deprecate(it) } }
335-
.apply { arg.defaultValue?.let { defaultValueLiteral(it) } }
336-
.withAppliedDirectives(*buildAppliedDirectives(arg.directives))
337-
.withDirectives(*buildDirectives(arg.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION))
338-
.build())
321+
definition.inputValueDefinitions.forEach { argumentDefinition ->
322+
argument(createArgument(argumentDefinition, inputObjects))
339323
}
340324
}
341325
.build()

0 commit comments

Comments
 (0)