Skip to content

Commit fa51285

Browse files
authored
fix detection of used arguments (apollographql#5837)
1 parent dfd7492 commit fa51285

File tree

58 files changed

+2326
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2326
-7
lines changed

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/InterfaceBuilder.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ internal class InterfaceBuilder(
2121

2222
override fun prepare() {
2323
context.resolver.registerSchemaType(iface.name, ClassName.get(packageName, simpleName))
24+
for (fieldDefinition in iface.fieldDefinitions) {
25+
fieldDefinition.argumentDefinitions.forEach { argumentDefinition ->
26+
context.resolver.registerArgumentDefinition(argumentDefinition.id, ClassName.get(packageName, simpleName))
27+
}
28+
}
2429
}
2530

2631
override fun build(): CodegenJavaFile {

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/InterfaceBuilder.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ internal class InterfaceBuilder(
3535
context.resolver.registerSchemaType(iface.name, ClassName(packageName, simpleName))
3636
context.resolver.registerMapType(iface.name, ClassName(packageName, mapName))
3737
context.resolver.registerBuilderType(iface.name, ClassName(packageName, builderName))
38+
for (fieldDefinition in iface.fieldDefinitions) {
39+
fieldDefinition.argumentDefinitions.forEach { argumentDefinition ->
40+
context.resolver.registerArgumentDefinition(argumentDefinition.id, ClassName(packageName, simpleName))
41+
}
42+
}
3843
}
3944

4045
override fun build(): CgFile {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,10 @@ internal class IrOperationsBuilder(
602602
usedCoordinates.putType(first.type.rawType().name)
603603

604604
// Track argument usage
605-
for (usedArgument in first.usedArguments) {
606-
usedCoordinates.putArgument(first.parentType, first.name, usedArgument)
605+
fields.map { it.parentType }.distinct().forEach { parentType ->
606+
for (usedArgument in first.usedArguments) {
607+
usedCoordinates.putArgument(parentType, first.name, usedArgument)
608+
}
607609
}
608610

609611
val irType = first

libraries/apollo-compiler/src/test/graphql/com/example/measurements

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// If you updated the codegen and test fixtures, you should commit this file too.
33

44
Test: Total LOC:
5-
aggregate-all 202649
6-
aggregate-kotlin-responseBased 65139
7-
aggregate-kotlin-operationBased 41775
5+
aggregate-all 204924
6+
aggregate-kotlin-responseBased 65822
7+
aggregate-kotlin-operationBased 42426
88
aggregate-kotlin-compat 0
9-
aggregate-java-operationBased 95735
9+
aggregate-java-operationBased 96676
1010

1111
java-operationBased-fragments_with_defer_and_include_directives 5600
1212
kotlin-operationBased-fragments_with_defer_and_include_directives 3488
@@ -60,7 +60,7 @@ java-operationBased-root_query_inline_fragment
6060
kotlin-operationBased-fragment_spread_with_include_directive 1121
6161
kotlin-operationBased-unique_type_name 1109
6262
kotlin-responseBased-fragments_with_type_condition 1102
63-
kotlin-responseBased-nested_conditional_inline 1082
63+
kotlin-responseBased-nested_conditional_inline 1085
6464
java-operationBased-java_primitive_types 1077
6565
kotlin-responseBased-multiple_fragments 1074
6666
kotlin-responseBased-named_fragment_with_variables 1067
@@ -80,6 +80,7 @@ java-operationBased-deprecated_merged_field
8080
kotlin-operationBased-nested_conditional_inline 948
8181
java-operationBased-input_object_oneof 943
8282
java-operationBased-hero_details 941
83+
java-operationBased-used_arguments 941
8384
java-operationBased-not_all_combinations_are_needed 938
8485
java-operationBased-simple_inline_fragment 919
8586
kotlin-responseBased-mutation_create_review_semantic_naming 918
@@ -127,6 +128,7 @@ kotlin-responseBased-input_object_variable_and_argument_with_generated_methods
127128
java-operationBased-monomorphic 689
128129
kotlin-operationBased-operationbased2_ex8 685
129130
java-operationBased-interface_always_nested 683
131+
kotlin-responseBased-used_arguments 680
130132
kotlin-responseBased-union_fragment 678
131133
kotlin-responseBased-java_android_annotations 674
132134
kotlin-responseBased-java_apollo_optionals 674
@@ -143,6 +145,7 @@ java-operationBased-deprecation
143145
kotlin-responseBased-fragment_with_multiple_fieldsets 659
144146
kotlin-responseBased-test_inline 657
145147
kotlin-responseBased-named_fragment_without_implementation 651
148+
kotlin-operationBased-used_arguments 651
146149
kotlin-operationBased-union_fragment 650
147150
kotlin-operationBased-decapitalized_fields 647
148151
kotlin-responseBased-hero_details 647

libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/used-coordinates.json.expected

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fragment ADetails on A {
2+
field(arg: 42)
3+
}
4+
5+
query GetA {
6+
a {
7+
... on B {
8+
field(arg: 42)
9+
}
10+
... on C {
11+
field(arg: 42)
12+
}
13+
}
14+
}

libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used-coordinates.json.expected

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)