Skip to content

Commit 0908fac

Browse files
committed
Add support for directives on directive definitions
1 parent 3c262e9 commit 0908fac

File tree

16 files changed

+204
-27
lines changed

16 files changed

+204
-27
lines changed

libraries/apollo-ast/api/apollo-ast.api

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,21 @@ public final class com/apollographql/apollo/ast/GQLDirectiveCoordinate : com/apo
231231
public fun writeInternal (Lcom/apollographql/apollo/ast/SDLWriter;)V
232232
}
233233

234-
public final class com/apollographql/apollo/ast/GQLDirectiveDefinition : com/apollographql/apollo/ast/GQLDefinition, com/apollographql/apollo/ast/GQLDescribed, com/apollographql/apollo/ast/GQLNamed {
234+
public final class com/apollographql/apollo/ast/GQLDirectiveDefinition : com/apollographql/apollo/ast/GQLDefinition, com/apollographql/apollo/ast/GQLDescribed, com/apollographql/apollo/ast/GQLHasDirectives, com/apollographql/apollo/ast/GQLNamed {
235235
public static final field Companion Lcom/apollographql/apollo/ast/GQLDirectiveDefinition$Companion;
236236
public fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;)V
237237
public synthetic fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
238-
public final fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;)Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;
238+
public fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;Ljava/util/List;)V
239+
public synthetic fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
240+
public final synthetic fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;)Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;
241+
public final fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;
239242
public static synthetic fun copy$default (Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;ILjava/lang/Object;)Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;
243+
public static synthetic fun copy$default (Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZLjava/util/List;Ljava/util/List;ILjava/lang/Object;)Lcom/apollographql/apollo/ast/GQLDirectiveDefinition;
240244
public fun copyWithNewChildrenInternal (Lcom/apollographql/apollo/ast/NodeContainer;)Lcom/apollographql/apollo/ast/GQLNode;
241245
public final fun getArguments ()Ljava/util/List;
242246
public fun getChildren ()Ljava/util/List;
243247
public fun getDescription ()Ljava/lang/String;
248+
public fun getDirectives ()Ljava/util/List;
244249
public final fun getLocations ()Ljava/util/List;
245250
public fun getName ()Ljava/lang/String;
246251
public final fun getRepeatable ()Z
@@ -253,8 +258,22 @@ public final class com/apollographql/apollo/ast/GQLDirectiveDefinition$Companion
253258
public final fun getBuiltInDirectives ()Ljava/util/Set;
254259
}
255260

