@@ -77,20 +77,21 @@ class DirectiveWiringHelper(
7777 private fun <T : GraphQLDirectiveContainer > wireDirectives (wrapper : WiringWrapper <T >): T {
7878 val directivesContainer = wrapper.graphQlType.definition as DirectivesContainer <* >
7979 val directives = buildDirectives(directivesContainer.directives, wrapper.directiveLocation)
80+ val directivesByName = directives.associateBy { it.name }
8081 var output = wrapper.graphQlType
8182 // first the specific named directives
82- directives. forEach { directive ->
83- val env = buildEnvironment(wrapper, directives, directive )
84- val wiring = runtimeWiring.registeredDirectiveWiring[directive .name]
83+ wrapper.graphQlType.appliedDirectives. forEach { appliedDirective ->
84+ val env = buildEnvironment(wrapper, directives, directivesByName[appliedDirective.name], appliedDirective )
85+ val wiring = runtimeWiring.registeredDirectiveWiring[appliedDirective .name]
8586 wiring?.let { output = wrapper.invoker(it, env) }
8687 }
8788 // now call any statically added to the runtime
8889 runtimeWiring.directiveWiring.forEach { staticWiring ->
89- val env = buildEnvironment(wrapper, directives, null )
90+ val env = buildEnvironment(wrapper, directives, null , null )
9091 output = wrapper.invoker(staticWiring, env)
9192 }
9293 // wiring factory is last (if present)
93- val env = buildEnvironment(wrapper, directives, null )
94+ val env = buildEnvironment(wrapper, directives, null , null )
9495 if (runtimeWiring.wiringFactory.providesSchemaDirectiveWiring(env)) {
9596 val factoryWiring = runtimeWiring.wiringFactory.getSchemaDirectiveWiring(env)
9697 output = wrapper.invoker(factoryWiring, env)
@@ -131,7 +132,7 @@ class DirectiveWiringHelper(
131132 return output
132133 }
133134
134- private fun <T : GraphQLDirectiveContainer > buildEnvironment (wrapper : WiringWrapper <T >, directives : List <GraphQLDirective >, directive : GraphQLDirective ? ): SchemaDirectiveWiringEnvironmentImpl <T > {
135+ private fun <T : GraphQLDirectiveContainer > buildEnvironment (wrapper : WiringWrapper <T >, directives : List <GraphQLDirective >, directive : GraphQLDirective ? , appliedDirective : GraphQLAppliedDirective ? ): SchemaDirectiveWiringEnvironmentImpl <T > {
135136 val nodeParentTree = buildAstTree(* listOfNotNull(
136137 wrapper.fieldsContainer?.definition,
137138 wrapper.inputFieldsContainer?.definition,
@@ -154,7 +155,7 @@ class DirectiveWiringHelper(
154155 is GraphQLFieldsContainer -> schemaDirectiveParameters.newParams(wrapper.graphQlType, nodeParentTree, elementParentTree)
155156 else -> schemaDirectiveParameters.newParams(nodeParentTree, elementParentTree)
156157 }
157- return SchemaDirectiveWiringEnvironmentImpl (wrapper.graphQlType, directives, wrapper.graphQlType.appliedDirectives, directive, params)
158+ return SchemaDirectiveWiringEnvironmentImpl (wrapper.graphQlType, directives, wrapper.graphQlType.appliedDirectives, directive, appliedDirective, params)
158159 }
159160
160161 fun buildDirectiveInputType (value : Value <* >): GraphQLInputType ? {
0 commit comments