diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/addRequiredFields.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/addRequiredFields.kt index 5527c50d5ce..d1c05a23a4b 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/addRequiredFields.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/addRequiredFields.kt @@ -10,6 +10,7 @@ import com.apollographql.apollo.ast.Schema import com.apollographql.apollo.ast.definitionFromScope import com.apollographql.apollo.ast.isAbstract import com.apollographql.apollo.ast.rawType +import com.apollographql.apollo.ast.responseName import com.apollographql.apollo.ast.rootTypeDefinition import com.apollographql.apollo.compiler.ADD_TYPENAME_ALWAYS import com.apollographql.apollo.compiler.ADD_TYPENAME_IF_ABSTRACT @@ -94,7 +95,7 @@ private fun List.addRequiredFields( requiredFieldNames.add("__typename") } - val fieldNames = parentFields + selectionSet.filterIsInstance().map { it.name }.toSet() + val fieldNames = parentFields + selectionSet.filterIsInstance().map { it.responseName() }.toSet() var newSelections = selectionSet.map { when (it) { diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/checkKeyFields.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/checkKeyFields.kt index 0152857142e..cec01740b26 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/checkKeyFields.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/internal/checkKeyFields.kt @@ -39,7 +39,11 @@ internal fun checkKeyFields( schema: Schema, allFragmentDefinitions: Map, ) { - CheckKeyFieldsScope(schema, allFragmentDefinitions).checkField("Fragment(${fragmentDefinition.name})", fragmentDefinition.selections, fragmentDefinition.typeCondition.name) + CheckKeyFieldsScope(schema, allFragmentDefinitions).checkField( + "Fragment(${fragmentDefinition.name})", + fragmentDefinition.selections, + fragmentDefinition.typeCondition.name + ) } private fun CheckKeyFieldsScope.checkField( @@ -61,9 +65,9 @@ private fun CheckKeyFieldsScope.checkFieldSet(path: String, selections: List { if (it.directives.hasCondition()) { return@flatMap emptyList() @@ -108,6 +113,7 @@ private fun CheckKeyFieldsScope.collectFields( collectFields(it.selections, it.typeCondition?.name ?: parentType, implementedTypes) } + is GQLFragmentSpread -> { if (it.directives.hasCondition()) { return@flatMap emptyList() diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/TestOperation.graphql b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/TestOperation.graphql new file mode 100644 index 00000000000..7d4e7b6543d --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/TestOperation.graphql @@ -0,0 +1,15 @@ +query GetA { + a { + ...AFragment1 + } +} + +fragment AFragment1 on A { + foo + ...AFragment2 +} + +fragment AFragment2 on A { + bar + myId: id +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/GetA.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/GetA.java.expected new file mode 100644 index 00000000000..f2502ec4eed --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/GetA.java.expected @@ -0,0 +1,278 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.ExecutableDefinition; +import com.apollographql.apollo.api.ObjectAdapter; +import com.apollographql.apollo.api.Query; +import com.apollographql.apollo.api.json.JsonWriter; +import com.example.typepolicy.adapter.GetA_ResponseAdapter; +import com.example.typepolicy.fragment.AFragment1; +import com.example.typepolicy.selections.GetASelections; +import java.io.IOException; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; + +public class GetA implements Query { + public static ExecutableDefinition definition = new Definition(); + + public static final String OPERATION_ID = "64f5865843b43e7efa316fea6e9f6b175f0bc5d262d317306109dd68613547e4"; + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * query GetA { + * a { + * __typename + * ...AFragment1 + * id + * } + * } + * + * fragment AFragment2 on A { + * bar + * myId: id + * id + * __typename + * } + * + * fragment AFragment1 on A { + * __typename + * foo + * ...AFragment2 + * id + * } + */ + public static final String OPERATION_DOCUMENT = "query GetA { a { __typename ...AFragment1 id } } fragment AFragment2 on A { bar myId: id id __typename } fragment AFragment1 on A { __typename foo ...AFragment2 id }"; + + 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.typepolicy.type.Query.type + ) + .selections(GetASelections.__root) + .build(); + } + + @SuppressWarnings("unchecked") + public static final class Builder { + Builder() { + } + + public GetA build() { + return new GetA(); + } + } + + private static class Definition implements ExecutableDefinition { + @Override + public Adapter getADAPTER() { + return new ObjectAdapter(GetA_ResponseAdapter.Data.INSTANCE, false); + } + + @Override + public CompiledField getROOT_FIELD() { + return new CompiledField.Builder( + "data", + com.example.typepolicy.type.Query.type + ) + .selections(GetASelections.__root) + .build(); + } + } + + 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; + + public String id; + + /** + * Synthetic field for 'AFragment1' + */ + public AFragment1 aFragment1; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public A(String __typename, String id, AFragment1 aFragment1) { + this.__typename = __typename; + this.id = id; + this.aFragment1 = aFragment1; + } + + @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.id == null) ? (that.id == null) : this.id.equals(that.id)) + &&((this.aFragment1 == null) ? (that.aFragment1 == null) : this.aFragment1.equals(that.aFragment1)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (__typename == null) ? 0 : __typename.hashCode(); + __h *= 1000003; + __h ^= (id == null) ? 0 : id.hashCode(); + __h *= 1000003; + __h ^= (aFragment1 == null) ? 0 : aFragment1.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "A{" + + "__typename=" + __typename + ", " + + "id=" + id + ", " + + "aFragment1=" + aFragment1 + + "}"; + } + return $toString; + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/adapter/GetA_ResponseAdapter.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/adapter/GetA_ResponseAdapter.java.expected new file mode 100644 index 00000000000..b7b792d78eb --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/adapter/GetA_ResponseAdapter.java.expected @@ -0,0 +1,104 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.adapter; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.Adapters; +import com.apollographql.apollo.api.Assertions; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.NullableAdapter; +import com.apollographql.apollo.api.ObjectAdapter; +import com.apollographql.apollo.api.json.JsonReader; +import com.apollographql.apollo.api.json.JsonWriter; +import com.example.typepolicy.GetA; +import com.example.typepolicy.fragment.AFragment1; +import java.io.IOException; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +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"); + + @SuppressWarnings("unchecked") + @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", "id"); + + @SuppressWarnings("unchecked") + @Override + public GetA.A fromJson(JsonReader reader, CustomScalarAdapters customScalarAdapters) throws + IOException { + String __typename = null; + String _id = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: __typename = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + case 1: _id = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + reader.rewind(); + AFragment1 _aFragment1 = com.example.typepolicy.fragment.AFragment1Impl_ResponseAdapter.AFragment1.INSTANCE.fromJson(reader, customScalarAdapters); + + Assertions.checkFieldNotMissing(__typename, "__typename"); + Assertions.checkFieldNotMissing(_id, "id"); + + return new GetA.A( + __typename, + _id, + _aFragment1 + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, GetA.A value) + throws IOException { + writer.name("__typename"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.__typename); + + writer.name("id"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.id); + + com.example.typepolicy.fragment.AFragment1Impl_ResponseAdapter.AFragment1.INSTANCE.toJson(writer, customScalarAdapters, value.aFragment1); + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1.java.expected new file mode 100644 index 00000000000..731408ade75 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1.java.expected @@ -0,0 +1,83 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Fragment; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class AFragment1 implements Fragment.Data { + public String __typename; + + public String foo; + + public String id; + + /** + * Synthetic field for 'AFragment2' + */ + public AFragment2 aFragment2; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public AFragment1(String __typename, String foo, String id, AFragment2 aFragment2) { + this.__typename = __typename; + this.foo = foo; + this.id = id; + this.aFragment2 = aFragment2; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof AFragment1) { + AFragment1 that = (AFragment1) o; + return ((this.__typename == null) ? (that.__typename == null) : this.__typename.equals(that.__typename)) + &&((this.foo == null) ? (that.foo == null) : this.foo.equals(that.foo)) + &&((this.id == null) ? (that.id == null) : this.id.equals(that.id)) + &&((this.aFragment2 == null) ? (that.aFragment2 == null) : this.aFragment2.equals(that.aFragment2)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (__typename == null) ? 0 : __typename.hashCode(); + __h *= 1000003; + __h ^= (foo == null) ? 0 : foo.hashCode(); + __h *= 1000003; + __h ^= (id == null) ? 0 : id.hashCode(); + __h *= 1000003; + __h ^= (aFragment2 == null) ? 0 : aFragment2.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "AFragment1{" + + "__typename=" + __typename + ", " + + "foo=" + foo + ", " + + "id=" + id + ", " + + "aFragment2=" + aFragment2 + + "}"; + } + return $toString; + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl.java.expected new file mode 100644 index 00000000000..20e745937b0 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl.java.expected @@ -0,0 +1,82 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.Fragment; +import com.apollographql.apollo.api.ObjectAdapter; +import com.apollographql.apollo.api.json.JsonWriter; +import com.example.typepolicy.fragment.selections.AFragment1Selections; +import com.example.typepolicy.type.A; +import java.io.IOException; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class AFragment1Impl implements Fragment { + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public AFragment1Impl() { + + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof AFragment1Impl) { + 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 = "AFragment1Impl{" + + "}"; + } + 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(AFragment1Impl_ResponseAdapter.AFragment1.INSTANCE, true); + } + + @Override + public CompiledField rootField() { + return new CompiledField.Builder( + "data", + A.type + ) + .selections(AFragment1Selections.__root) + .build(); + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.java.expected new file mode 100644 index 00000000000..17ec29e690f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.java.expected @@ -0,0 +1,74 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.Adapters; +import com.apollographql.apollo.api.Assertions; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.json.JsonReader; +import com.apollographql.apollo.api.json.JsonWriter; +import java.io.IOException; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.Arrays; +import java.util.List; + +public class AFragment1Impl_ResponseAdapter { + public enum AFragment1 implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("__typename", "foo", "id"); + + @SuppressWarnings("unchecked") + @Override + public com.example.typepolicy.fragment.AFragment1 fromJson(JsonReader reader, + CustomScalarAdapters customScalarAdapters) throws IOException { + String __typename = null; + String _foo = null; + String _id = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: __typename = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + case 1: _foo = Adapters.NullableStringAdapter.fromJson(reader, customScalarAdapters); break; + case 2: _id = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + reader.rewind(); + AFragment2 _aFragment2 = com.example.typepolicy.fragment.AFragment2Impl_ResponseAdapter.AFragment2.INSTANCE.fromJson(reader, customScalarAdapters); + + Assertions.checkFieldNotMissing(__typename, "__typename"); + Assertions.checkFieldNotMissing(_id, "id"); + + return new com.example.typepolicy.fragment.AFragment1( + __typename, + _foo, + _id, + _aFragment2 + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + com.example.typepolicy.fragment.AFragment1 value) throws IOException { + writer.name("__typename"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.__typename); + + writer.name("foo"); + Adapters.NullableStringAdapter.toJson(writer, customScalarAdapters, value.foo); + + writer.name("id"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.id); + + com.example.typepolicy.fragment.AFragment2Impl_ResponseAdapter.AFragment2.INSTANCE.toJson(writer, customScalarAdapters, value.aFragment2); + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2.java.expected new file mode 100644 index 00000000000..eeca3a02586 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2.java.expected @@ -0,0 +1,80 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Fragment; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class AFragment2 implements Fragment.Data { + public String bar; + + public String myId; + + public String id; + + public String __typename; + + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public AFragment2(String bar, String myId, String id, String __typename) { + this.bar = bar; + this.myId = myId; + this.id = id; + this.__typename = __typename; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof AFragment2) { + AFragment2 that = (AFragment2) o; + return ((this.bar == null) ? (that.bar == null) : this.bar.equals(that.bar)) + &&((this.myId == null) ? (that.myId == null) : this.myId.equals(that.myId)) + &&((this.id == null) ? (that.id == null) : this.id.equals(that.id)) + &&((this.__typename == null) ? (that.__typename == null) : this.__typename.equals(that.__typename)); + } + return false; + } + + @Override + public int hashCode() { + if (!$hashCodeMemoized) { + int __h = 1; + __h *= 1000003; + __h ^= (bar == null) ? 0 : bar.hashCode(); + __h *= 1000003; + __h ^= (myId == null) ? 0 : myId.hashCode(); + __h *= 1000003; + __h ^= (id == null) ? 0 : id.hashCode(); + __h *= 1000003; + __h ^= (__typename == null) ? 0 : __typename.hashCode(); + $hashCode = __h; + $hashCodeMemoized = true; + } + return $hashCode; + } + + @Override + public String toString() { + if ($toString == null) { + $toString = "AFragment2{" + + "bar=" + bar + ", " + + "myId=" + myId + ", " + + "id=" + id + ", " + + "__typename=" + __typename + + "}"; + } + return $toString; + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl.java.expected new file mode 100644 index 00000000000..a78e9efd906 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl.java.expected @@ -0,0 +1,82 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.Fragment; +import com.apollographql.apollo.api.ObjectAdapter; +import com.apollographql.apollo.api.json.JsonWriter; +import com.example.typepolicy.fragment.selections.AFragment2Selections; +import com.example.typepolicy.type.A; +import java.io.IOException; +import java.lang.Object; +import java.lang.Override; +import java.lang.String; + +public class AFragment2Impl implements Fragment { + private transient volatile int $hashCode; + + private transient volatile boolean $hashCodeMemoized; + + private transient volatile String $toString; + + public AFragment2Impl() { + + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof AFragment2Impl) { + 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 = "AFragment2Impl{" + + "}"; + } + 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(AFragment2Impl_ResponseAdapter.AFragment2.INSTANCE, false); + } + + @Override + public CompiledField rootField() { + return new CompiledField.Builder( + "data", + A.type + ) + .selections(AFragment2Selections.__root) + .build(); + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.java.expected new file mode 100644 index 00000000000..bdefa76f89c --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.java.expected @@ -0,0 +1,75 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment; + +import com.apollographql.apollo.api.Adapter; +import com.apollographql.apollo.api.Adapters; +import com.apollographql.apollo.api.Assertions; +import com.apollographql.apollo.api.CustomScalarAdapters; +import com.apollographql.apollo.api.json.JsonReader; +import com.apollographql.apollo.api.json.JsonWriter; +import java.io.IOException; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.Arrays; +import java.util.List; + +public class AFragment2Impl_ResponseAdapter { + public enum AFragment2 implements Adapter { + INSTANCE; + + private static final List RESPONSE_NAMES = Arrays.asList("bar", "myId", "id", "__typename"); + + @SuppressWarnings("unchecked") + @Override + public com.example.typepolicy.fragment.AFragment2 fromJson(JsonReader reader, + CustomScalarAdapters customScalarAdapters) throws IOException { + String _bar = null; + String _myId = null; + String _id = null; + String __typename = null; + + loop: + while(true) { + switch (reader.selectName(RESPONSE_NAMES)) { + case 0: _bar = Adapters.NullableStringAdapter.fromJson(reader, customScalarAdapters); break; + case 1: _myId = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + case 2: _id = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + case 3: __typename = Adapters.StringAdapter.fromJson(reader, customScalarAdapters); break; + default: break loop; + } + } + + Assertions.checkFieldNotMissing(_myId, "myId"); + Assertions.checkFieldNotMissing(_id, "id"); + Assertions.checkFieldNotMissing(__typename, "__typename"); + + return new com.example.typepolicy.fragment.AFragment2( + _bar, + _myId, + _id, + __typename + ); + } + + @Override + public void toJson(JsonWriter writer, CustomScalarAdapters customScalarAdapters, + com.example.typepolicy.fragment.AFragment2 value) throws IOException { + writer.name("bar"); + Adapters.NullableStringAdapter.toJson(writer, customScalarAdapters, value.bar); + + writer.name("myId"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.myId); + + writer.name("id"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.id); + + writer.name("__typename"); + Adapters.StringAdapter.toJson(writer, customScalarAdapters, value.__typename); + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment1Selections.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment1Selections.java.expected new file mode 100644 index 00000000000..a346dbfaebd --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment1Selections.java.expected @@ -0,0 +1,26 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections; + +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CompiledFragment; +import com.apollographql.apollo.api.CompiledNotNullType; +import com.apollographql.apollo.api.CompiledSelection; +import com.example.typepolicy.type.GraphQLID; +import com.example.typepolicy.type.GraphQLString; +import java.lang.SuppressWarnings; +import java.util.Arrays; +import java.util.List; + +@SuppressWarnings("unchecked") +public class AFragment1Selections { + public static List __root = Arrays.asList( + new CompiledField.Builder("__typename", new CompiledNotNullType(GraphQLString.type)).build(), + new CompiledField.Builder("foo", GraphQLString.type).build(), + new CompiledFragment.Builder("A", Arrays.asList("A")).selections(AFragment2Selections.__root).build(), + new CompiledField.Builder("id", new CompiledNotNullType(GraphQLID.type)).build() + ); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment2Selections.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment2Selections.java.expected new file mode 100644 index 00000000000..b7b7db61700 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/fragment/selections/AFragment2Selections.java.expected @@ -0,0 +1,25 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections; + +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CompiledNotNullType; +import com.apollographql.apollo.api.CompiledSelection; +import com.example.typepolicy.type.GraphQLID; +import com.example.typepolicy.type.GraphQLString; +import java.lang.SuppressWarnings; +import java.util.Arrays; +import java.util.List; + +@SuppressWarnings("unchecked") +public class AFragment2Selections { + public static List __root = Arrays.asList( + new CompiledField.Builder("bar", GraphQLString.type).build(), + new CompiledField.Builder("id", new CompiledNotNullType(GraphQLID.type)).alias("myId").build(), + new CompiledField.Builder("id", new CompiledNotNullType(GraphQLID.type)).build(), + new CompiledField.Builder("__typename", new CompiledNotNullType(GraphQLString.type)).build() + ); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/selections/GetASelections.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/selections/GetASelections.java.expected new file mode 100644 index 00000000000..07e70d52149 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/selections/GetASelections.java.expected @@ -0,0 +1,31 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.selections; + +import com.apollographql.apollo.api.CompiledField; +import com.apollographql.apollo.api.CompiledFragment; +import com.apollographql.apollo.api.CompiledNotNullType; +import com.apollographql.apollo.api.CompiledSelection; +import com.example.typepolicy.fragment.selections.AFragment1Selections; +import com.example.typepolicy.type.A; +import com.example.typepolicy.type.GraphQLID; +import com.example.typepolicy.type.GraphQLString; +import java.lang.SuppressWarnings; +import java.util.Arrays; +import java.util.List; + +@SuppressWarnings("unchecked") +public class GetASelections { + private static List __a = Arrays.asList( + new CompiledField.Builder("__typename", new CompiledNotNullType(GraphQLString.type)).build(), + new CompiledFragment.Builder("A", Arrays.asList("A")).selections(AFragment1Selections.__root).build(), + new CompiledField.Builder("id", new CompiledNotNullType(GraphQLID.type)).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/typepolicy/java/operationBased/typepolicy/type/A.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/A.java.expected new file mode 100644 index 00000000000..795b14d4e03 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/A.java.expected @@ -0,0 +1,13 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.type; + +import com.apollographql.apollo.api.ObjectType; +import java.util.Arrays; + +public class A { + public static ObjectType type = (new ObjectType.Builder("A")).keyFields(Arrays.asList("id")).build(); +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/GraphQLID.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/GraphQLID.java.expected new file mode 100644 index 00000000000..f9bf235cf14 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/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.typepolicy.type; + +import com.apollographql.apollo.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/typepolicy/java/operationBased/typepolicy/type/GraphQLString.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/GraphQLString.java.expected new file mode 100644 index 00000000000..ef062fda116 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/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.typepolicy.type; + +import com.apollographql.apollo.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/typepolicy/java/operationBased/typepolicy/type/Query.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/type/Query.java.expected new file mode 100644 index 00000000000..f3df2149f42 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/typepolicy/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.typepolicy.type; + +import com.apollographql.apollo.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/typepolicy/java/operationBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/used-coordinates.json.expected new file mode 100644 index 00000000000..17fd609a898 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/java/operationBased/used-coordinates.json.expected @@ -0,0 +1,12 @@ +{ + "typeToFieldsToArguments": { + "A": { + }, + "String": { + }, + "ID": { + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/GetA.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/GetA.kt.expected new file mode 100644 index 00000000000..d342fb209cd --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/GetA.kt.expected @@ -0,0 +1,108 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy + +import com.apollographql.apollo.annotations.ApolloAdaptableWith +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Query +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.adapter.GetA_ResponseAdapter +import com.example.typepolicy.fragment.AFragment1 +import com.example.typepolicy.selections.GetASelections +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import com.example.typepolicy.type.Query as CompiledQuery + +public class GetA() : Query { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + @ApolloAdaptableWith(GetA_ResponseAdapter.Data::class) + public data class Data( + public val a: A?, + ) : Query.Data { + public data class A( + public val __typename: String, + public val id: String, + /** + * Synthetic field for 'AFragment1' + */ + public val aFragment1: AFragment1, + ) + } + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = GetA_ResponseAdapter.Data.obj() + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = CompiledQuery.type + ) + .selections(selections = GetASelections.__root) + .build() + + public const val OPERATION_ID: String = + "64f5865843b43e7efa316fea6e9f6b175f0bc5d262d317306109dd68613547e4" + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * ``` + * query GetA { + * a { + * __typename + * ...AFragment1 + * id + * } + * } + * + * fragment AFragment2 on A { + * bar + * myId: id + * id + * __typename + * } + * + * fragment AFragment1 on A { + * __typename + * foo + * ...AFragment2 + * id + * } + * ``` + */ + public val OPERATION_DOCUMENT: String + get() = "query GetA { a { __typename ...AFragment1 id } } fragment AFragment2 on A { bar myId: id id __typename } fragment AFragment1 on A { __typename foo ...AFragment2 id }" + + public const val OPERATION_NAME: String = "GetA" + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..94accd21eff --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected @@ -0,0 +1,89 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.adapter + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import com.apollographql.apollo.api.nullable +import com.apollographql.apollo.api.obj +import com.example.typepolicy.GetA +import com.example.typepolicy.fragment.AFragment1Impl_ResponseAdapter +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", "id") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetA.Data.A { + var __typename: String? = null + var _id: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + reader.rewind() + val _aFragment1 = com.example.typepolicy.fragment.AFragment1Impl_ResponseAdapter.AFragment1.fromJson(reader, customScalarAdapters) + + return GetA.Data.A( + __typename = __typename ?: missingField(reader, "__typename"), + id = _id ?: missingField(reader, "id"), + aFragment1 = _aFragment1 + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + + AFragment1Impl_ResponseAdapter.AFragment1.toJson(writer, customScalarAdapters, value.aFragment1) + } + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1.kt.expected new file mode 100644 index 00000000000..17b5f21fa62 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1.kt.expected @@ -0,0 +1,19 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.example.typepolicy.type.A +import kotlin.String + +public data class AFragment1( + public val __typename: String, + public val foo: String?, + public val id: String, + /** + * Synthetic field for 'AFragment2' + */ + public val aFragment2: AFragment2, +) : A.Data diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl.kt.expected new file mode 100644 index 00000000000..5be6b6d685f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl.kt.expected @@ -0,0 +1,48 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.fragment.selections.AFragment1Selections +import com.example.typepolicy.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int + +public class AFragment1Impl() : Fragment { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = AFragment1Impl_ResponseAdapter.AFragment1.obj(true) + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = AFragment1Selections.__root) + .build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..06ad917e79f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected @@ -0,0 +1,64 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.NullableStringAdapter +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import kotlin.String +import kotlin.collections.List + +public object AFragment1Impl_ResponseAdapter { + public object AFragment1 : Adapter { + public val RESPONSE_NAMES: List = listOf("__typename", "foo", "id") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.typepolicy.fragment.AFragment1 { + var __typename: String? = null + var _foo: String? = null + var _id: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _foo = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + reader.rewind() + val _aFragment2 = com.example.typepolicy.fragment.AFragment2Impl_ResponseAdapter.AFragment2.fromJson(reader, customScalarAdapters) + + return com.example.typepolicy.fragment.AFragment1( + __typename = __typename ?: missingField(reader, "__typename"), + foo = _foo, + id = _id ?: missingField(reader, "id"), + aFragment2 = _aFragment2 + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: com.example.typepolicy.fragment.AFragment1, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("foo") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.foo) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + + AFragment2Impl_ResponseAdapter.AFragment2.toJson(writer, customScalarAdapters, value.aFragment2) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2.kt.expected new file mode 100644 index 00000000000..f44afef0064 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2.kt.expected @@ -0,0 +1,16 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.example.typepolicy.type.A +import kotlin.String + +public data class AFragment2( + public val bar: String?, + public val myId: String, + public val id: String, + public val __typename: String, +) : A.Data diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl.kt.expected new file mode 100644 index 00000000000..b5d297f7d19 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl.kt.expected @@ -0,0 +1,48 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.fragment.selections.AFragment2Selections +import com.example.typepolicy.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int + +public class AFragment2Impl() : Fragment { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = AFragment2Impl_ResponseAdapter.AFragment2.obj() + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = AFragment2Selections.__root) + .build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..bd9f7218f50 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected @@ -0,0 +1,64 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.NullableStringAdapter +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import kotlin.String +import kotlin.collections.List + +public object AFragment2Impl_ResponseAdapter { + public object AFragment2 : Adapter { + public val RESPONSE_NAMES: List = listOf("bar", "myId", "id", "__typename") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.typepolicy.fragment.AFragment2 { + var _bar: String? = null + var _myId: String? = null + var _id: String? = null + var __typename: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _bar = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _myId = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return com.example.typepolicy.fragment.AFragment2( + bar = _bar, + myId = _myId ?: missingField(reader, "myId"), + id = _id ?: missingField(reader, "id"), + __typename = __typename ?: missingField(reader, "__typename") + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: com.example.typepolicy.fragment.AFragment2, + ) { + writer.name("bar") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.bar) + + writer.name("myId") + StringAdapter.toJson(writer, customScalarAdapters, value.myId) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected new file mode 100644 index 00000000000..5720c84bb18 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected @@ -0,0 +1,36 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledFragment +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object AFragment1Selections { + public val __root: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledField.Builder( + name = "foo", + type = GraphQLString.type + ).build(), + CompiledFragment.Builder( + typeCondition = "A", + possibleTypes = listOf("A") + ).selections(AFragment2Selections.__root) + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected new file mode 100644 index 00000000000..3fe297471ec --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected @@ -0,0 +1,35 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object AFragment2Selections { + public val __root: List = listOf( + CompiledField.Builder( + name = "bar", + type = GraphQLString.type + ).build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).alias("myId") + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).build(), + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/selections/GetASelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/selections/GetASelections.kt.expected new file mode 100644 index 00000000000..1aa19b48c8f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/selections/GetASelections.kt.expected @@ -0,0 +1,42 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledFragment +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.fragment.selections.AFragment1Selections +import com.example.typepolicy.type.A +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object GetASelections { + private val __a: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledFragment.Builder( + typeCondition = "A", + possibleTypes = listOf("A") + ).selections(AFragment1Selections.__root) + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).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/typepolicy/kotlin/operationBased/typepolicy/type/A.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/A.kt.expected new file mode 100644 index 00000000000..2fe2e2fef92 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/A.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.typepolicy.type + +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.ObjectType + +public class A { + public interface Data : Fragment.Data + + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "A").keyFields(listOf("id")).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/GraphQLID.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/GraphQLID.kt.expected new file mode 100644 index 00000000000..6ac7c0dd7de --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/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.typepolicy.type + +import com.apollographql.apollo.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/typepolicy/kotlin/operationBased/typepolicy/type/GraphQLString.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/GraphQLString.kt.expected new file mode 100644 index 00000000000..d9054fc2c4d --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/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.typepolicy.type + +import com.apollographql.apollo.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/typepolicy/kotlin/operationBased/typepolicy/type/Query.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/Query.kt.expected new file mode 100644 index 00000000000..35506acd821 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/typepolicy/type/Query.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.typepolicy.type + +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.ObjectType + +public class Query { + public interface Data : Fragment.Data + + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "Query").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/used-coordinates.json.expected new file mode 100644 index 00000000000..17fd609a898 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/operationBased/used-coordinates.json.expected @@ -0,0 +1,12 @@ +{ + "typeToFieldsToArguments": { + "A": { + }, + "String": { + }, + "ID": { + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/GetA.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/GetA.kt.expected new file mode 100644 index 00000000000..25408c78769 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/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.typepolicy + +import com.apollographql.apollo.annotations.ApolloAdaptableWith +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Query +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.adapter.GetA_ResponseAdapter +import com.example.typepolicy.fragment.AFragment1 +import com.example.typepolicy.selections.GetASelections +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import kotlin.Suppress +import com.example.typepolicy.type.Query as CompiledQuery + +public class GetA() : Query { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + @ApolloAdaptableWith(GetA_ResponseAdapter.Data::class) + public data class Data( + public val a: A?, + ) : Query.Data { + public data class A( + override val __typename: String, + override val foo: String?, + override val bar: String?, + override val myId: String, + override val id: String, + ) : AFragment1 { + public companion object { + @Suppress("USELESS_CAST") + public fun A.aFragment1(): AFragment1? = this as? AFragment1 + } + } + } + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = GetA_ResponseAdapter.Data.obj() + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = CompiledQuery.type + ) + .selections(selections = GetASelections.__root) + .build() + + public const val OPERATION_ID: String = + "64f5865843b43e7efa316fea6e9f6b175f0bc5d262d317306109dd68613547e4" + + /** + * The minimized GraphQL document being sent to the server to save a few bytes. + * The un-minimized version is: + * + * ``` + * query GetA { + * a { + * __typename + * ...AFragment1 + * id + * } + * } + * + * fragment AFragment2 on A { + * bar + * myId: id + * id + * __typename + * } + * + * fragment AFragment1 on A { + * __typename + * foo + * ...AFragment2 + * id + * } + * ``` + */ + public val OPERATION_DOCUMENT: String + get() = "query GetA { a { __typename ...AFragment1 id } } fragment AFragment2 on A { bar myId: id id __typename } fragment AFragment1 on A { __typename foo ...AFragment2 id }" + + public const val OPERATION_NAME: String = "GetA" + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..ff4a01702f1 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/adapter/GetA_ResponseAdapter.kt.expected @@ -0,0 +1,101 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.adapter + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.NullableStringAdapter +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import com.apollographql.apollo.api.nullable +import com.apollographql.apollo.api.obj +import com.example.typepolicy.GetA +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().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 { + public val RESPONSE_NAMES: List = listOf("__typename", "foo", "bar", "myId", "id") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetA.Data.A { + var __typename: String? = null + var _foo: String? = null + var _bar: String? = null + var _myId: String? = null + var _id: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _foo = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> _bar = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> _myId = StringAdapter.fromJson(reader, customScalarAdapters) + 4 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return GetA.Data.A( + __typename = __typename ?: missingField(reader, "__typename"), + foo = _foo, + bar = _bar, + myId = _myId ?: missingField(reader, "myId"), + id = _id ?: missingField(reader, "id") + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: GetA.Data.A, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("foo") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.foo) + + writer.name("bar") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.bar) + + writer.name("myId") + StringAdapter.toJson(writer, customScalarAdapters, value.myId) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + } + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1.kt.expected new file mode 100644 index 00000000000..a6cc6e1034a --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1.kt.expected @@ -0,0 +1,26 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import kotlin.String +import kotlin.Suppress + +public interface AFragment1 : AFragment2 { + override val __typename: String + + public val foo: String? + + override val bar: String? + + override val myId: String + + override val id: String + + public companion object { + @Suppress("USELESS_CAST") + public fun AFragment1.aFragment2(): AFragment2? = this as? AFragment2 + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl.kt.expected new file mode 100644 index 00000000000..fa1c6f0e085 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl.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.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.fragment.selections.AFragment1Selections +import com.example.typepolicy.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import kotlin.Suppress + +public class AFragment1Impl() : Fragment { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + public data class Data( + override val __typename: String, + override val foo: String?, + override val bar: String?, + override val myId: String, + override val id: String, + ) : AFragment2, + AFragment1, + A.Data { + public companion object { + @Suppress("USELESS_CAST") + public fun Data.aFragment2(): AFragment2? = this as? AFragment2 + } + } + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = AFragment1Impl_ResponseAdapter.Data.obj() + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = AFragment1Selections.__root) + .build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..f1f58fabe16 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment1Impl_ResponseAdapter.kt.expected @@ -0,0 +1,70 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.NullableStringAdapter +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import kotlin.String +import kotlin.collections.List + +public object AFragment1Impl_ResponseAdapter { + public object Data : Adapter { + public val RESPONSE_NAMES: List = listOf("__typename", "foo", "bar", "myId", "id") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): AFragment1Impl.Data { + var __typename: String? = null + var _foo: String? = null + var _bar: String? = null + var _myId: String? = null + var _id: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _foo = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> _bar = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> _myId = StringAdapter.fromJson(reader, customScalarAdapters) + 4 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return AFragment1Impl.Data( + __typename = __typename ?: missingField(reader, "__typename"), + foo = _foo, + bar = _bar, + myId = _myId ?: missingField(reader, "myId"), + id = _id ?: missingField(reader, "id") + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: AFragment1Impl.Data, + ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("foo") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.foo) + + writer.name("bar") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.bar) + + writer.name("myId") + StringAdapter.toJson(writer, customScalarAdapters, value.myId) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2.kt.expected new file mode 100644 index 00000000000..ef767fd398c --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2.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.typepolicy.fragment + +import kotlin.String + +public interface AFragment2 { + public val bar: String? + + public val myId: String + + public val id: String + + public val __typename: String +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl.kt.expected new file mode 100644 index 00000000000..f0dc961969c --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl.kt.expected @@ -0,0 +1,57 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.ExecutableDefinition +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.obj +import com.example.typepolicy.fragment.selections.AFragment2Selections +import com.example.typepolicy.type.A +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String + +public class AFragment2Impl() : Fragment { + 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 = ADAPTER + + override fun rootField(): CompiledField = ROOT_FIELD + + public data class Data( + override val bar: String?, + override val myId: String, + override val id: String, + override val __typename: String, + ) : AFragment2, + A.Data + + public companion object : ExecutableDefinition { + override val ADAPTER: Adapter = AFragment2Impl_ResponseAdapter.Data.obj() + + override val ROOT_FIELD: CompiledField = CompiledField.Builder( + name = "data", + type = A.type + ) + .selections(selections = AFragment2Selections.__root) + .build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected new file mode 100644 index 00000000000..96973abd21c --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/AFragment2Impl_ResponseAdapter.kt.expected @@ -0,0 +1,64 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment + +import com.apollographql.apollo.api.Adapter +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.NullableStringAdapter +import com.apollographql.apollo.api.StringAdapter +import com.apollographql.apollo.api.json.JsonReader +import com.apollographql.apollo.api.json.JsonWriter +import com.apollographql.apollo.api.missingField +import kotlin.String +import kotlin.collections.List + +public object AFragment2Impl_ResponseAdapter { + public object Data : Adapter { + public val RESPONSE_NAMES: List = listOf("bar", "myId", "id", "__typename") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): AFragment2Impl.Data { + var _bar: String? = null + var _myId: String? = null + var _id: String? = null + var __typename: String? = null + + while (true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> _bar = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 1 -> _myId = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> _id = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return AFragment2Impl.Data( + bar = _bar, + myId = _myId ?: missingField(reader, "myId"), + id = _id ?: missingField(reader, "id"), + __typename = __typename ?: missingField(reader, "__typename") + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + `value`: AFragment2Impl.Data, + ) { + writer.name("bar") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.bar) + + writer.name("myId") + StringAdapter.toJson(writer, customScalarAdapters, value.myId) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + } + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected new file mode 100644 index 00000000000..5720c84bb18 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment1Selections.kt.expected @@ -0,0 +1,36 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledFragment +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object AFragment1Selections { + public val __root: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledField.Builder( + name = "foo", + type = GraphQLString.type + ).build(), + CompiledFragment.Builder( + typeCondition = "A", + possibleTypes = listOf("A") + ).selections(AFragment2Selections.__root) + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected new file mode 100644 index 00000000000..3fe297471ec --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/fragment/selections/AFragment2Selections.kt.expected @@ -0,0 +1,35 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.fragment.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object AFragment2Selections { + public val __root: List = listOf( + CompiledField.Builder( + name = "bar", + type = GraphQLString.type + ).build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).alias("myId") + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).build(), + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build() + ) +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/selections/GetASelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/selections/GetASelections.kt.expected new file mode 100644 index 00000000000..1aa19b48c8f --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/selections/GetASelections.kt.expected @@ -0,0 +1,42 @@ +// +// AUTO-GENERATED FILE. DO NOT MODIFY. +// +// This class was automatically generated by Apollo GraphQL version '$VERSION'. +// +package com.example.typepolicy.selections + +import com.apollographql.apollo.api.CompiledField +import com.apollographql.apollo.api.CompiledFragment +import com.apollographql.apollo.api.CompiledSelection +import com.apollographql.apollo.api.notNull +import com.example.typepolicy.fragment.selections.AFragment1Selections +import com.example.typepolicy.type.A +import com.example.typepolicy.type.GraphQLID +import com.example.typepolicy.type.GraphQLString +import kotlin.collections.List + +public object GetASelections { + private val __a: List = listOf( + CompiledField.Builder( + name = "__typename", + type = GraphQLString.type.notNull() + ).build(), + CompiledFragment.Builder( + typeCondition = "A", + possibleTypes = listOf("A") + ).selections(AFragment1Selections.__root) + .build(), + CompiledField.Builder( + name = "id", + type = GraphQLID.type.notNull() + ).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/typepolicy/kotlin/responseBased/typepolicy/type/A.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/A.kt.expected new file mode 100644 index 00000000000..2fe2e2fef92 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/A.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.typepolicy.type + +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.ObjectType + +public class A { + public interface Data : Fragment.Data + + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "A").keyFields(listOf("id")).build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/GraphQLID.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/GraphQLID.kt.expected new file mode 100644 index 00000000000..6ac7c0dd7de --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/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.typepolicy.type + +import com.apollographql.apollo.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/typepolicy/kotlin/responseBased/typepolicy/type/GraphQLString.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/GraphQLString.kt.expected new file mode 100644 index 00000000000..d9054fc2c4d --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/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.typepolicy.type + +import com.apollographql.apollo.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/typepolicy/kotlin/responseBased/typepolicy/type/Query.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/Query.kt.expected new file mode 100644 index 00000000000..35506acd821 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/typepolicy/type/Query.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.typepolicy.type + +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.ObjectType + +public class Query { + public interface Data : Fragment.Data + + public companion object { + public val type: ObjectType = ObjectType.Builder(name = "Query").build() + } +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/used-coordinates.json.expected b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/used-coordinates.json.expected new file mode 100644 index 00000000000..17fd609a898 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/kotlin/responseBased/used-coordinates.json.expected @@ -0,0 +1,12 @@ +{ + "typeToFieldsToArguments": { + "A": { + }, + "String": { + }, + "ID": { + }, + "Query": { + } + } +} \ No newline at end of file diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/schema.graphqls b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/schema.graphqls new file mode 100644 index 00000000000..f0f3ca6f880 --- /dev/null +++ b/libraries/apollo-compiler/src/test/graphql/com/example/typepolicy/schema.graphqls @@ -0,0 +1,15 @@ +extend schema +@link( + url: "https://specs.apollo.dev/kotlin_labs/v0.3", + import: ["@typePolicy"] +) + +type A @typePolicy(keyFields: "id") { + id: ID! + foo: String + bar: String +} + +type Query { + a: A +} \ No newline at end of file