261+
public final class com/apollographql/apollo/ast/GQLDirectiveExtension : com/apollographql/apollo/ast/GQLDefinition, com/apollographql/apollo/ast/GQLHasDirectives, com/apollographql/apollo/ast/GQLNamed, com/apollographql/apollo/ast/GQLTypeSystemExtension {
262+
public fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/util/List;)V
263+
public synthetic fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
264+
public final fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDirectiveExtension;
265+
public static synthetic fun copy$default (Lcom/apollographql/apollo/ast/GQLDirectiveExtension;Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lcom/apollographql/apollo/ast/GQLDirectiveExtension;
266+
public fun copyWithNewChildrenInternal (Lcom/apollographql/apollo/ast/NodeContainer;)Lcom/apollographql/apollo/ast/GQLNode;
267+
public fun getChildren ()Ljava/util/List;
268+
public fun getDirectives ()Ljava/util/List;
269+
public fun getName ()Ljava/lang/String;
270+
public fun getSourceLocation ()Lcom/apollographql/apollo/ast/SourceLocation;
271+
public fun writeInternal (Lcom/apollographql/apollo/ast/SDLWriter;)V
272+
}
273+
256274
public final class com/apollographql/apollo/ast/GQLDirectiveLocation : java/lang/Enum {
257275
public static final field ARGUMENT_DEFINITION Lcom/apollographql/apollo/ast/GQLDirectiveLocation;
276+
public static final field DIRECTIVE_DEFINITION Lcom/apollographql/apollo/ast/GQLDirectiveLocation;
258277
public static final field ENUM Lcom/apollographql/apollo/ast/GQLDirectiveLocation;
259278
public static final field ENUM_VALUE Lcom/apollographql/apollo/ast/GQLDirectiveLocation;
260279
public static final field FIELD Lcom/apollographql/apollo/ast/GQLDirectiveLocation;

libraries/apollo-ast/api/apollo-ast.klib.api

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final enum class com.apollographql.apollo.ast/CatchTo : kotlin/Enum<com.apollogr
2020

2121
final enum class com.apollographql.apollo.ast/GQLDirectiveLocation : kotlin/Enum<com.apollographql.apollo.ast/GQLDirectiveLocation> { // com.apollographql.apollo.ast/GQLDirectiveLocation|null[0]
2222
enum entry ARGUMENT_DEFINITION // com.apollographql.apollo.ast/GQLDirectiveLocation.ARGUMENT_DEFINITION|null[0]
23+
enum entry DIRECTIVE_DEFINITION // com.apollographql.apollo.ast/GQLDirectiveLocation.DIRECTIVE_DEFINITION|null[0]
2324
enum entry ENUM // com.apollographql.apollo.ast/GQLDirectiveLocation.ENUM|null[0]
2425
enum entry ENUM_VALUE // com.apollographql.apollo.ast/GQLDirectiveLocation.ENUM_VALUE|null[0]
2526
enum entry FIELD // com.apollographql.apollo.ast/GQLDirectiveLocation.FIELD|null[0]
@@ -362,15 +363,18 @@ final class com.apollographql.apollo.ast/GQLDirectiveCoordinate : com.apollograp
362363
final fun writeInternal(com.apollographql.apollo.ast/SDLWriter) // com.apollographql.apollo.ast/GQLDirectiveCoordinate.writeInternal|writeInternal(com.apollographql.apollo.ast.SDLWriter){}[0]
363364
}
364365

365-
final class com.apollographql.apollo.ast/GQLDirectiveDefinition : com.apollographql.apollo.ast/GQLDefinition, com.apollographql.apollo.ast/GQLDescribed, com.apollographql.apollo.ast/GQLNamed { // com.apollographql.apollo.ast/GQLDirectiveDefinition|null[0]
366+
final class com.apollographql.apollo.ast/GQLDirectiveDefinition : com.apollographql.apollo.ast/GQLDefinition, com.apollographql.apollo.ast/GQLDescribed, com.apollographql.apollo.ast/GQLHasDirectives, com.apollographql.apollo.ast/GQLNamed { // com.apollographql.apollo.ast/GQLDirectiveDefinition|null[0]
366367
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String?, kotlin/String, kotlin.collections/List<com.apollographql.apollo.ast/GQLInputValueDefinition>, kotlin/Boolean, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirectiveLocation>) // com.apollographql.apollo.ast/GQLDirectiveDefinition.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLInputValueDefinition>;kotlin.Boolean;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirectiveLocation>){}[0]
368+
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String?, kotlin/String, kotlin.collections/List<com.apollographql.apollo.ast/GQLInputValueDefinition>, kotlin/Boolean, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirectiveLocation>, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective>) // com.apollographql.apollo.ast/GQLDirectiveDefinition.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLInputValueDefinition>;kotlin.Boolean;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirectiveLocation>;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
367369

368370
final val arguments // com.apollographql.apollo.ast/GQLDirectiveDefinition.arguments|{}arguments[0]
369371
final fun <get-arguments>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLInputValueDefinition> // com.apollographql.apollo.ast/GQLDirectiveDefinition.arguments.<get-arguments>|<get-arguments>(){}[0]
370372
final val children // com.apollographql.apollo.ast/GQLDirectiveDefinition.children|{}children[0]
371373
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLNode> // com.apollographql.apollo.ast/GQLDirectiveDefinition.children.<get-children>|<get-children>(){}[0]
372374
final val description // com.apollographql.apollo.ast/GQLDirectiveDefinition.description|{}description[0]
373375
final fun <get-description>(): kotlin/String? // com.apollographql.apollo.ast/GQLDirectiveDefinition.description.<get-description>|<get-description>(){}[0]
376+
final val directives // com.apollographql.apollo.ast/GQLDirectiveDefinition.directives|{}directives[0]
377+
final fun <get-directives>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> // com.apollographql.apollo.ast/GQLDirectiveDefinition.directives.<get-directives>|<get-directives>(){}[0]
374378
final val locations // com.apollographql.apollo.ast/GQLDirectiveDefinition.locations|{}locations[0]
375379
final fun <get-locations>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDirectiveLocation> // com.apollographql.apollo.ast/GQLDirectiveDefinition.locations.<get-locations>|<get-locations>(){}[0]
376380
final val name // com.apollographql.apollo.ast/GQLDirectiveDefinition.name|{}name[0]
@@ -381,6 +385,7 @@ final class com.apollographql.apollo.ast/GQLDirectiveDefinition : com.apollograp
381385
final fun <get-sourceLocation>(): com.apollographql.apollo.ast/SourceLocation? // com.apollographql.apollo.ast/GQLDirectiveDefinition.sourceLocation.<get-sourceLocation>|<get-sourceLocation>(){}[0]
382386

383387
final fun copy(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String? = ..., kotlin/String = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLInputValueDefinition> = ..., kotlin/Boolean = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirectiveLocation> = ...): com.apollographql.apollo.ast/GQLDirectiveDefinition // com.apollographql.apollo.ast/GQLDirectiveDefinition.copy|copy(com.apollographql.apollo.ast.SourceLocation?;kotlin.String?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLInputValueDefinition>;kotlin.Boolean;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirectiveLocation>){}[0]
388+
final fun copy(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String? = ..., kotlin/String = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLInputValueDefinition> = ..., kotlin/Boolean = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirectiveLocation> = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> = ...): com.apollographql.apollo.ast/GQLDirectiveDefinition // com.apollographql.apollo.ast/GQLDirectiveDefinition.copy|copy(com.apollographql.apollo.ast.SourceLocation?;kotlin.String?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLInputValueDefinition>;kotlin.Boolean;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirectiveLocation>;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
384389
final fun copyWithNewChildrenInternal(com.apollographql.apollo.ast/NodeContainer): com.apollographql.apollo.ast/GQLNode // com.apollographql.apollo.ast/GQLDirectiveDefinition.copyWithNewChildrenInternal|copyWithNewChildrenInternal(com.apollographql.apollo.ast.NodeContainer){}[0]
385390
final fun isBuiltIn(): kotlin/Boolean // com.apollographql.apollo.ast/GQLDirectiveDefinition.isBuiltIn|isBuiltIn(){}[0]
386391
final fun writeInternal(com.apollographql.apollo.ast/SDLWriter) // com.apollographql.apollo.ast/GQLDirectiveDefinition.writeInternal|writeInternal(com.apollographql.apollo.ast.SDLWriter){}[0]
@@ -391,6 +396,23 @@ final class com.apollographql.apollo.ast/GQLDirectiveDefinition : com.apollograp
391396
}
392397
}
393398

