From fa51285b0f51b5fab521f8c939262726e4d4b3b5 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 19 Apr 2024 22:01:01 +0200 Subject: [PATCH] fix detection of used arguments (#5837) --- .../codegen/java/schema/InterfaceBuilder.kt | 5 + .../codegen/kotlin/schema/InterfaceBuilder.kt | 5 + .../compiler/ir/IrOperationsBuilder.kt | 6 +- .../src/test/graphql/com/example/measurements | 13 +- .../used-coordinates.json.expected | 3 + .../used_arguments/TestOperation.graphql | 14 + .../used-coordinates.json.expected | 25 ++ .../used_arguments/GetA.java.expected | 350 ++++++++++++++++++ .../GetA_ResponseAdapter.java.expected | 175 +++++++++ .../fragment/ADetails.java.expected | 60 +++ .../fragment/ADetailsImpl.java.expected | 87 +++++ ...ADetailsImpl_ResponseAdapter.java.expected | 51 +++ .../ADetailsSelections.java.expected | 20 + .../selections/GetASelections.java.expected | 39 ++ .../used_arguments/type/A.java.expected | 15 + .../used_arguments/type/B.java.expected | 16 + .../used_arguments/type/C.java.expected | 16 + .../type/GraphQLBoolean.java.expected | 15 + .../type/GraphQLFloat.java.expected | 15 + .../type/GraphQLID.java.expected | 15 + .../type/GraphQLInt.java.expected | 15 + .../type/GraphQLString.java.expected | 15 + .../used_arguments/type/Query.java.expected | 12 + .../used-coordinates.json.expected | 25 ++ .../used_arguments/GetA.kt.expected | 106 ++++++ .../adapter/GetA_ResponseAdapter.kt.expected | 169 +++++++++ .../fragment/ADetails.kt.expected | 13 + .../fragment/ADetailsImpl.kt.expected | 43 +++ .../ADetailsImpl_ResponseAdapter.kt.expected | 46 +++ .../selections/ADetailsSelections.kt.expected | 25 ++ .../selections/GetASelections.kt.expected | 65 ++++ .../used_arguments/type/A.kt.expected | 18 + .../used_arguments/type/B.kt.expected | 18 + .../used_arguments/type/C.kt.expected | 18 + .../type/GraphQLBoolean.kt.expected | 17 + .../type/GraphQLFloat.kt.expected | 18 + .../used_arguments/type/GraphQLID.kt.expected | 20 + .../type/GraphQLInt.kt.expected | 18 + .../type/GraphQLString.kt.expected | 18 + .../used_arguments/type/Query.kt.expected | 14 + .../used-coordinates.json.expected | 25 ++ .../used_arguments/GetA.kt.expected | 113 ++++++ .../adapter/GetA_ResponseAdapter.kt.expected | 188 ++++++++++ .../fragment/ADetails.kt.expected | 12 + .../fragment/ADetailsImpl.kt.expected | 47 +++ .../ADetailsImpl_ResponseAdapter.kt.expected | 46 +++ .../selections/ADetailsSelections.kt.expected | 25 ++ .../selections/GetASelections.kt.expected | 65 ++++ .../used_arguments/type/A.kt.expected | 18 + .../used_arguments/type/B.kt.expected | 18 + .../used_arguments/type/C.kt.expected | 18 + .../type/GraphQLBoolean.kt.expected | 17 + .../type/GraphQLFloat.kt.expected | 18 + .../used_arguments/type/GraphQLID.kt.expected | 20 + .../type/GraphQLInt.kt.expected | 18 + .../type/GraphQLString.kt.expected | 18 + .../used_arguments/type/Query.kt.expected | 14 + .../example/used_arguments/schema.graphqls | 15 + 58 files changed, 2326 insertions(+), 7 deletions(-) create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/TestOperation.graphql create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used-coordinates.json.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/GetA.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/adapter/GetA_ResponseAdapter.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetails.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/selections/ADetailsSelections.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/selections/GetASelections.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/A.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/B.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/C.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLBoolean.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLFloat.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLID.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLInt.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLString.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/Query.java.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used-coordinates.json.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/GetA.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetails.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/selections/GetASelections.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/A.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/B.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/C.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLBoolean.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLFloat.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLID.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLInt.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLString.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/Query.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used-coordinates.json.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/GetA.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetails.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/selections/GetASelections.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/A.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/B.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/C.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLBoolean.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLFloat.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLID.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLInt.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLString.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/Query.kt.expected create mode 100644 libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/schema.graphqls diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/InterfaceBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/InterfaceBuilder.kt index e46e12aac2e..45f1f574b60 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/InterfaceBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/InterfaceBuilder.kt @@ -21,6 +21,11 @@ internal class InterfaceBuilder( override fun prepare() { context.resolver.registerSchemaType(iface.name, ClassName.get(packageName, simpleName)) + for (fieldDefinition in iface.fieldDefinitions) { + fieldDefinition.argumentDefinitions.forEach { argumentDefinition -> + context.resolver.registerArgumentDefinition(argumentDefinition.id, ClassName.get(packageName, simpleName)) + } + } } override fun build(): CodegenJavaFile { diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/InterfaceBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/InterfaceBuilder.kt index bc5f3d14f4a..7473db2bd9c 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/InterfaceBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/InterfaceBuilder.kt @@ -35,6 +35,11 @@ internal class InterfaceBuilder( context.resolver.registerSchemaType(iface.name, ClassName(packageName, simpleName)) context.resolver.registerMapType(iface.name, ClassName(packageName, mapName)) context.resolver.registerBuilderType(iface.name, ClassName(packageName, builderName)) + for (fieldDefinition in iface.fieldDefinitions) { + fieldDefinition.argumentDefinitions.forEach { argumentDefinition -> + context.resolver.registerArgumentDefinition(argumentDefinition.id, ClassName(packageName, simpleName)) + } + } } override fun build(): CgFile { diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/IrOperationsBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/IrOperationsBuilder.kt index 6c5fdc82d8a..6e875deaebb 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/IrOperationsBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/IrOperationsBuilder.kt @@ -602,8 +602,10 @@ internal class IrOperationsBuilder( usedCoordinates.putType(first.type.rawType().name) // Track argument usage - for (usedArgument in first.usedArguments) { - usedCoordinates.putArgument(first.parentType, first.name, usedArgument) + fields.map { it.parentType }.distinct().forEach { parentType -> + for (usedArgument in first.usedArguments) { + usedCoordinates.putArgument(parentType, first.name, usedArgument) + } } val irType = first diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/measurements b/libraries/apollo-compiler/src/test/graphql/com/example/measurements index 22834f7b618..662444cfe5e 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/measurements +++ b/libraries/apollo-compiler/src/test/graphql/com/example/measurements @@ -2,11 +2,11 @@ // If you updated the codegen and test fixtures, you should commit this file too. Test: Total LOC: -aggregate-all 202649 -aggregate-kotlin-responseBased 65139 -aggregate-kotlin-operationBased 41775 +aggregate-all 204924 +aggregate-kotlin-responseBased 65822 +aggregate-kotlin-operationBased 42426 aggregate-kotlin-compat 0 -aggregate-java-operationBased 95735 +aggregate-java-operationBased 96676 java-operationBased-fragments_with_defer_and_include_directives 5600 kotlin-operationBased-fragments_with_defer_and_include_directives 3488 @@ -60,7 +60,7 @@ java-operationBased-root_query_inline_fragment kotlin-operationBased-fragment_spread_with_include_directive 1121 kotlin-operationBased-unique_type_name 1109 kotlin-responseBased-fragments_with_type_condition 1102 -kotlin-responseBased-nested_conditional_inline 1082 +kotlin-responseBased-nested_conditional_inline 1085 java-operationBased-java_primitive_types 1077 kotlin-responseBased-multiple_fragments 1074 kotlin-responseBased-named_fragment_with_variables 1067 @@ -80,6 +80,7 @@ java-operationBased-deprecated_merged_field kotlin-operationBased-nested_conditional_inline 948 java-operationBased-input_object_oneof 943 java-operationBased-hero_details 941 +java-operationBased-used_arguments 941 java-operationBased-not_all_combinations_are_needed 938 java-operationBased-simple_inline_fragment 919 kotlin-responseBased-mutation_create_review_semantic_naming 918 @@ -127,6 +128,7 @@ kotlin-responseBased-input_object_variable_and_argument_with_generated_methods java-operationBased-monomorphic 689 kotlin-operationBased-operationbased2_ex8 685 java-operationBased-interface_always_nested 683 +kotlin-responseBased-used_arguments 680 kotlin-responseBased-union_fragment 678 kotlin-responseBased-java_android_annotations 674 kotlin-responseBased-java_apollo_optionals 674 @@ -143,6 +145,7 @@ java-operationBased-deprecation kotlin-responseBased-fragment_with_multiple_fieldsets 659 kotlin-responseBased-test_inline 657 kotlin-responseBased-named_fragment_without_implementation 651 +kotlin-operationBased-used_arguments 651 kotlin-operationBased-union_fragment 650 kotlin-operationBased-decapitalized_fields 647 kotlin-responseBased-hero_details 647 diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/used-coordinates.json.expected index 546fcc688a9..167b723c3cd 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/used-coordinates.json.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/used-coordinates.json.expected @@ -1,6 +1,9 @@ { "typeToFieldsToArguments": { "Character": { + "height": [ + "unit" + ] }, "Query": { "hero": [ diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/TestOperation.graphql b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/TestOperation.graphql new file mode 100644 index 00000000000..a2c3f1aecb4 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/TestOperation.graphql @@ -0,0 +1,14 @@ +fragment ADetails on A { + field(arg: 42) +} + +query GetA { + a { + ... on B { + field(arg: 42) + } + ... on C { + field(arg: 42) + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used-coordinates.json.expected new file mode 100644 index 00000000000..40699d8490a --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used-coordinates.json.expected @@ -0,0 +1,25 @@ +{ + "typeToFieldsToArguments": { + "A": { + "field": [ + "arg" + ] + }, + "Int": { + }, + "B": { + "field": [ + "arg" + ] + }, + "C": { + "field": [ + "arg" + ] + }, + "String": { + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/GetA.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/GetA.java.expected new file mode 100644 index 00000000000..ea539f92bae --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/GetA.java.expected @@ -0,0 +1,350 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments; + +import com.apollographql.apollo3.api.Adapter; +import com.apollographql.apollo3.api.CompiledField; +import com.apollographql.apollo3.api.CustomScalarAdapters; +import com.apollographql.apollo3.api.ObjectAdapter; +import com.apollographql.apollo3.api.Query; +import com.apollographql.apollo3.api.json.JsonWriter; +import com.example.used_arguments.adapter.GetA_ResponseAdapter; +import com.example.used_arguments.selections.GetASelections; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class GetA implements Query { + public static final String OPERATION_ID = "9ea4fe0d8d5f625417b080b65cba65b994059847d59fac8d092ffd51eb6cd39e"; + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * query GetA { + * a { + * __typename + * ... on B { + * field(arg: 42) + * } + * ... on C { + * field(arg: 42) + * } + * } + * } + */ + public static final String OPERATION_DOCUMENT = "query GetA { a { __typename ... on B { field(arg: 42) } ... on C { field(arg: 42) } } }"; + + public static final String OPERATION_NAME = "GetA"; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public GetA() { + + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof GetA) { + return true; + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "GetA{" + + "}"; + } + return $toString; + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String id() { + return OPERATION_ID; + } + + @Override + public String document() { + return OPERATION_DOCUMENT; + } + + @Override + public String name() { + return OPERATION_NAME; + } + + @Override + public void serializeVariables(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + boolean withDefaultValues) throws IOException { + // This operation doesn't have any variable + } + + @Override + public Adapter adapter() { + return new ObjectAdapter(GetA_ResponseAdapter.Data.INSTANCE, false); + } + + @Override + public CompiledField rootField() { + return new CompiledField.Builder( + "data", + com.example.used_arguments.type.Query.type + ) + .selections(GetASelections.__root) + .build(); + } + + @Override + public boolean getIgnoreErrors() { + return false; + } + + public static final class Builder { + Builder() { + } + + public GetA build() { + return new GetA(); + } + } + + public static class Data implements Query.Data { + public A a; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public Data(A a) { + this.a = a; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Data) { + Data that = (Data) o; + return ((this.a == null) ? (that.a == null) : this.a.equals(that.a)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (a == null) ? 0 : a.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "Data{" + + "a=" + a + + "}"; + } + return $toString; + } + } + + public static class A { + public String __typename; + + /** + * Synthetic field for inline fragment on B + */ + public OnB onB; + + /** + * Synthetic field for inline fragment on C + */ + public OnC onC; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public A(String __typename, OnB onB, OnC onC) { + this.__typename = __typename; + this.onB = onB; + this.onC = onC; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof A) { + A that = (A) o; + return ((this.__typename == null) ? (that.__typename == null) : this.__typename.equals(that.__typename)) + &&((this.onB == null) ? (that.onB == null) : this.onB.equals(that.onB)) + &&((this.onC == null) ? (that.onC == null) : this.onC.equals(that.onC)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (__typename == null) ? 0 : __typename.hashCode(); + __h *= 1000003; + __h ^= (onB == null) ? 0 : onB.hashCode(); + __h *= 1000003; + __h ^= (onC == null) ? 0 : onC.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "A{" + + "__typename=" + __typename + ", " + + "onB=" + onB + ", " + + "onC=" + onC + + "}"; + } + return $toString; + } + } + + public static class OnB { + public Integer field; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public OnB(Integer field) { + this.field = field; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof OnB) { + OnB that = (OnB) o; + return ((this.field == null) ? (that.field == null) : this.field.equals(that.field)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (field == null) ? 0 : field.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "OnB{" + + "field=" + field + + "}"; + } + return $toString; + } + } + + public static class OnC { + public Integer field; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public OnC(Integer field) { + this.field = field; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof OnC) { + OnC that = (OnC) o; + return ((this.field == null) ? (that.field == null) : this.field.equals(that.field)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (field == null) ? 0 : field.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "OnC{" + + "field=" + field + + "}"; + } + return $toString; + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/adapter/GetA_ResponseAdapter.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/adapter/GetA_ResponseAdapter.java.expected new file mode 100644 index 00000000000..b93dd71b02f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/adapter/GetA_ResponseAdapter.java.expected @@ -0,0 +1,175 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.adapter; + +import com.apollographql.apollo3.api.Adapter; +import com.apollographql.apollo3.api.Adapters; +import com.apollographql.apollo3.api.Assertions; +import com.apollographql.apollo3.api.BPossibleTypes; +import com.apollographql.apollo3.api.BTerm; +import com.apollographql.apollo3.api.BooleanExpression; +import com.apollographql.apollo3.api.BooleanExpressions; +import com.apollographql.apollo3.api.CustomScalarAdapters; +import com.apollographql.apollo3.api.NullableAdapter; +import com.apollographql.apollo3.api.ObjectAdapter; +import com.apollographql.apollo3.api.json.JsonReader; +import com.apollographql.apollo3.api.json.JsonWriter; +import com.example.used_arguments.GetA; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.Arrays; +import java.util.List; + +public class GetA_ResponseAdapter { + public enum Data implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("a"); + + @Override + public GetA.Data fromJson(JsonReader reader, CustomScalarAdapters customScalarAdapters) throws + IOException { + GetA.A _a = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: _a = new NullableAdapter<>(new ObjectAdapter(A.INSTANCE, true)).fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + return new GetA.Data( + _a + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + GetA.Data value) throws IOException { + writer.name("a"); + new NullableAdapter<>(new ObjectAdapter(A.INSTANCE, true)).toJson(writer, customScalarAdapters, value.a); + } + } + + public enum A implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("__typename"); + + @Override + public GetA.A fromJson(JsonReader reader, CustomScalarAdapters customScalarAdapters) throws + IOException { + String __typename = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: __typename = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + Assertions.checkFieldNotMissing(__typename, "__typename"); + GetA.OnB _onB = null; + if (BooleanExpressions.evaluate(new BooleanExpression.Element(new BPossibleTypes("B")), customScalarAdapters.falseVariables, __typename, customScalarAdapters.deferredFragmentIdentifiers, null)) { + reader.rewind(); + _onB = com.example.used_arguments.adapter.GetA_ResponseAdapter.OnB.INSTANCE.fromJson(reader, customScalarAdapters); + } + + GetA.OnC _onC = null; + if (BooleanExpressions.evaluate(new BooleanExpression.Element(new BPossibleTypes("C")), customScalarAdapters.falseVariables, __typename, customScalarAdapters.deferredFragmentIdentifiers, null)) { + reader.rewind(); + _onC = com.example.used_arguments.adapter.GetA_ResponseAdapter.OnC.INSTANCE.fromJson(reader, customScalarAdapters); + } + + return new GetA.A( + __typename, + _onB, + _onC + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, GetA.A value) + throws IOException { + writer.name("__typename"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.__typename); + + if (value.onB != null) { + com.example.used_arguments.adapter.GetA_ResponseAdapter.OnB.INSTANCE.toJson(writer, customScalarAdapters, value.onB); + } + + if (value.onC != null) { + com.example.used_arguments.adapter.GetA_ResponseAdapter.OnC.INSTANCE.toJson(writer, customScalarAdapters, value.onC); + } + } + } + + public enum OnB implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("field"); + + @Override + public GetA.OnB fromJson(JsonReader reader, CustomScalarAdapters customScalarAdapters) throws + IOException { + Integer _field = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: _field = Adapters.NullableIntAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + return new GetA.OnB( + _field + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, GetA.OnB value) + throws IOException { + writer.name("field"); + Adapters.NullableIntAdapter.toJson(writer, customScalarAdapters, value.field); + } + } + + public enum OnC implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("field"); + + @Override + public GetA.OnC fromJson(JsonReader reader, CustomScalarAdapters customScalarAdapters) throws + IOException { + Integer _field = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: _field = Adapters.NullableIntAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + return new GetA.OnC( + _field + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, GetA.OnC value) + throws IOException { + writer.name("field"); + Adapters.NullableIntAdapter.toJson(writer, customScalarAdapters, value.field); + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetails.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetails.java.expected new file mode 100644 index 00000000000..b36f90011ec --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetails.java.expected @@ -0,0 +1,60 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment; + +import com.apollographql.apollo3.api.Fragment; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class ADetails implements Fragment.Data { + public Integer field; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public ADetails(Integer field) { + this.field = field; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ADetails) { + ADetails that = (ADetails) o; + return ((this.field == null) ? (that.field == null) : this.field.equals(that.field)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (field == null) ? 0 : field.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "ADetails{" + + "field=" + field + + "}"; + } + return $toString; + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl.java.expected new file mode 100644 index 00000000000..40f040999e1 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl.java.expected @@ -0,0 +1,87 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment; + +import com.apollographql.apollo3.api.Adapter; +import com.apollographql.apollo3.api.CompiledField; +import com.apollographql.apollo3.api.CustomScalarAdapters; +import com.apollographql.apollo3.api.Fragment; +import com.apollographql.apollo3.api.ObjectAdapter; +import com.apollographql.apollo3.api.json.JsonWriter; +import com.example.used_arguments.fragment.selections.ADetailsSelections; +import com.example.used_arguments.type.A; +import java.io.IOException; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class ADetailsImpl implements Fragment { + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public ADetailsImpl() { + + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ADetailsImpl) { + return true; + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "ADetailsImpl{" + + "}"; + } + return $toString; + } + + @Override + public void serializeVariables(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + boolean withDefaultValues) throws IOException { + // This fragment doesn't have any variable + } + + @Override + public Adapter adapter() { + return new ObjectAdapter(ADetailsImpl_ResponseAdapter.ADetails.INSTANCE, false); + } + + @Override + public CompiledField rootField() { + return new CompiledField.Builder( + "data", + A.type + ) + .selections(ADetailsSelections.__root) + .build(); + } + + @Override + public boolean getIgnoreErrors() { + return false; + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.java.expected new file mode 100644 index 00000000000..680bbe4c732 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.java.expected @@ -0,0 +1,51 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment; + +import com.apollographql.apollo3.api.Adapter; +import com.apollographql.apollo3.api.Adapters; +import com.apollographql.apollo3.api.CustomScalarAdapters; +import com.apollographql.apollo3.api.json.JsonReader; +import com.apollographql.apollo3.api.json.JsonWriter; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Override; +import java.lang.String; +import java.util.Arrays; +import java.util.List; + +public class ADetailsImpl_ResponseAdapter { + public enum ADetails implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("field"); + + @Override + public com.example.used_arguments.fragment.ADetails fromJson(JsonReader reader, + CustomScalarAdapters customScalarAdapters) throws IOException { + Integer _field = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: _field = Adapters.NullableIntAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + return new com.example.used_arguments.fragment.ADetails( + _field + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + com.example.used_arguments.fragment.ADetails value) throws IOException { + writer.name("field"); + Adapters.NullableIntAdapter.toJson(writer, customScalarAdapters, value.field); + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/selections/ADetailsSelections.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/selections/ADetailsSelections.java.expected new file mode 100644 index 00000000000..1231ffa0d38 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/fragment/selections/ADetailsSelections.java.expected @@ -0,0 +1,20 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment.selections; + +import com.apollographql.apollo3.api.CompiledArgument; +import com.apollographql.apollo3.api.CompiledField; +import com.apollographql.apollo3.api.CompiledSelection; +import com.example.used_arguments.type.A; +import com.example.used_arguments.type.GraphQLInt; +import java.util.Arrays; +import java.util.List; + +public class ADetailsSelections { + public static List __root = Arrays.asList( + new CompiledField.Builder("field", GraphQLInt.type).arguments(Arrays.asList(new CompiledArgument.Builder(A.__field_arg).value(42).build())).build() + ); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/selections/GetASelections.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/selections/GetASelections.java.expected new file mode 100644 index 00000000000..01187f84731 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/selections/GetASelections.java.expected @@ -0,0 +1,39 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.selections; + +import com.apollographql.apollo3.api.CompiledArgument; +import com.apollographql.apollo3.api.CompiledField; +import com.apollographql.apollo3.api.CompiledFragment; +import com.apollographql.apollo3.api.CompiledNotNullType; +import com.apollographql.apollo3.api.CompiledSelection; +import com.example.used_arguments.type.A; +import com.example.used_arguments.type.B; +import com.example.used_arguments.type.C; +import com.example.used_arguments.type.GraphQLInt; +import com.example.used_arguments.type.GraphQLString; +import java.util.Arrays; +import java.util.List; + +public class GetASelections { + private static List __onB = Arrays.asList( + new CompiledField.Builder("field", GraphQLInt.type).arguments(Arrays.asList(new CompiledArgument.Builder(B.__field_arg).value(42).build())).build() + ); + + private static List __onC = Arrays.asList( + new CompiledField.Builder("field", GraphQLInt.type).arguments(Arrays.asList(new CompiledArgument.Builder(C.__field_arg).value(42).build())).build() + ); + + private static List __a = Arrays.asList( + new CompiledField.Builder("__typename", new CompiledNotNullType(GraphQLString.type)).build(), + new CompiledFragment.Builder("B", Arrays.asList("B")).selections(__onB).build(), + new CompiledFragment.Builder("C", Arrays.asList("C")).selections(__onC).build() + ); + + public static List __root = Arrays.asList( + new CompiledField.Builder("a", A.type).selections(__a).build() + ); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/A.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/A.java.expected new file mode 100644 index 00000000000..f206e28575e --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/A.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CompiledArgumentDefinition; +import com.apollographql.apollo3.api.InterfaceType; + +public class A { + public static final CompiledArgumentDefinition __field_arg = new CompiledArgumentDefinition.Builder("arg").build(); + + public static InterfaceType type = (new InterfaceType.Builder("A")).build(); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/B.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/B.java.expected new file mode 100644 index 00000000000..90080337790 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/B.java.expected @@ -0,0 +1,16 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CompiledArgumentDefinition; +import com.apollographql.apollo3.api.ObjectType; +import java.util.Arrays; + +public class B { + public static final CompiledArgumentDefinition __field_arg = new CompiledArgumentDefinition.Builder("arg").build(); + + public static ObjectType type = (new ObjectType.Builder("B")).interfaces(Arrays.asList(A.type)).build(); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/C.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/C.java.expected new file mode 100644 index 00000000000..498568c31fd --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/C.java.expected @@ -0,0 +1,16 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CompiledArgumentDefinition; +import com.apollographql.apollo3.api.ObjectType; +import java.util.Arrays; + +public class C { + public static final CompiledArgumentDefinition __field_arg = new CompiledArgumentDefinition.Builder("arg").build(); + + public static ObjectType type = (new ObjectType.Builder("C")).interfaces(Arrays.asList(A.type)).build(); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLBoolean.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLBoolean.java.expected new file mode 100644 index 00000000000..e04e00dc0dc --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLBoolean.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CustomScalarType; + +/** + * The `Boolean` scalar type represents `true` or `false`. + */ +public class GraphQLBoolean { + public static CustomScalarType type = new CustomScalarType("Boolean", "java.lang.Boolean"); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLFloat.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLFloat.java.expected new file mode 100644 index 00000000000..54dda2133d5 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLFloat.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CustomScalarType; + +/** + * The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). + */ +public class GraphQLFloat { + public static CustomScalarType type = new CustomScalarType("Float", "java.lang.Float"); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLID.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLID.java.expected new file mode 100644 index 00000000000..fe5d817194c --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLID.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CustomScalarType; + +/** + * The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID. + */ +public class GraphQLID { + public static CustomScalarType type = new CustomScalarType("ID", "java.lang.String"); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLInt.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLInt.java.expected new file mode 100644 index 00000000000..79253448d3f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLInt.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CustomScalarType; + +/** + * The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. + */ +public class GraphQLInt { + public static CustomScalarType type = new CustomScalarType("Int", "java.lang.Integer"); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLString.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLString.java.expected new file mode 100644 index 00000000000..d2e99dea977 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/GraphQLString.java.expected @@ -0,0 +1,15 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.CustomScalarType; + +/** + * The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. + */ +public class GraphQLString { + public static CustomScalarType type = new CustomScalarType("String", "java.lang.String"); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/Query.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/Query.java.expected new file mode 100644 index 00000000000..0632de196f5 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/java/operationBased/used_arguments/type/Query.java.expected @@ -0,0 +1,12 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type; + +import com.apollographql.apollo3.api.ObjectType; + +public class Query { + public static ObjectType type = (new ObjectType.Builder("Query")).build(); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used-coordinates.json.expected new file mode 100644 index 00000000000..40699d8490a --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used-coordinates.json.expected @@ -0,0 +1,25 @@ +{ + "typeToFieldsToArguments": { + "A": { + "field": [ + "arg" + ] + }, + "Int": { + }, + "B": { + "field": [ + "arg" + ] + }, + "C": { + "field": [ + "arg" + ] + }, + "String": { + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/GetA.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/GetA.kt.expected new file mode 100644 index 00000000000..54626ad7ddf --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/GetA.kt.expected @@ -0,0 +1,106 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments + +import com.apollographql.apollo3.annotations.ApolloAdaptableWith +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.Query +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.obj +import com.example.used_arguments.adapter.GetA_ResponseAdapter +import com.example.used_arguments.selections.GetASelections +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import com.example.used_arguments.type.Query as CompiledQuery + +public class GetA() : Query { + override val ignoreErrors: Boolean = false + + override fun equals(other: Any?): Boolean = other != null && other::class == this::class + + override fun hashCode(): Int = this::class.hashCode() + + override fun id(): String = OPERATION_ID + + override fun document(): String = OPERATION_DOCUMENT + + override fun name(): String = OPERATION_NAME + + override fun serializeVariables( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + withDefaultValues: Boolean, + ) { + // This operation doesn't have any variable + } + + override fun adapter(): Adapter = GetA_ResponseAdapter.Data.obj() + + override fun rootField(): CompiledField = CompiledField.Builder( + name = "data", + type = CompiledQuery.type + ) + .selections(selections = GetASelections.__root) + .build() + + @ApolloAdaptableWith(GetA_ResponseAdapter.Data::class) + public data class Data( + public val a: A?, + ) : Query.Data { + public data class A( + public val __typename: String, + /** + * Synthetic field for inline fragment on B + */ + public val onB: OnB?, + /** + * Synthetic field for inline fragment on C + */ + public val onC: OnC?, + ) { + public data class OnB( + public val `field`: Int?, + ) + + public data class OnC( + public val `field`: Int?, + ) + } + } + + public companion object { + public const val OPERATION_ID: String = + "9ea4fe0d8d5f625417b080b65cba65b994059847d59fac8d092ffd51eb6cd39e" + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * ``` + * query GetA { + * a { + * __typename + * ... on B { + * field(arg: 42) + * } + * ... on C { + * field(arg: 42) + * } + * } + * } + * ``` + */ + public val OPERATION_DOCUMENT: String + get() = + "query GetA { a { __typename ... on B { field(arg: 42) } ... on C { field(arg: 42) } } }" + + public const val OPERATION_NAME: String = "GetA" + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..8c2b6ef68ed --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected @@ -0,0 +1,169 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.adapter + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.NullableIntAdapter +import com.apollographql.apollo3.api.StringAdapter +import com.apollographql.apollo3.api.evaluate +import com.apollographql.apollo3.api.json.JsonReader +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.nullable +import com.apollographql.apollo3.api.obj +import com.apollographql.apollo3.api.possibleTypes +import com.example.used_arguments.GetA +import kotlin.Int +import kotlin.String +import kotlin.collections.List + +public object GetA_ResponseAdapter { + public object Data : Adapter { + public val RESPONSE_NAMES: List = listOf("a") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data { + var _a: GetA.Data.A? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _a = A.obj(true).nullable().fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data( + a = _a + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data, + ) { + writer.name("a") + A.obj(true).nullable().toJson(writer, customScalarAdapters, value.a) + } + + private object A : Adapter { + public val RESPONSE_NAMES: List = listOf("__typename") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data.A { + var __typename: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + check(__typename != null) { + "__typename was not found" + } + + var _onB: GetA.Data.A.OnB? = null + if (possibleTypes("B").evaluate(customScalarAdapters.falseVariables, __typename, customScalarAdapters.deferredFragmentIdentifiers, null)) { + reader.rewind() + _onB = com.example.used_arguments.adapter.GetA_ResponseAdapter.Data.A.OnB.fromJson(reader, + customScalarAdapters) + } + + var _onC: GetA.Data.A.OnC? = null + if (possibleTypes("C").evaluate(customScalarAdapters.falseVariables, __typename, customScalarAdapters.deferredFragmentIdentifiers, null)) { + reader.rewind() + _onC = com.example.used_arguments.adapter.GetA_ResponseAdapter.Data.A.OnC.fromJson(reader, + customScalarAdapters) + } + + return GetA.Data.A( + __typename = __typename, + onB = _onB, + onC = _onC + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + if (value.onB != null) { + com.example.used_arguments.adapter.GetA_ResponseAdapter.Data.A.OnB.toJson(writer, + customScalarAdapters, value.onB) + } + + if (value.onC != null) { + com.example.used_arguments.adapter.GetA_ResponseAdapter.Data.A.OnC.toJson(writer, + customScalarAdapters, value.onC) + } + } + + private object OnB : Adapter { + public val RESPONSE_NAMES: List = listOf("field") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data.A.OnB { + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.A.OnB( + `field` = _field + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A.OnB, + ) { + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } + + private object OnC : Adapter { + public val RESPONSE_NAMES: List = listOf("field") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data.A.OnC { + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.A.OnC( + `field` = _field + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A.OnC, + ) { + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetails.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetails.kt.expected new file mode 100644 index 00000000000..5fadcedb659 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetails.kt.expected @@ -0,0 +1,13 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import com.apollographql.apollo3.api.Fragment +import kotlin.Int + +public data class ADetails( + public val `field`: Int?, +) : Fragment.Data diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl.kt.expected new file mode 100644 index 00000000000..9f0688cf23a --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl.kt.expected @@ -0,0 +1,43 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.Fragment +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.obj +import com.example.used_arguments.fragment.selections.ADetailsSelections +import com.example.used_arguments.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int + +public class ADetailsImpl() : Fragment { + override val ignoreErrors: Boolean = false + + override fun equals(other: Any?): Boolean = other != null && other::class == this::class + + override fun hashCode(): Int = this::class.hashCode() + + override fun serializeVariables( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + withDefaultValues: Boolean, + ) { + // This fragment doesn't have any variable + } + + override fun adapter(): Adapter = ADetailsImpl_ResponseAdapter.ADetails.obj() + + override fun rootField(): CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = ADetailsSelections.__root) + .build() +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..a6e5ee8e4ef --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected @@ -0,0 +1,46 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.NullableIntAdapter +import com.apollographql.apollo3.api.json.JsonReader +import com.apollographql.apollo3.api.json.JsonWriter +import kotlin.Int +import kotlin.String +import kotlin.collections.List + +public object ADetailsImpl_ResponseAdapter { + public object ADetails : Adapter { + public val RESPONSE_NAMES: List = listOf("field") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + com.example.used_arguments.fragment.ADetails { + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return com.example.used_arguments.fragment.ADetails( + `field` = _field + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: com.example.used_arguments.fragment.ADetails, + ) { + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected new file mode 100644 index 00000000000..63da2e37f32 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected @@ -0,0 +1,25 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment.selections + +import com.apollographql.apollo3.api.CompiledArgument +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CompiledSelection +import com.example.used_arguments.type.A +import com.example.used_arguments.type.GraphQLInt +import kotlin.collections.List + +public object ADetailsSelections { + public val __root: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(A.__field_arg).value(42).build() + )) + .build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/selections/GetASelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/selections/GetASelections.kt.expected new file mode 100644 index 00000000000..f0b67930fad --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/selections/GetASelections.kt.expected @@ -0,0 +1,65 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.selections + +import com.apollographql.apollo3.api.CompiledArgument +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CompiledFragment +import com.apollographql.apollo3.api.CompiledSelection +import com.apollographql.apollo3.api.notNull +import com.example.used_arguments.type.A +import com.example.used_arguments.type.B +import com.example.used_arguments.type.C +import com.example.used_arguments.type.GraphQLInt +import com.example.used_arguments.type.GraphQLString +import kotlin.collections.List + +public object GetASelections { + private val __onB: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(B.__field_arg).value(42).build() + )) + .build() + ) + + private val __onC: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(C.__field_arg).value(42).build() + )) + .build() + ) + + private val __a: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledFragment.Builder( + typeCondition = "B", + possibleTypes = listOf("B") + ).selections(__onB) + .build(), + CompiledFragment.Builder( + typeCondition = "C", + possibleTypes = listOf("C") + ).selections(__onC) + .build() + ) + + public val __root: List = listOf( + CompiledField.Builder( + name = "a", + type = A.type + ).selections(__a) + .build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/A.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/A.kt.expected new file mode 100644 index 00000000000..64ef85e7695 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/A.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.InterfaceType + +public class A { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: InterfaceType = InterfaceType.Builder(name = "A").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/B.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/B.kt.expected new file mode 100644 index 00000000000..3a79f545529 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/B.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.ObjectType + +public class B { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: ObjectType = ObjectType.Builder(name = "B").interfaces(listOf(A.type)).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/C.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/C.kt.expected new file mode 100644 index 00000000000..38dace1ef13 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/C.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.ObjectType + +public class C { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: ObjectType = ObjectType.Builder(name = "C").interfaces(listOf(A.type)).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLBoolean.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLBoolean.kt.expected new file mode 100644 index 00000000000..dd7af72e4db --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLBoolean.kt.expected @@ -0,0 +1,17 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Boolean` scalar type represents `true` or `false`. + */ +public class GraphQLBoolean { + public companion object { + public val type: CustomScalarType = CustomScalarType("Boolean", "kotlin.Boolean") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLFloat.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLFloat.kt.expected new file mode 100644 index 00000000000..4073753ac46 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLFloat.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Float` scalar type represents signed double-precision fractional values as specified by + * [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). + */ +public class GraphQLFloat { + public companion object { + public val type: CustomScalarType = CustomScalarType("Float", "kotlin.Float") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLID.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLID.kt.expected new file mode 100644 index 00000000000..632ecbb7087 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLID.kt.expected @@ -0,0 +1,20 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `ID` scalar type represents a unique identifier, often used to refetch an object or as key + * for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be + * human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) + * input value will be accepted as an ID. + */ +public class GraphQLID { + public companion object { + public val type: CustomScalarType = CustomScalarType("ID", "kotlin.String") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLInt.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLInt.kt.expected new file mode 100644 index 00000000000..48a3c885801 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLInt.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent + * values between -(2^31) and 2^31 - 1. + */ +public class GraphQLInt { + public companion object { + public val type: CustomScalarType = CustomScalarType("Int", "kotlin.Int") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLString.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLString.kt.expected new file mode 100644 index 00000000000..3c5a69ebb1b --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/GraphQLString.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `String` scalar type represents textual data, represented as UTF-8 character sequences. The + * String type is most often used by GraphQL to represent free-form human-readable text. + */ +public class GraphQLString { + public companion object { + public val type: CustomScalarType = CustomScalarType("String", "kotlin.String") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/Query.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/Query.kt.expected new file mode 100644 index 00000000000..67599158a2f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/operationBased/used_arguments/type/Query.kt.expected @@ -0,0 +1,14 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.ObjectType + +public class Query { + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "Query").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used-coordinates.json.expected new file mode 100644 index 00000000000..c20738d07ba --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used-coordinates.json.expected @@ -0,0 +1,25 @@ +{ + "typeToFieldsToArguments": { + "A": { + "field": [ + "arg" + ] + }, + "String": { + }, + "Int": { + }, + "B": { + "field": [ + "arg" + ] + }, + "C": { + "field": [ + "arg" + ] + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/GetA.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/GetA.kt.expected new file mode 100644 index 00000000000..14e0e7dc9cf --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/GetA.kt.expected @@ -0,0 +1,113 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments + +import com.apollographql.apollo3.annotations.ApolloAdaptableWith +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.Query +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.obj +import com.example.used_arguments.adapter.GetA_ResponseAdapter +import com.example.used_arguments.selections.GetASelections +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import kotlin.Suppress +import com.example.used_arguments.type.Query as CompiledQuery + +public class GetA() : Query { + override val ignoreErrors: Boolean = false + + override fun equals(other: Any?): Boolean = other != null && other::class == this::class + + override fun hashCode(): Int = this::class.hashCode() + + override fun id(): String = OPERATION_ID + + override fun document(): String = OPERATION_DOCUMENT + + override fun name(): String = OPERATION_NAME + + override fun serializeVariables( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + withDefaultValues: Boolean, + ) { + // This operation doesn't have any variable + } + + override fun adapter(): Adapter = GetA_ResponseAdapter.Data.obj() + + override fun rootField(): CompiledField = CompiledField.Builder( + name = "data", + type = CompiledQuery.type + ) + .selections(selections = GetASelections.__root) + .build() + + @ApolloAdaptableWith(GetA_ResponseAdapter.Data::class) + public data class Data( + public val a: A?, + ) : Query.Data { + public sealed interface A { + public val __typename: String + + public companion object { + @Suppress("USELESS_CAST") + public fun A.asB(): BA? = this as? BA + + @Suppress("USELESS_CAST") + public fun A.asC(): CA? = this as? CA + } + } + + public data class BA( + override val __typename: String, + public val `field`: Int?, + ) : A + + public data class CA( + override val __typename: String, + public val `field`: Int?, + ) : A + + public data class OtherA( + override val __typename: String, + ) : A + } + + public companion object { + public const val OPERATION_ID: String = + "9ea4fe0d8d5f625417b080b65cba65b994059847d59fac8d092ffd51eb6cd39e" + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * ``` + * query GetA { + * a { + * __typename + * ... on B { + * field(arg: 42) + * } + * ... on C { + * field(arg: 42) + * } + * } + * } + * ``` + */ + public val OPERATION_DOCUMENT: String + get() = + "query GetA { a { __typename ... on B { field(arg: 42) } ... on C { field(arg: 42) } } }" + + public const val OPERATION_NAME: String = "GetA" + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..3f401e1ed4d --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/adapter/GetA_ResponseAdapter.kt.expected @@ -0,0 +1,188 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.adapter + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.NullableIntAdapter +import com.apollographql.apollo3.api.StringAdapter +import com.apollographql.apollo3.api.json.JsonReader +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.json.readTypename +import com.apollographql.apollo3.api.missingField +import com.apollographql.apollo3.api.nullable +import com.apollographql.apollo3.api.obj +import com.example.used_arguments.GetA +import kotlin.Int +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List + +public object GetA_ResponseAdapter { + public object Data : Adapter { + public val RESPONSE_NAMES: List = listOf("a") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data { + var _a: GetA.Data.A? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _a = A.obj().nullable().fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data( + a = _a + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data, + ) { + writer.name("a") + A.obj().nullable().toJson(writer, customScalarAdapters, value.a) + } + + private object A : Adapter { + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + GetA.Data.A { + val __typename = reader.readTypename() + return when(__typename) { + "B", + -> BA.fromJson(reader, customScalarAdapters, __typename) + "C", + -> CA.fromJson(reader, customScalarAdapters, __typename) + else + -> OtherA.fromJson(reader, customScalarAdapters, __typename) + } + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A, + ) { + when(value) { + is GetA.Data.BA -> BA.toJson(writer, customScalarAdapters, value) + is GetA.Data.CA -> CA.toJson(writer, customScalarAdapters, value) + is GetA.Data.OtherA -> OtherA.toJson(writer, customScalarAdapters, value) + } + } + } + + public object BA { + public val RESPONSE_NAMES: List = listOf("__typename", "field") + + public fun fromJson( + reader: JsonReader, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + typename: String, + ): GetA.Data.BA { + var __typename: String? = typename + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.BA( + __typename = __typename ?: missingField(reader, "__typename"), + `field` = _field + ) + } + + public fun toJson( + writer: JsonWriter, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.BA, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } + + public object CA { + public val RESPONSE_NAMES: List = listOf("__typename", "field") + + public fun fromJson( + reader: JsonReader, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + typename: String, + ): GetA.Data.CA { + var __typename: String? = typename + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.CA( + __typename = __typename ?: missingField(reader, "__typename"), + `field` = _field + ) + } + + public fun toJson( + writer: JsonWriter, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.CA, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } + + public object OtherA { + public val RESPONSE_NAMES: List = listOf("__typename") + + public fun fromJson( + reader: JsonReader, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + typename: String, + ): GetA.Data.OtherA { + var __typename: String? = typename + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.OtherA( + __typename = __typename ?: missingField(reader, "__typename") + ) + } + + public fun toJson( + writer: JsonWriter, + @Suppress("UNUSED_PARAMETER") customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.OtherA, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + } + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetails.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetails.kt.expected new file mode 100644 index 00000000000..723829773d1 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetails.kt.expected @@ -0,0 +1,12 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import kotlin.Int + +public interface ADetails { + public val `field`: Int? +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl.kt.expected new file mode 100644 index 00000000000..80fb85b9e46 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl.kt.expected @@ -0,0 +1,47 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.Fragment +import com.apollographql.apollo3.api.json.JsonWriter +import com.apollographql.apollo3.api.obj +import com.example.used_arguments.fragment.selections.ADetailsSelections +import com.example.used_arguments.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int + +public class ADetailsImpl() : Fragment { + override val ignoreErrors: Boolean = false + + override fun equals(other: Any?): Boolean = other != null && other::class == this::class + + override fun hashCode(): Int = this::class.hashCode() + + override fun serializeVariables( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + withDefaultValues: Boolean, + ) { + // This fragment doesn't have any variable + } + + override fun adapter(): Adapter = ADetailsImpl_ResponseAdapter.Data.obj() + + override fun rootField(): CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = ADetailsSelections.__root) + .build() + + public data class Data( + override val `field`: Int?, + ) : ADetails, Fragment.Data +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..dd947d4204a --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/ADetailsImpl_ResponseAdapter.kt.expected @@ -0,0 +1,46 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment + +import com.apollographql.apollo3.api.Adapter +import com.apollographql.apollo3.api.CustomScalarAdapters +import com.apollographql.apollo3.api.NullableIntAdapter +import com.apollographql.apollo3.api.json.JsonReader +import com.apollographql.apollo3.api.json.JsonWriter +import kotlin.Int +import kotlin.String +import kotlin.collections.List + +public object ADetailsImpl_ResponseAdapter { + public object Data : Adapter { + public val RESPONSE_NAMES: List = listOf("field") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + ADetailsImpl.Data { + var _field: Int? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _field = NullableIntAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return ADetailsImpl.Data( + `field` = _field + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: ADetailsImpl.Data, + ) { + writer.name("field") + NullableIntAdapter.toJson(writer, customScalarAdapters, value.`field`) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected new file mode 100644 index 00000000000..63da2e37f32 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/fragment/selections/ADetailsSelections.kt.expected @@ -0,0 +1,25 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.fragment.selections + +import com.apollographql.apollo3.api.CompiledArgument +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CompiledSelection +import com.example.used_arguments.type.A +import com.example.used_arguments.type.GraphQLInt +import kotlin.collections.List + +public object ADetailsSelections { + public val __root: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(A.__field_arg).value(42).build() + )) + .build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/selections/GetASelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/selections/GetASelections.kt.expected new file mode 100644 index 00000000000..f0b67930fad --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/selections/GetASelections.kt.expected @@ -0,0 +1,65 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.selections + +import com.apollographql.apollo3.api.CompiledArgument +import com.apollographql.apollo3.api.CompiledField +import com.apollographql.apollo3.api.CompiledFragment +import com.apollographql.apollo3.api.CompiledSelection +import com.apollographql.apollo3.api.notNull +import com.example.used_arguments.type.A +import com.example.used_arguments.type.B +import com.example.used_arguments.type.C +import com.example.used_arguments.type.GraphQLInt +import com.example.used_arguments.type.GraphQLString +import kotlin.collections.List + +public object GetASelections { + private val __onB: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(B.__field_arg).value(42).build() + )) + .build() + ) + + private val __onC: List = listOf( + CompiledField.Builder( + name = "field", + type = GraphQLInt.type + ).arguments(listOf( + CompiledArgument.Builder(C.__field_arg).value(42).build() + )) + .build() + ) + + private val __a: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledFragment.Builder( + typeCondition = "B", + possibleTypes = listOf("B") + ).selections(__onB) + .build(), + CompiledFragment.Builder( + typeCondition = "C", + possibleTypes = listOf("C") + ).selections(__onC) + .build() + ) + + public val __root: List = listOf( + CompiledField.Builder( + name = "a", + type = A.type + ).selections(__a) + .build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/A.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/A.kt.expected new file mode 100644 index 00000000000..64ef85e7695 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/A.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.InterfaceType + +public class A { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: InterfaceType = InterfaceType.Builder(name = "A").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/B.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/B.kt.expected new file mode 100644 index 00000000000..3a79f545529 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/B.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.ObjectType + +public class B { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: ObjectType = ObjectType.Builder(name = "B").interfaces(listOf(A.type)).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/C.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/C.kt.expected new file mode 100644 index 00000000000..38dace1ef13 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/C.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CompiledArgumentDefinition +import com.apollographql.apollo3.api.ObjectType + +public class C { + public companion object { + public val __field_arg: CompiledArgumentDefinition = + CompiledArgumentDefinition.Builder("arg").build() + + public val type: ObjectType = ObjectType.Builder(name = "C").interfaces(listOf(A.type)).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLBoolean.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLBoolean.kt.expected new file mode 100644 index 00000000000..dd7af72e4db --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLBoolean.kt.expected @@ -0,0 +1,17 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Boolean` scalar type represents `true` or `false`. + */ +public class GraphQLBoolean { + public companion object { + public val type: CustomScalarType = CustomScalarType("Boolean", "kotlin.Boolean") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLFloat.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLFloat.kt.expected new file mode 100644 index 00000000000..4073753ac46 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLFloat.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Float` scalar type represents signed double-precision fractional values as specified by + * [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). + */ +public class GraphQLFloat { + public companion object { + public val type: CustomScalarType = CustomScalarType("Float", "kotlin.Float") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLID.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLID.kt.expected new file mode 100644 index 00000000000..632ecbb7087 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLID.kt.expected @@ -0,0 +1,20 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `ID` scalar type represents a unique identifier, often used to refetch an object or as key + * for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be + * human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) + * input value will be accepted as an ID. + */ +public class GraphQLID { + public companion object { + public val type: CustomScalarType = CustomScalarType("ID", "kotlin.String") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLInt.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLInt.kt.expected new file mode 100644 index 00000000000..48a3c885801 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLInt.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent + * values between -(2^31) and 2^31 - 1. + */ +public class GraphQLInt { + public companion object { + public val type: CustomScalarType = CustomScalarType("Int", "kotlin.Int") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLString.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLString.kt.expected new file mode 100644 index 00000000000..3c5a69ebb1b --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/GraphQLString.kt.expected @@ -0,0 +1,18 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.CustomScalarType + +/** + * The `String` scalar type represents textual data, represented as UTF-8 character sequences. The + * String type is most often used by GraphQL to represent free-form human-readable text. + */ +public class GraphQLString { + public companion object { + public val type: CustomScalarType = CustomScalarType("String", "kotlin.String") + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/Query.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/Query.kt.expected new file mode 100644 index 00000000000..67599158a2f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/kotlin/responseBased/used_arguments/type/Query.kt.expected @@ -0,0 +1,14 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.used_arguments.type + +import com.apollographql.apollo3.api.ObjectType + +public class Query { + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "Query").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/schema.graphqls b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/schema.graphqls new file mode 100644 index 00000000000..81ad9ab23c7 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/used_arguments/schema.graphqls @@ -0,0 +1,15 @@ +interface A { + field(arg: Int!): Int +} + +type B implements A { + field(arg: Int!): Int +} + +type C implements A { + field(arg: Int!): Int +} + +type Query { + a: A +} \ No newline at end of file