@@ -122,6 +122,7 @@ class SchemaParser internal constructor(
122122 .definition(objectDefinition)
123123 .description(getDocumentation(objectDefinition, options))
124124 .withAppliedDirectives(* buildAppliedDirectives(objectDefinition.directives))
125+ .withDirectives(* buildDirectives(objectDefinition.directives, Introspection .DirectiveLocation .OBJECT ))
125126 .apply {
126127 objectDefinition.implements.forEach { implementsDefinition ->
127128 val interfaceName = (implementsDefinition as TypeName ).name
@@ -162,6 +163,7 @@ class SchemaParser internal constructor(
162163 .extensionDefinitions(extensionDefinitions)
163164 .description(getDocumentation(definition, options))
164165 .withAppliedDirectives(* buildAppliedDirectives(definition.directives))
166+ .withDirectives(* buildDirectives(definition.directives, Introspection .DirectiveLocation .INPUT_OBJECT ))
165167 .apply {
166168 (extensionDefinitions + definition).forEach { typeDefinition ->
167169 typeDefinition.inputValueDefinitions.forEach { fieldDefinition ->
@@ -174,6 +176,12 @@ class SchemaParser internal constructor(
174176 .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } }
175177 .type(determineInputType(fieldDefinition.type, inputObjects, referencingInputObjects))
176178 .withAppliedDirectives(* buildAppliedDirectives(fieldDefinition.directives))
179+ .withDirectives(
180+ * buildDirectives(
181+ definition.directives,
182+ Introspection .DirectiveLocation .INPUT_FIELD_DEFINITION
183+ )
184+ )
177185 .build()
178186 )
179187 }
@@ -194,6 +202,7 @@ class SchemaParser internal constructor(
194202 .definition(definition)
195203 .description(getDocumentation(definition, options))
196204 .withAppliedDirectives(* buildAppliedDirectives(definition.directives))
205+ .withDirectives(* buildDirectives(definition.directives, Introspection .DirectiveLocation .ENUM ))
197206 .apply {
198207 definition.enumValueDefinitions.forEach { valueDefinition ->
199208 val enumName = valueDefinition.name
@@ -207,6 +216,7 @@ class SchemaParser internal constructor(
207216 .value(enumValue)
208217 .apply { getDeprecated(valueDefinition.directives)?.let { deprecationReason(it) } }
209218 .withAppliedDirectives(* buildAppliedDirectives(valueDefinition.directives))
219+ .withDirectives(* buildDirectives(valueDefinition.directives, Introspection .DirectiveLocation .ENUM_VALUE ))
210220 .definition(valueDefinition)
211221 .build()
212222 )
@@ -222,6 +232,7 @@ class SchemaParser internal constructor(
222232 .definition(interfaceDefinition)
223233 .description(getDocumentation(interfaceDefinition, options))
224234 .withAppliedDirectives(* buildAppliedDirectives(interfaceDefinition.directives))
235+ .withDirectives(* buildDirectives(interfaceDefinition.directives, Introspection .DirectiveLocation .INTERFACE ))
225236 .apply {
226237 interfaceDefinition.fieldDefinitions.forEach { fieldDefinition ->
227238 field { field -> createField(field, fieldDefinition, inputObjects) }
@@ -243,6 +254,7 @@ class SchemaParser internal constructor(
243254 .definition(definition)
244255 .description(getDocumentation(definition, options))
245256 .withAppliedDirectives(* buildAppliedDirectives(definition.directives))
257+ .withDirectives(* buildDirectives(definition.directives, Introspection .DirectiveLocation .UNION ))
246258 .apply {
247259 getLeafUnionObjects(definition, types).forEach { possibleType(it) }
248260 }
@@ -278,6 +290,7 @@ class SchemaParser internal constructor(
278290 .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } }
279291 .type(determineOutputType(fieldDefinition.type, inputObjects))
280292 .withAppliedDirectives(* buildAppliedDirectives(fieldDefinition.directives))
293+ .withDirectives(* buildDirectives(fieldDefinition.directives, Introspection .DirectiveLocation .FIELD_DEFINITION ))
281294 .apply {
282295 fieldDefinition.inputValueDefinitions.forEach { argumentDefinition ->
283296 argument(
@@ -289,6 +302,12 @@ class SchemaParser internal constructor(
289302 .apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } }
290303 .apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } }
291304 .withAppliedDirectives(* buildAppliedDirectives(argumentDefinition.directives))
305+ .withDirectives(
306+ * buildDirectives(
307+ fieldDefinition.directives,
308+ Introspection .DirectiveLocation .ARGUMENT_DEFINITION
309+ )
310+ )
292311 .build()
293312 )
294313 }
@@ -315,6 +334,7 @@ class SchemaParser internal constructor(
315334 .apply { getDeprecated(arg.directives)?.let { deprecate(it) } }
316335 .apply { arg.defaultValue?.let { defaultValueLiteral(it) } }
317336 .withAppliedDirectives(* buildAppliedDirectives(arg.directives))
337+ .withDirectives(* buildDirectives(arg.directives, Introspection .DirectiveLocation .ARGUMENT_DEFINITION ))
318338 .build())
319339 }
320340 }
@@ -333,17 +353,31 @@ class SchemaParser internal constructor(
333353 .name(arg.name)
334354 .type(directiveWiringHelper.buildDirectiveInputType(arg.value))
335355 .valueLiteral(arg.value)
336- .build())
356+ .build()
357+ )
337358 }
338359 }
339360 .build()
340361 }.toTypedArray()
341362 }
342363
364+ // TODO remove this once directives are fully replaced with applied directives
365+ private fun buildDirectives (
366+ directives : List <Directive >,
367+ directiveLocation : Introspection .DirectiveLocation
368+ ): Array <GraphQLDirective > {
369+ return directiveWiringHelper.buildDirectives(directives, directiveLocation).toTypedArray()
370+ }
371+
343372 private fun determineOutputType (typeDefinition : Type <* >, inputObjects : List <GraphQLInputObjectType >) =
344373 determineType(GraphQLOutputType ::class , typeDefinition, permittedTypesForObject, inputObjects) as GraphQLOutputType
345374
346- private fun <T : Any > determineType (expectedType : KClass <T >, typeDefinition : Type <* >, allowedTypeReferences : Set <String >, inputObjects : List <GraphQLInputObjectType >): GraphQLType =
375+ private fun <T : Any > determineType (
376+ expectedType : KClass <T >,
377+ typeDefinition : Type <* >,
378+ allowedTypeReferences : Set <String >,
379+ inputObjects : List <GraphQLInputObjectType >
380+ ): GraphQLType =
347381 when (typeDefinition) {
348382 is ListType -> GraphQLList (determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects))
349383 is NonNullType -> GraphQLNonNull (determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects))
0 commit comments