399+
final class com.apollographql.apollo.ast/GQLDirectiveExtension : com.apollographql.apollo.ast/GQLDefinition, com.apollographql.apollo.ast/GQLHasDirectives, com.apollographql.apollo.ast/GQLNamed, com.apollographql.apollo.ast/GQLTypeSystemExtension { // com.apollographql.apollo.ast/GQLDirectiveExtension|null[0]
400+
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective>) // com.apollographql.apollo.ast/GQLDirectiveExtension.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
401+
402+
final val children // com.apollographql.apollo.ast/GQLDirectiveExtension.children|{}children[0]
403+
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLNode> // com.apollographql.apollo.ast/GQLDirectiveExtension.children.<get-children>|<get-children>(){}[0]
404+
final val directives // com.apollographql.apollo.ast/GQLDirectiveExtension.directives|{}directives[0]
405+
final fun <get-directives>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> // com.apollographql.apollo.ast/GQLDirectiveExtension.directives.<get-directives>|<get-directives>(){}[0]
406+
final val name // com.apollographql.apollo.ast/GQLDirectiveExtension.name|{}name[0]
407+
final fun <get-name>(): kotlin/String // com.apollographql.apollo.ast/GQLDirectiveExtension.name.<get-name>|<get-name>(){}[0]
408+
final val sourceLocation // com.apollographql.apollo.ast/GQLDirectiveExtension.sourceLocation|{}sourceLocation[0]
409+
final fun <get-sourceLocation>(): com.apollographql.apollo.ast/SourceLocation? // com.apollographql.apollo.ast/GQLDirectiveExtension.sourceLocation.<get-sourceLocation>|<get-sourceLocation>(){}[0]
410+
411+
final fun copy(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> = ...): com.apollographql.apollo.ast/GQLDirectiveExtension // com.apollographql.apollo.ast/GQLDirectiveExtension.copy|copy(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
412+
final fun copyWithNewChildrenInternal(com.apollographql.apollo.ast/NodeContainer): com.apollographql.apollo.ast/GQLNode // com.apollographql.apollo.ast/GQLDirectiveExtension.copyWithNewChildrenInternal|copyWithNewChildrenInternal(com.apollographql.apollo.ast.NodeContainer){}[0]
413+
final fun writeInternal(com.apollographql.apollo.ast/SDLWriter) // com.apollographql.apollo.ast/GQLDirectiveExtension.writeInternal|writeInternal(com.apollographql.apollo.ast.SDLWriter){}[0]
414+
}
415+
394416
final class com.apollographql.apollo.ast/GQLDocument : com.apollographql.apollo.ast/GQLNode { // com.apollographql.apollo.ast/GQLDocument|null[0]
395417
constructor <init>(kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition>, com.apollographql.apollo.ast/SourceLocation?) // com.apollographql.apollo.ast/GQLDocument.<init>|<init>(kotlin.collections.List<com.apollographql.apollo.ast.GQLDefinition>;com.apollographql.apollo.ast.SourceLocation?){}[0]
396418

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/gql.kt

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,23 +678,46 @@ class GQLDirectiveDefinition(
678678
val arguments: List<GQLInputValueDefinition>,
679679
val repeatable: Boolean,
680680
val locations: List<GQLDirectiveLocation>,
681-
) : GQLDefinition, GQLDescribed, GQLNamed {
681+
override val directives: List<GQLDirective>,
682+
) : GQLDefinition, GQLDescribed, GQLNamed, GQLHasDirectives {
683+
684+
@Deprecated("Use the other constructor")
685+
@ApolloDeprecatedSince(ApolloDeprecatedSince.Version.v5_0_0)
686+
constructor(
687+
sourceLocation: SourceLocation? = null,
688+
description: String?,
689+
name: String,
690+
arguments: List<GQLInputValueDefinition>,
691+
repeatable: Boolean,
692+
locations: List<GQLDirectiveLocation>,
693+
) : this(
694+
sourceLocation = sourceLocation,
695+
description = description,
696+
name = name,
697+
arguments = arguments,
698+
repeatable = repeatable,
699+
locations = locations,
700+
directives = emptyList(),
701+
)
702+
682703
override val children: List<GQLNode> = arguments
683704

684705
override fun writeInternal(writer: SDLWriter) {
685706
with(writer) {
686707
writeDescription(description)
687708
write("directive @$name")
688709
if (arguments.isNotEmpty()) {
689-
write(" ")
690710
arguments.join(writer, prefix = "(", separator = ", ", postfix = ")") {
691711
it.write(writer, true)
692712
}
693713
}
714+
if (directives.isNotEmpty()) {
715+
directives.join(writer, prefix = " ")
716+
}
694717
if (repeatable) {
695718
write(" repeatable")
696719
}
697-
write(" on ${locations.joinToString("|")}")
720+
write(" on ${locations.joinToString(" | ")}")
698721
write("\n")
699722
}
700723
}
@@ -706,13 +729,34 @@ class GQLDirectiveDefinition(
706729
arguments: List<GQLInputValueDefinition> = this.arguments,
707730
repeatable: Boolean = this.repeatable,
708731
locations: List<GQLDirectiveLocation> = this.locations,
732+
directives: List<GQLDirective> = this.directives,
709733
): GQLDirectiveDefinition = GQLDirectiveDefinition(
710734
sourceLocation = sourceLocation,
711735
description = description,
712736
name = name,
713737
arguments = arguments,
714738
repeatable = repeatable,
715739
locations = locations,
740+
directives = directives,
741+
)
742+
743+
@Deprecated("Kept for binary compatibility", level = DeprecationLevel.HIDDEN)
744+
@ApolloDeprecatedSince(ApolloDeprecatedSince.Version.v5_0_0)
745+
fun copy(
746+
sourceLocation: SourceLocation? = this.sourceLocation,
747+
description: String? = this.description,
748+
name: String = this.name,
749+
arguments: List<GQLInputValueDefinition> = this.arguments,
750+
repeatable: Boolean = this.repeatable,
751+
locations: List<GQLDirectiveLocation> = this.locations,
752+
): GQLDirectiveDefinition = GQLDirectiveDefinition(
753+
sourceLocation = sourceLocation,
754+
description = description,
755+
name = name,
756+
arguments = arguments,
757+
repeatable = repeatable,
758+
locations = locations,
759+
directives = this.directives,
716760
)
717761

718762
override fun copyWithNewChildrenInternal(container: NodeContainer): GQLNode {
@@ -1055,6 +1099,40 @@ class GQLUnionTypeExtension(
10551099
}
10561100
}
10571101

1102+
class GQLDirectiveExtension(
1103+
override val sourceLocation: SourceLocation? = null,
1104+
override val name: String,
1105+
override val directives: List<GQLDirective>,
1106+
) : GQLDefinition, GQLTypeSystemExtension, GQLNamed, GQLHasDirectives {
1107+
1108+
override val children: List<GQLNode> = directives
1109+
1110+
override fun writeInternal(writer: SDLWriter) {
1111+
with(writer) {
1112+
write("extend directive @$name")
1113+
if (directives.isNotEmpty()) {
1114+
directives.join(writer, prefix = " ")
1115+
}
1116+
}
1117+
}
1118+
1119+
fun copy(
1120+
sourceLocation: SourceLocation? = this.sourceLocation,
1121+
name: String = this.name,
1122+
directives: List<GQLDirective> = this.directives,
1123+
): GQLDirectiveExtension = GQLDirectiveExtension(
1124+
sourceLocation = sourceLocation,
1125+
name = name,
1126+
directives = directives,
1127+
)
1128+
1129+
override fun copyWithNewChildrenInternal(container: NodeContainer): GQLNode {
1130+
return copy(
1131+
directives = container.take()
1132+
)
1133+
}
1134+
}
1135+
10581136
class GQLEnumValueDefinition(
10591137
override val sourceLocation: SourceLocation? = null,
10601138
override val description: String?,
@@ -2059,6 +2137,7 @@ enum class GQLDirectiveLocation {
20592137
ENUM_VALUE,
20602138
INPUT_OBJECT,
20612139
INPUT_FIELD_DEFINITION,
2140+
DIRECTIVE_DEFINITION,
20622141
}
20632142

20642143
sealed interface GQLSchemaCoordinate

0 commit comments

Comments
 (0)