Skip to content

Commit 39bcab0

Browse files
authored
Support descriptions on variable definitions (#6699)
* Support descriptions on variable definitions * Remove debug leftovers
1 parent ccfe1d8 commit 39bcab0

File tree

13 files changed

+89
-15
lines changed

13 files changed

+89
-15
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,19 @@ public final class com/apollographql/apollo/ast/GQLUnionTypeExtension : com/apol
851851
public abstract class com/apollographql/apollo/ast/GQLValue : com/apollographql/apollo/ast/GQLNode {
852852
}
853853

854-
public final class com/apollographql/apollo/ast/GQLVariableDefinition : com/apollographql/apollo/ast/GQLHasDirectives, com/apollographql/apollo/ast/GQLNamed, com/apollographql/apollo/ast/GQLNode {
854+
public final class com/apollographql/apollo/ast/GQLVariableDefinition : com/apollographql/apollo/ast/GQLDescribed, com/apollographql/apollo/ast/GQLHasDirectives, com/apollographql/apollo/ast/GQLNamed, com/apollographql/apollo/ast/GQLNode {
855855
public fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;)V
856856
public synthetic fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
857+
public fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;Ljava/lang/String;)V
858+
public synthetic fun <init> (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
857859
public final fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLVariableDefinition;
860+
public final fun copy (Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;Ljava/lang/String;)Lcom/apollographql/apollo/ast/GQLVariableDefinition;
858861
public static synthetic fun copy$default (Lcom/apollographql/apollo/ast/GQLVariableDefinition;Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;ILjava/lang/Object;)Lcom/apollographql/apollo/ast/GQLVariableDefinition;
862+
public static synthetic fun copy$default (Lcom/apollographql/apollo/ast/GQLVariableDefinition;Lcom/apollographql/apollo/ast/SourceLocation;Ljava/lang/String;Lcom/apollographql/apollo/ast/GQLType;Lcom/apollographql/apollo/ast/GQLValue;Ljava/util/List;Ljava/lang/String;ILjava/lang/Object;)Lcom/apollographql/apollo/ast/GQLVariableDefinition;
859863
public fun copyWithNewChildrenInternal (Lcom/apollographql/apollo/ast/NodeContainer;)Lcom/apollographql/apollo/ast/GQLNode;
860864
public fun getChildren ()Ljava/util/List;
861865
public final fun getDefaultValue ()Lcom/apollographql/apollo/ast/GQLValue;
866+
public fun getDescription ()Ljava/lang/String;
862867
public fun getDirectives ()Ljava/util/List;
863868
public fun getName ()Ljava/lang/String;
864869
public fun getSourceLocation ()Lcom/apollographql/apollo/ast/SourceLocation;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,13 +1098,16 @@ final class com.apollographql.apollo.ast/GQLUnionTypeExtension : com.apollograph
10981098
final fun writeInternal(com.apollographql.apollo.ast/SDLWriter) // com.apollographql.apollo.ast/GQLUnionTypeExtension.writeInternal|writeInternal(com.apollographql.apollo.ast.SDLWriter){}[0]
10991099
}
11001100

1101-
final class com.apollographql.apollo.ast/GQLVariableDefinition : com.apollographql.apollo.ast/GQLHasDirectives, com.apollographql.apollo.ast/GQLNamed, com.apollographql.apollo.ast/GQLNode { // com.apollographql.apollo.ast/GQLVariableDefinition|null[0]
1101+
final class com.apollographql.apollo.ast/GQLVariableDefinition : com.apollographql.apollo.ast/GQLDescribed, com.apollographql.apollo.ast/GQLHasDirectives, com.apollographql.apollo.ast/GQLNamed, com.apollographql.apollo.ast/GQLNode { // com.apollographql.apollo.ast/GQLVariableDefinition|null[0]
11021102
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String, com.apollographql.apollo.ast/GQLType, com.apollographql.apollo.ast/GQLValue?, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective>) // com.apollographql.apollo.ast/GQLVariableDefinition.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;com.apollographql.apollo.ast.GQLType;com.apollographql.apollo.ast.GQLValue?;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
1103+
constructor <init>(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String, com.apollographql.apollo.ast/GQLType, com.apollographql.apollo.ast/GQLValue?, kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective>, kotlin/String?) // com.apollographql.apollo.ast/GQLVariableDefinition.<init>|<init>(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;com.apollographql.apollo.ast.GQLType;com.apollographql.apollo.ast.GQLValue?;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>;kotlin.String?){}[0]
11031104

11041105
final val children // com.apollographql.apollo.ast/GQLVariableDefinition.children|{}children[0]
11051106
final fun <get-children>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLNode> // com.apollographql.apollo.ast/GQLVariableDefinition.children.<get-children>|<get-children>(){}[0]
11061107
final val defaultValue // com.apollographql.apollo.ast/GQLVariableDefinition.defaultValue|{}defaultValue[0]
11071108
final fun <get-defaultValue>(): com.apollographql.apollo.ast/GQLValue? // com.apollographql.apollo.ast/GQLVariableDefinition.defaultValue.<get-defaultValue>|<get-defaultValue>(){}[0]
1109+
final val description // com.apollographql.apollo.ast/GQLVariableDefinition.description|{}description[0]
1110+
final fun <get-description>(): kotlin/String? // com.apollographql.apollo.ast/GQLVariableDefinition.description.<get-description>|<get-description>(){}[0]
11081111
final val directives // com.apollographql.apollo.ast/GQLVariableDefinition.directives|{}directives[0]
11091112
final fun <get-directives>(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> // com.apollographql.apollo.ast/GQLVariableDefinition.directives.<get-directives>|<get-directives>(){}[0]
11101113
final val name // com.apollographql.apollo.ast/GQLVariableDefinition.name|{}name[0]
@@ -1115,6 +1118,7 @@ final class com.apollographql.apollo.ast/GQLVariableDefinition : com.apollograph
11151118
final fun <get-type>(): com.apollographql.apollo.ast/GQLType // com.apollographql.apollo.ast/GQLVariableDefinition.type.<get-type>|<get-type>(){}[0]
11161119

11171120
final fun copy(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String = ..., com.apollographql.apollo.ast/GQLType = ..., com.apollographql.apollo.ast/GQLValue? = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> = ...): com.apollographql.apollo.ast/GQLVariableDefinition // com.apollographql.apollo.ast/GQLVariableDefinition.copy|copy(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;com.apollographql.apollo.ast.GQLType;com.apollographql.apollo.ast.GQLValue?;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>){}[0]
1121+
final fun copy(com.apollographql.apollo.ast/SourceLocation? = ..., kotlin/String = ..., com.apollographql.apollo.ast/GQLType = ..., com.apollographql.apollo.ast/GQLValue? = ..., kotlin.collections/List<com.apollographql.apollo.ast/GQLDirective> = ..., kotlin/String? = ...): com.apollographql.apollo.ast/GQLVariableDefinition // com.apollographql.apollo.ast/GQLVariableDefinition.copy|copy(com.apollographql.apollo.ast.SourceLocation?;kotlin.String;com.apollographql.apollo.ast.GQLType;com.apollographql.apollo.ast.GQLValue?;kotlin.collections.List<com.apollographql.apollo.ast.GQLDirective>;kotlin.String?){}[0]
11181122
final fun copyWithNewChildrenInternal(com.apollographql.apollo.ast/NodeContainer): com.apollographql.apollo.ast/GQLNode // com.apollographql.apollo.ast/GQLVariableDefinition.copyWithNewChildrenInternal|copyWithNewChildrenInternal(com.apollographql.apollo.ast.NodeContainer){}[0]
11191123
final fun writeInternal(com.apollographql.apollo.ast/SDLWriter) // com.apollographql.apollo.ast/GQLVariableDefinition.writeInternal|writeInternal(com.apollographql.apollo.ast.SDLWriter){}[0]
11201124
}

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class GQLOperationDefinition(
165165
val variableDefinitions: List<GQLVariableDefinition>,
166166
override val directives: List<GQLDirective>,
167167
val selections: List<GQLSelection>,
168-
override val description: String?, // spec extension
168+
override val description: String?,
169169
) : GQLExecutableDefinition, GQLDescribed, GQLHasDirectives {
170170
@Suppress("DEPRECATION_ERROR")
171171
@Deprecated("Use selections directly", level = DeprecationLevel.ERROR)
@@ -1234,7 +1234,23 @@ class GQLVariableDefinition(
12341234
val type: GQLType,
12351235
val defaultValue: GQLValue?,
12361236
override val directives: List<GQLDirective>,
1237-
) : GQLNode, GQLNamed, GQLHasDirectives {
1237+
override val description: String?,
1238+
) : GQLNode, GQLNamed, GQLDescribed, GQLHasDirectives {
1239+
1240+
constructor(
1241+
sourceLocation: SourceLocation? = null,
1242+
name: String,
1243+
type: GQLType,
1244+
defaultValue: GQLValue?,
1245+
directives: List<GQLDirective>,
1246+
) : this(
1247+
sourceLocation = sourceLocation,
1248+
name = name,
1249+
type = type,
1250+
defaultValue = defaultValue,
1251+
directives = directives,
1252+
description = null
1253+
)
12381254

12391255
override val children = listOfNotNull(defaultValue) + directives
12401256

@@ -1258,13 +1274,32 @@ class GQLVariableDefinition(
12581274
type: GQLType = this.type,
12591275
defaultValue: GQLValue? = this.defaultValue,
12601276
directives: List<GQLDirective> = this.directives,
1277+
description: String? = this.description,
12611278
): GQLVariableDefinition {
12621279
return GQLVariableDefinition(
12631280
sourceLocation = sourceLocation,
12641281
name = name,
12651282
type = type,
12661283
defaultValue = defaultValue,
12671284
directives = directives,
1285+
description = description,
1286+
)
1287+
}
1288+
1289+
fun copy(
1290+
sourceLocation: SourceLocation? = this.sourceLocation,
1291+
name: String = this.name,
1292+
type: GQLType = this.type,
1293+
defaultValue: GQLValue? = this.defaultValue,
1294+
directives: List<GQLDirective> = this.directives,
1295+
): GQLVariableDefinition {
1296+
return copy(
1297+
sourceLocation = sourceLocation,
1298+
name = name,
1299+
type = type,
1300+
defaultValue = defaultValue,
1301+
directives = directives,
1302+
description = null,
12681303
)
12691304
}
12701305

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import com.apollographql.apollo.ast.GQLVariableDefinition
5555
import com.apollographql.apollo.ast.GQLVariableValue
5656
import com.apollographql.apollo.ast.ParserOptions
5757
import com.apollographql.apollo.ast.SourceLocation
58-
import kotlin.math.exp
5958

6059
internal class Parser(
6160
src: String,
@@ -358,6 +357,7 @@ internal class Parser(
358357
}
359358

360359
private fun parseVariableDefinition(): GQLVariableDefinition {
360+
val description = expectOptionalToken<Token.String>()?.value
361361
val start = token
362362
expectToken<Token.Dollar>()
363363
val name = parseName()
@@ -374,7 +374,8 @@ internal class Parser(
374374
name = name,
375375
type = type,
376376
defaultValue = defaultValue,
377-
directives = directives
377+
directives = directives,
378+
description = description,
378379
)
379380
}
380381

libraries/apollo-compiler/api/apollo-compiler.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,14 +1919,16 @@ public final class com/apollographql/apollo/compiler/ir/IrValue$Companion {
19191919

19201920
public final class com/apollographql/apollo/compiler/ir/IrVariable {
19211921
public static final field Companion Lcom/apollographql/apollo/compiler/ir/IrVariable$Companion;
1922-
public fun <init> (Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Lcom/apollographql/apollo/compiler/ir/IrValue;)V
1922+
public fun <init> (Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrValue;)V
19231923
public final fun component1 ()Ljava/lang/String;
19241924
public final fun component2 ()Lcom/apollographql/apollo/compiler/ir/IrType;
1925-
public final fun component3 ()Lcom/apollographql/apollo/compiler/ir/IrValue;
1926-
public final fun copy (Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Lcom/apollographql/apollo/compiler/ir/IrValue;)Lcom/apollographql/apollo/compiler/ir/IrVariable;
1927-
public static synthetic fun copy$default (Lcom/apollographql/apollo/compiler/ir/IrVariable;Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Lcom/apollographql/apollo/compiler/ir/IrValue;ILjava/lang/Object;)Lcom/apollographql/apollo/compiler/ir/IrVariable;
1925+
public final fun component3 ()Ljava/lang/String;
1926+
public final fun component4 ()Lcom/apollographql/apollo/compiler/ir/IrValue;
1927+
public final fun copy (Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrValue;)Lcom/apollographql/apollo/compiler/ir/IrVariable;
1928+
public static synthetic fun copy$default (Lcom/apollographql/apollo/compiler/ir/IrVariable;Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrType;Ljava/lang/String;Lcom/apollographql/apollo/compiler/ir/IrValue;ILjava/lang/Object;)Lcom/apollographql/apollo/compiler/ir/IrVariable;
19281929
public fun equals (Ljava/lang/Object;)Z
19291930
public final fun getDefaultValue ()Lcom/apollographql/apollo/compiler/ir/IrValue;
1931+
public final fun getDescription ()Ljava/lang/String;
19301932
public final fun getName ()Ljava/lang/String;
19311933
public final fun getType ()Lcom/apollographql/apollo/compiler/ir/IrType;
19321934
public fun hashCode ()I

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/java/helpers/NamedType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal fun NamedType.toParameterSpec(context: JavaContext): ParameterSpec {
2828
context.layout.javaPropertyName(graphQlName),
2929
)
3030
.addAnnotations(irType.annotations)
31+
3132
.build()
3233
}
3334

@@ -42,7 +43,7 @@ internal fun IrInputField.toNamedType() = NamedType(
4243
internal fun IrVariable.toNamedType() = NamedType(
4344
graphQlName = name,
4445
type = type,
45-
description = null,
46+
description = description,
4647
deprecationReason = null,
4748
)
4849

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/java/operations/OperationBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ internal class OperationBuilder(
272272
.map {
273273
val irType = context.resolver.resolveIrType(it.type)
274274
FieldSpec.builder(irType.withoutAnnotations(), context.layout.javaPropertyName(it.name))
275+
.maybeAddDescription(it.description)
275276
.addAnnotations(irType.annotations)
276277
.build()
277278
}

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/helpers/NamedType.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal fun IrInputField.toNamedType() = NamedType(
101101
internal fun IrVariable.toNamedType() = NamedType(
102102
graphQlName = name,
103103
type = type,
104-
description = null,
104+
description = description,
105105
deprecationReason = null,
106106
optInFeature = null,
107107
)
@@ -141,4 +141,4 @@ private fun List<NamedType>.toBuildFunSpec(context: KotlinContext, returnedClass
141141
.build()
142142
)
143143
.build()
144-
}
144+
}

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/IrOperations.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,11 @@ data class IrModelGroup(
348348
data class IrVariable(
349349
val name: String,
350350
val type: IrType,
351+
val description: String?,
351352
/**
352353
* Used in `Operation.serializeVariables`
353354
*/
354-
val defaultValue: IrValue?
355+
val defaultValue: IrValue?,
355356
)
356357

357358
private val json = Json { classDiscriminator = "#class" }

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/IrOperationsBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ internal class IrOperationsBuilder(
374374
return IrVariable(
375375
name = name,
376376
type = irType,
377+
description = null,
377378
defaultValue = null
378379
)
379380
}
@@ -412,6 +413,7 @@ internal class IrOperationsBuilder(
412413
return IrVariable(
413414
name = name,
414415
type = irType,
416+
description = description,
415417
defaultValue = defaultValue?.toIrValue()
416418
)
417419
}

0 commit comments

Comments
 (0)