Skip to content

Commit 4685314

Browse files
committed
Fix applied directive support
1 parent b4f0fd8 commit 4685314

3 files changed

Lines changed: 55 additions & 15 deletions

File tree

lib/src/main/java/graphql/nadel/definition/coordinates/NadelSchemaMemberCoordinatesFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class NadelSchemaMemberCoordinatesFactory {
160160
element: NadelSchemaTraverserElement.AppliedDirective,
161161
): Boolean {
162162
coordinates.add(element.coordinates())
163-
return true
163+
return false // Don't traverse argument further
164164
}
165165

166166
override fun visitGraphQLAppliedDirectiveArgument(

lib/src/main/java/graphql/nadel/engine/blueprint/NadelSchemaTraverserElement.kt

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal sealed interface NadelSchemaTraverserElement {
7171
override fun coordinates(): NadelArgumentParentCoordinates
7272
}
7373

74-
sealed interface Argument : NadelSchemaTraverserElement {
74+
sealed interface Argument : NadelSchemaTraverserElement, AppliedDirectiveParent {
7575
override val parent: ArgumentParent
7676

7777
override val node: GraphQLArgument
@@ -82,6 +82,10 @@ internal sealed interface NadelSchemaTraverserElement {
8282

8383
override fun forEachChild(onElement: (NadelSchemaTraverserElement) -> Unit) {
8484
onElement(InputType.from(node.type))
85+
86+
node.appliedDirectives.forEach {
87+
onElement(AppliedDirective(this, it))
88+
}
8589
}
8690
}
8791

@@ -144,7 +148,7 @@ internal sealed interface NadelSchemaTraverserElement {
144148

145149
data class UnionType(
146150
override val node: GraphQLUnionType,
147-
) : NadelSchemaTraverserElement, Type, OutputType {
151+
) : NadelSchemaTraverserElement, Type, OutputType, AppliedDirectiveParent {
148152
override val parent: NadelSchemaTraverserElement? = null
149153

150154
override fun coordinates(): NadelUnionCoordinates {
@@ -155,6 +159,10 @@ internal sealed interface NadelSchemaTraverserElement {
155159
node.types.forEach { member ->
156160
onElement(UnionMemberType(this, member as GraphQLObjectType))
157161
}
162+
163+
node.appliedDirectives.forEach {
164+
onElement(AppliedDirective(this, it))
165+
}
158166
}
159167
}
160168

@@ -179,7 +187,7 @@ internal sealed interface NadelSchemaTraverserElement {
179187

180188
data class InterfaceType(
181189
override val node: GraphQLInterfaceType,
182-
) : NadelSchemaTraverserElement, Type, OutputType, FieldsContainer {
190+
) : NadelSchemaTraverserElement, Type, OutputType, FieldsContainer, AppliedDirectiveParent {
183191
override val parent: NadelSchemaTraverserElement? = null
184192

185193
override fun coordinates(): NadelInterfaceCoordinates {
@@ -193,12 +201,15 @@ internal sealed interface NadelSchemaTraverserElement {
193201
node.interfaces.forEach { parentType ->
194202
onElement(InterfaceType(parentType as GraphQLInterfaceType))
195203
}
204+
node.appliedDirectives.forEach {
205+
onElement(AppliedDirective(this, it))
206+
}
196207
}
197208
}
198209

199210
data class EnumType(
200211
override val node: GraphQLEnumType,
201-
) : NadelSchemaTraverserElement, Type, InputType, OutputType {
212+
) : NadelSchemaTraverserElement, Type, InputType, OutputType, AppliedDirectiveParent {
202213
override val parent: NadelSchemaTraverserElement? = null
203214

204215
override fun coordinates(): NadelEnumCoordinates {
@@ -209,25 +220,32 @@ internal sealed interface NadelSchemaTraverserElement {
209220
node.values.forEach { value ->
210221
onElement(EnumValueDefinition(this, value))
211222
}
223+
224+
node.appliedDirectives.forEach {
225+
onElement(AppliedDirective(this, it))
226+
}
212227
}
213228
}
214229

215230
data class EnumValueDefinition(
216231
override val parent: EnumType,
217232
override val node: GraphQLEnumValueDefinition,
218-
) : NadelSchemaTraverserElement {
233+
) : NadelSchemaTraverserElement, AppliedDirectiveParent {
219234
override fun coordinates(): NadelEnumValueCoordinates {
220235
return parent.coordinates().enumValue(node.name)
221236
}
222237

223238
override fun forEachChild(onElement: (NadelSchemaTraverserElement) -> Unit) {
239+
node.appliedDirectives.forEach {
240+
onElement(AppliedDirective(this, it))
241+
}
224242
}
225243
}
226244

227245
data class FieldDefinition(
228246
override val parent: FieldsContainer,
229247
override val node: GraphQLFieldDefinition,
230-
) : NadelSchemaTraverserElement, ArgumentParent {
248+
) : NadelSchemaTraverserElement, ArgumentParent, AppliedDirectiveParent {
231249
override fun coordinates(): NadelFieldCoordinates {
232250
return parent.coordinates().field(node.name)
233251
}
@@ -238,25 +256,33 @@ internal sealed interface NadelSchemaTraverserElement {
238256
node.arguments.forEach { arg ->
239257
onElement(FieldArgument(this, arg))
240258
}
259+
260+
node.appliedDirectives.forEach {
261+
onElement(AppliedDirective(this, it))
262+
}
241263
}
242264
}
243265

244266
data class InputObjectField(
245267
override val parent: InputObjectType,
246268
override val node: GraphQLInputObjectField,
247-
) : NadelSchemaTraverserElement {
269+
) : NadelSchemaTraverserElement, AppliedDirectiveParent {
248270
override fun coordinates(): NadelInputObjectFieldCoordinates {
249271
return parent.coordinates().field(node.name)
250272
}
251273

252274
override fun forEachChild(onElement: (NadelSchemaTraverserElement) -> Unit) {
253275
onElement(InputType.from(node.type))
276+
277+
node.appliedDirectives.forEach {
278+
onElement(AppliedDirective(this, it))
279+
}
254280
}
255281
}
256282

257283
data class InputObjectType(
258284
override val node: GraphQLInputObjectType,
259-
) : NadelSchemaTraverserElement, Type, InputType {
285+
) : NadelSchemaTraverserElement, Type, InputType, AppliedDirectiveParent {
260286
override val parent: NadelSchemaTraverserElement? = null
261287

262288
override fun coordinates(): NadelInputObjectCoordinates {
@@ -267,12 +293,16 @@ internal sealed interface NadelSchemaTraverserElement {
267293
node.fields.forEach { field ->
268294
onElement(InputObjectField(this, field))
269295
}
296+
297+
node.appliedDirectives.forEach {
298+
onElement(AppliedDirective(this, it))
299+
}
270300
}
271301
}
272302

273303
data class ObjectType(
274304
override val node: GraphQLObjectType,
275-
) : NadelSchemaTraverserElement, Type, OutputType, FieldsContainer {
305+
) : NadelSchemaTraverserElement, Type, OutputType, FieldsContainer, AppliedDirectiveParent {
276306
override val parent: NadelSchemaTraverserElement? = null
277307

278308
override fun coordinates(): NadelObjectCoordinates {
@@ -287,19 +317,26 @@ internal sealed interface NadelSchemaTraverserElement {
287317
node.interfaces.forEach { parentType ->
288318
onElement(InterfaceType(parentType as GraphQLInterfaceType))
289319
}
320+
321+
node.appliedDirectives.forEach {
322+
onElement(AppliedDirective(this, it))
323+
}
290324
}
291325
}
292326

293327
data class ScalarType(
294328
override val node: GraphQLScalarType,
295-
) : NadelSchemaTraverserElement, Type, InputType, OutputType {
329+
) : NadelSchemaTraverserElement, Type, InputType, OutputType , AppliedDirectiveParent{
296330
override val parent: NadelSchemaTraverserElement? = null
297331

298332
override fun coordinates(): NadelScalarCoordinates {
299333
return node.coordinates()
300334
}
301335

302336
override fun forEachChild(onElement: (NadelSchemaTraverserElement) -> Unit) {
337+
node.appliedDirectives.forEach {
338+
onElement(AppliedDirective(this, it))
339+
}
303340
}
304341
}
305342

@@ -323,15 +360,15 @@ internal sealed interface NadelSchemaTraverserElement {
323360
override val parent: AppliedDirectiveParent,
324361
override val node: GraphQLAppliedDirective,
325362
) : NadelSchemaTraverserElement {
363+
override fun coordinates(): NadelAppliedDirectiveCoordinates {
364+
return parent.coordinates().appliedDirective(node.name)
365+
}
366+
326367
override fun forEachChild(onElement: (NadelSchemaTraverserElement) -> Unit) {
327368
node.arguments.forEach { arg ->
328369
onElement(AppliedDirectiveArgument(this, arg))
329370
}
330371
}
331-
332-
override fun coordinates(): NadelAppliedDirectiveCoordinates {
333-
return parent.coordinates().appliedDirective(node.name)
334-
}
335372
}
336373

337374
companion object {

lib/src/test/kotlin/graphql/nadel/definition/coordinates/NadelSchemaMemberCoordinatesFactoryTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class NadelSchemaMemberCoordinatesFactoryTest {
8787
}
8888
type Query {
8989
me: AuthenticationContext!
90+
authContext: AuthenticationContext @deprecated(reason: "Hello world")
9091
user(accountId: ID!): User
9192
users(accountIds: [ID!]!): [User!]
9293
thirdPartyUsers(ids: [ID!]!): [ThirdPartyUser!]
@@ -96,6 +97,8 @@ class NadelSchemaMemberCoordinatesFactoryTest {
9697
val expectedSet = setOf(
9798
NadelObjectCoordinates("Query"),
9899
NadelObjectCoordinates("Query").field("me"),
100+
NadelObjectCoordinates("Query").field("authContext"),
101+
NadelObjectCoordinates("Query").field("authContext").appliedDirective("deprecated"),
99102
NadelObjectCoordinates("AuthenticationContext"),
100103
NadelObjectCoordinates("AuthenticationContext").field("user"),
101104
NadelInterfaceCoordinates("User"),

0 commit comments

Comments
 (0)