From f2334160c7d13b550a313923eb0874fd7c1ced47 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 25 Jun 2021 19:22:23 +0200 Subject: [PATCH] Do not merge inline fragments with directives (#3189) * [compat] Fix inline fragments with include directive Even if these inline fragments have the same type condition as their parent type, we can't merge them as the nullability status of their fields might be different Closes #2796 * Compound -> Composite * update test fixtures --- .../apollo3/api/CompiledGraphQL.kt | 2 +- .../ir/OperationBasedModelGroupBuilder.kt | 75 +++-- .../compat/TestQuery.kt.expected | 8 +- .../TestQuery_ResponseAdapter.kt.expected | 40 +-- .../compat/fragment/IFragment.kt.expected | 4 +- .../IFragmentImpl_ResponseAdapter.kt.expected | 18 +- .../hero_name/compat/TestQuery.kt.expected | 10 +- .../TestQuery_ResponseAdapter.kt.expected | 22 +- .../compat/TestQuery.kt.expected | 10 +- .../TestQuery_ResponseAdapter.kt.expected | 20 +- .../compat/TestQuery.kt.expected | 20 +- .../TestQuery_ResponseAdapter.kt.expected | 40 +-- .../compat/TestOperation.kt.expected | 22 +- .../TestOperation_ResponseAdapter.kt.expected | 130 ++++---- .../compat/TestQuery.kt.expected | 4 +- .../TestQuery_ResponseAdapter.kt.expected | 20 +- .../compat/TestQuery.kt.expected | 40 ++- .../TestQuery_ResponseAdapter.kt.expected | 153 +++++---- .../operationBased/TestQuery.kt.expected | 12 +- .../TestQuery_ResponseAdapter.kt.expected | 61 ++-- .../compat/TestQuery.kt.expected | 24 +- .../TestQuery_ResponseAdapter.kt.expected | 64 ++-- .../compat/TestQuery.kt.expected | 4 +- .../TestQuery_ResponseAdapter.kt.expected | 20 +- .../compat/GetHuman.kt.expected | 4 +- .../GetHuman_ResponseAdapter.kt.expected | 18 +- .../src/test/graphql/com/example/measurements | 300 +++++++++--------- .../compat/TestQuery.kt.expected | 40 +-- .../TestQuery_ResponseAdapter.kt.expected | 84 ++--- .../compat/TestQuery.kt.expected | 16 +- .../TestQuery_ResponseAdapter.kt.expected | 96 +++--- .../compat/TestQuery.kt.expected | 8 +- .../TestQuery_ResponseAdapter.kt.expected | 36 +-- .../compat/TestQuery.kt.expected | 4 +- .../TestQuery_ResponseAdapter.kt.expected | 18 +- .../compat/TestQuery.kt.expected | 10 +- .../TestQuery_ResponseAdapter.kt.expected | 22 +- .../compat/fragment/HeroDetails.kt.expected | 20 +- ...eroDetailsImpl_ResponseAdapter.kt.expected | 40 +-- .../compat/TestQuery.kt.expected | 20 +- .../TestQuery_ResponseAdapter.kt.expected | 44 +-- .../test_inline/compat/GetPage.kt.expected | 10 +- .../GetPage_ResponseAdapter.kt.expected | 56 ++-- .../compat/TestQuery.kt.expected | 6 +- .../TestQuery_ResponseAdapter.kt.expected | 34 +- .../compat/TestQuery.kt.expected | 4 +- .../TestQuery_ResponseAdapter.kt.expected | 18 +- .../compat/TestQuery.kt.expected | 32 +- .../TestQuery_ResponseAdapter.kt.expected | 104 +++--- .../compat/HeroDetailQuery.kt.expected | 22 +- ...eroDetailQuery_ResponseAdapter.kt.expected | 52 +-- .../gradle/internal/DefaultApolloExtension.kt | 2 +- .../merge_trivial_inline_fragments.kt | 2 +- .../apollo3/cache/normalized/CacheResolver.kt | 9 - .../cache/normalized/internal/Normalizer.kt | 4 +- .../tests/models-compat/build.gradle.kts | 19 +- .../ConditionalInlineFragmentTest.kt | 24 ++ .../graphql/operations.graphql | 6 + .../graphql/schema.graphqls | 4 + design-docs/Glossary.md | 2 +- 60 files changed, 1060 insertions(+), 953 deletions(-) create mode 100644 composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/ConditionalInlineFragmentTest.kt create mode 100644 composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/operations.graphql create mode 100644 composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/schema.graphqls diff --git a/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CompiledGraphQL.kt b/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CompiledGraphQL.kt index 058f4a21bdd..fe23fa10803 100644 --- a/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CompiledGraphQL.kt +++ b/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CompiledGraphQL.kt @@ -188,7 +188,7 @@ val CompiledBooleanType = ScalarType("Boolean") @SharedImmutable val CompiledIDType = ScalarType("ID") -fun CompiledNamedType.isCompound(): Boolean { +fun CompiledNamedType.isComposite(): Boolean { return when (this) { is UnionType, is InterfaceType, diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/OperationBasedModelGroupBuilder.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/OperationBasedModelGroupBuilder.kt index 7de5e167235..b141e799f8a 100644 --- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/OperationBasedModelGroupBuilder.kt +++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ir/OperationBasedModelGroupBuilder.kt @@ -190,37 +190,50 @@ internal class OperationBasedModelGroupBuilder( */ val inlineFragmentsFields = selections.map { it.selection }.filterIsInstance() .groupBy { - InlineFragmentKey(it.typeCondition.name, it.directives.toBooleanExpression()) - }.entries.map { entry -> - val inlineFragmentsWithSameKey = entry.value - val typeCondition = entry.key.typeCondition - val prefix = if (collectAllInlineFragmentFields) "as" else "on" - - val childInfo = IrFieldInfo( - responseName = "$prefix${entry.key.toName()}", - description = "Synthetic field for inline fragment on $typeCondition", - deprecationReason = null, - type = IrModelType(IrUnknownModelId) - ) - - val possibleTypes = schema.possibleTypes(typeCondition) - val childCondition = entry.key.condition.and(BooleanExpression.Element(BPossibleTypes(possibleTypes))).simplify() - - val childSelections = inlineFragmentsWithSameKey.flatMap { - it.selectionSet.selections.map { SelectionWithParent(it, typeCondition) } - }.toMutableList() - if (collectAllInlineFragmentFields) { - childSelections.addAll(selections.filter { it.selection is GQLField}) - } - - buildField( - root = root, - path = selfPath, - info = childInfo, - selections = childSelections, - condition = childCondition, - isSynthetic = true - ) + it.typeCondition.name + }.entries.flatMap { + val typeCondition = it.key + + // If there is only one fragment, no need to disambiguate it + val nameNeedsCondition = it.value.size > 1 + + it.value.groupBy { it.directives.toBooleanExpression() } + .entries.map { entry -> + val prefix = if (collectAllInlineFragmentFields) "as" else "on" + + val name = if (nameNeedsCondition) { + InlineFragmentKey(typeCondition, entry.key).toName() + } else { + InlineFragmentKey(typeCondition, BooleanExpression.True).toName() + } + + val childInfo = IrFieldInfo( + responseName = "$prefix$name", + description = "Synthetic field for inline fragment on $typeCondition", + deprecationReason = null, + type = IrModelType(IrUnknownModelId) + ) + + val possibleTypes = schema.possibleTypes(typeCondition) + val childCondition = entry.key.and(BooleanExpression.Element(BPossibleTypes(possibleTypes))).simplify() + + var childSelections = entry.value.flatMap { + it.selectionSet.selections.map { SelectionWithParent(it, typeCondition) } + } + + if (collectAllInlineFragmentFields) { + childSelections = selections.filter { it.selection is GQLField} + childSelections + } + + buildField( + root = root, + path = selfPath, + info = childInfo, + selections = childSelections, + condition = childCondition, + isSynthetic = true + ) + } } /** diff --git a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/TestQuery.kt.expected index 8fb937db10b..3ec08099b5a 100644 --- a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/TestQuery.kt.expected @@ -59,9 +59,9 @@ class TestQuery : Query { ) data class AsB( - val fieldB1: String?, val __typename: String, - val fieldA1: String? + val fieldA1: String?, + val fieldB1: String? ) data class AsB1( @@ -74,9 +74,9 @@ class TestQuery : Query { ) data class AsA1( - val fieldA2: String?, val __typename: String, - val fieldB2: String? + val fieldB2: String?, + val fieldA2: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 61a62ba01dc..cc9fd1c8fb1 100644 --- a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -161,27 +161,27 @@ object TestQuery_ResponseAdapter { } object AsB : Adapter { - val RESPONSE_NAMES: List = listOf("fieldB1", "__typename", "fieldA1") + val RESPONSE_NAMES: List = listOf("__typename", "fieldA1", "fieldB1") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsB { - var fieldB1: String? = null var __typename: String? = null var fieldA1: String? = null + var fieldB1: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> fieldA1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldA1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsB( - fieldB1 = fieldB1, __typename = __typename!!, - fieldA1 = fieldA1 + fieldA1 = fieldA1, + fieldB1 = fieldB1 ) } @@ -190,14 +190,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsB ) { - writer.name("fieldB1") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("fieldA1") NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA1) + + writer.name("fieldB1") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) } } @@ -254,27 +254,27 @@ object TestQuery_ResponseAdapter { } object AsA1 : Adapter { - val RESPONSE_NAMES: List = listOf("fieldA2", "__typename", "fieldB2") + val RESPONSE_NAMES: List = listOf("__typename", "fieldB2", "fieldA2") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsA1 { - var fieldA2: String? = null var __typename: String? = null var fieldB2: String? = null + var fieldA2: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldA2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> fieldB2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldB2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> fieldA2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsA1( - fieldA2 = fieldA2, __typename = __typename!!, - fieldB2 = fieldB2 + fieldB2 = fieldB2, + fieldA2 = fieldA2 ) } @@ -283,14 +283,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsA1 ) { - writer.name("fieldA2") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA2) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("fieldB2") NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB2) + + writer.name("fieldA2") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA2) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragment.kt.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragment.kt.expected index 69eddc17433..9f3bc975672 100644 --- a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragment.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragment.kt.expected @@ -16,7 +16,7 @@ data class IFragment( val asA: AsA? ) : Fragment.Data { data class AsA( - val fieldA: String?, - val __typename: String + val __typename: String, + val fieldA: String? ) } diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragmentImpl_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragmentImpl_ResponseAdapter.kt.expected index e4050549447..37546adc00c 100644 --- a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragmentImpl_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/compat/fragment/IFragmentImpl_ResponseAdapter.kt.expected @@ -64,24 +64,24 @@ object IFragmentImpl_ResponseAdapter { } object AsA : Adapter { - val RESPONSE_NAMES: List = listOf("fieldA", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "fieldA") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.fragment_with_multiple_fieldsets.fragment.IFragment.AsA { - var fieldA: String? = null var __typename: String? = null + var fieldA: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldA = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldA = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return com.example.fragment_with_multiple_fieldsets.fragment.IFragment.AsA( - fieldA = fieldA, - __typename = __typename!! + __typename = __typename!!, + fieldA = fieldA ) } @@ -90,11 +90,11 @@ object IFragmentImpl_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: com.example.fragment_with_multiple_fieldsets.fragment.IFragment.AsA ) { - writer.name("fieldA") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("fieldA") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/hero_name/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/hero_name/compat/TestQuery.kt.expected index bd3a02972ff..903acbe8064 100644 --- a/apollo-compiler/src/test/graphql/com/example/hero_name/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/hero_name/compat/TestQuery.kt.expected @@ -55,10 +55,6 @@ class TestQuery : Query { ) data class AsDroid( - /** - * This droid's primary function - */ - val primaryFunction: String?, val __typename: String, /** * The name of the character @@ -67,7 +63,11 @@ class TestQuery : Query { /** * The date character was born. */ - val birthDate: Any + val birthDate: Any, + /** + * This droid's primary function + */ + val primaryFunction: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/hero_name/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/hero_name/compat/adapter/TestQuery_ResponseAdapter.kt.expected index da25bcd18d9..70e4841b384 100644 --- a/apollo-compiler/src/test/graphql/com/example/hero_name/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/hero_name/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -110,30 +110,30 @@ object TestQuery_ResponseAdapter { } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "__typename", "name", "birthDate") + val RESPONSE_NAMES: List = listOf("__typename", "name", "birthDate", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var primaryFunction: String? = null var __typename: String? = null var name: String? = null var birthDate: Any? = null + var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> birthDate = AnyAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> birthDate = AnyAdapter.fromJson(reader, customScalarAdapters) + 3 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - primaryFunction = primaryFunction, __typename = __typename!!, name = name!!, - birthDate = birthDate!! + birthDate = birthDate!!, + primaryFunction = primaryFunction ) } @@ -142,9 +142,6 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) @@ -153,6 +150,9 @@ object TestQuery_ResponseAdapter { writer.name("birthDate") AnyAdapter.toJson(writer, customScalarAdapters, value.birthDate) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/TestQuery.kt.expected index db555d5682e..5d5688acabe 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/TestQuery.kt.expected @@ -51,15 +51,15 @@ class TestQuery : Query { ) data class AsHuman( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 14703d364ff..7b399cb1a34 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -102,27 +102,27 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null var __typename: String? = null var name: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, __typename = __typename!!, - name = name!! + name = name!!, + height = height ) } @@ -131,14 +131,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/TestQuery.kt.expected index cae7df77b41..ccf42a086f1 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/TestQuery.kt.expected @@ -64,27 +64,27 @@ class TestQuery : Query { ) data class AsHuman( - /** - * The home planet of the human, or null if unknown - */ - val homePlanet: String?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * The home planet of the human, or null if unknown + */ + val homePlanet: String? ) data class AsDroid( - /** - * This droid's primary function - */ - val primaryFunction: String?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * This droid's primary function + */ + val primaryFunction: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 7d36c85fb59..447e1db6d57 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -164,27 +164,27 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("homePlanet", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "homePlanet") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var homePlanet: String? = null var __typename: String? = null var name: String? = null + var homePlanet: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - homePlanet = homePlanet, __typename = __typename!!, - name = name!! + name = name!!, + homePlanet = homePlanet ) } @@ -193,39 +193,39 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("homePlanet") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("homePlanet") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) } } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var primaryFunction: String? = null var __typename: String? = null var name: String? = null + var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - primaryFunction = primaryFunction, __typename = __typename!!, - name = name!! + name = name!!, + primaryFunction = primaryFunction ) } @@ -234,14 +234,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/TestOperation.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/TestOperation.kt.expected index be2c56140bd..49a7d99434b 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/TestOperation.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/TestOperation.kt.expected @@ -72,22 +72,22 @@ class TestOperation : Query { ) data class AsWookie( - val lifeExpectancy: Double?, val __typename: String, - val name: String + val name: String, + val lifeExpectancy: Double? ) data class AsHuman( - val profilePictureUrl: String?, - val friends: List, val __typename: String, - val name: String + val name: String, + val friends: List, + val profilePictureUrl: String? ) data class Friend1( val __typename: String, - val isFamous: Boolean?, val name: String, + val isFamous: Boolean?, /** * Synthetic field for inline fragment on Wookie */ @@ -95,17 +95,17 @@ class TestOperation : Query { ) data class AsWookie1( - val race: Race, - val lifeExpectancy: Double?, val __typename: String, + val name: String, val isFamous: Boolean?, - val name: String + val lifeExpectancy: Double?, + val race: Race ) data class AsWookie2( + val __typename: String, val race: Race, - val friends: List, - val __typename: String + val friends: List ) data class Friend2( diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/adapter/TestOperation_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/adapter/TestOperation_ResponseAdapter.kt.expected index 3cc172d2b1e..28e3022bc99 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/adapter/TestOperation_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/compat/adapter/TestOperation_ResponseAdapter.kt.expected @@ -225,27 +225,27 @@ object TestOperation_ResponseAdapter { } object AsWookie : Adapter { - val RESPONSE_NAMES: List = listOf("lifeExpectancy", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "lifeExpectancy") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestOperation.AsWookie { - var lifeExpectancy: Double? = null var __typename: String? = null var name: String? = null + var lifeExpectancy: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> lifeExpectancy = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> lifeExpectancy = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestOperation.AsWookie( - lifeExpectancy = lifeExpectancy, __typename = __typename!!, - name = name!! + name = name!!, + lifeExpectancy = lifeExpectancy ) } @@ -254,42 +254,42 @@ object TestOperation_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestOperation.AsWookie ) { - writer.name("lifeExpectancy") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.lifeExpectancy) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("lifeExpectancy") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.lifeExpectancy) } } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("profilePictureUrl", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "friends", "profilePictureUrl") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestOperation.AsHuman { - var profilePictureUrl: String? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var friends: List? = null + var profilePictureUrl: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> profilePictureUrl = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend1.obj(true).list().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> friends = Friend1.obj(true).list().fromJson(reader, customScalarAdapters) + 3 -> profilePictureUrl = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestOperation.AsHuman( - profilePictureUrl = profilePictureUrl, - friends = friends!!, __typename = __typename!!, - name = name!! + name = name!!, + friends = friends!!, + profilePictureUrl = profilePictureUrl ) } @@ -298,34 +298,34 @@ object TestOperation_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestOperation.AsHuman ) { - writer.name("profilePictureUrl") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.profilePictureUrl) - - writer.name("friends") - Friend1.obj(true).list().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("friends") + Friend1.obj(true).list().toJson(writer, customScalarAdapters, value.friends) + + writer.name("profilePictureUrl") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.profilePictureUrl) } } object Friend1 : Adapter { - val RESPONSE_NAMES: List = listOf("__typename", "isFamous", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "isFamous") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestOperation.Friend1 { var __typename: String? = null - var isFamous: Boolean? = null var name: String? = null + var isFamous: Boolean? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> isFamous = NullableBooleanAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> isFamous = NullableBooleanAdapter.fromJson(reader, customScalarAdapters) else -> break } } @@ -343,8 +343,8 @@ object TestOperation_ResponseAdapter { return TestOperation.Friend1( __typename = __typename, - isFamous = isFamous, name = name!!, + isFamous = isFamous, asWookie = asWookie ) } @@ -357,12 +357,12 @@ object TestOperation_ResponseAdapter { writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) - writer.name("isFamous") - NullableBooleanAdapter.toJson(writer, customScalarAdapters, value.isFamous) - writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + writer.name("isFamous") + NullableBooleanAdapter.toJson(writer, customScalarAdapters, value.isFamous) + if (value.asWookie != null) { com.example.inline_fragment_intersection.adapter.TestOperation_ResponseAdapter.AsWookie1.toJson(writer, customScalarAdapters, value.asWookie) @@ -371,34 +371,34 @@ object TestOperation_ResponseAdapter { } object AsWookie1 : Adapter { - val RESPONSE_NAMES: List = listOf("race", "lifeExpectancy", "__typename", "isFamous", - "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "isFamous", "lifeExpectancy", + "race") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestOperation.AsWookie1 { - var race: Race? = null - var lifeExpectancy: Double? = null var __typename: String? = null - var isFamous: Boolean? = null var name: String? = null + var isFamous: Boolean? = null + var lifeExpectancy: Double? = null + var race: Race? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> race = Race_ResponseAdapter.fromJson(reader, customScalarAdapters) - 1 -> lifeExpectancy = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> isFamous = NullableBooleanAdapter.fromJson(reader, customScalarAdapters) - 4 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> isFamous = NullableBooleanAdapter.fromJson(reader, customScalarAdapters) + 3 -> lifeExpectancy = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) + 4 -> race = Race_ResponseAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestOperation.AsWookie1( - race = race!!, - lifeExpectancy = lifeExpectancy, __typename = __typename!!, + name = name!!, isFamous = isFamous, - name = name!! + lifeExpectancy = lifeExpectancy, + race = race!! ) } @@ -407,45 +407,45 @@ object TestOperation_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestOperation.AsWookie1 ) { - writer.name("race") - Race_ResponseAdapter.toJson(writer, customScalarAdapters, value.race) - - writer.name("lifeExpectancy") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.lifeExpectancy) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) + writer.name("isFamous") NullableBooleanAdapter.toJson(writer, customScalarAdapters, value.isFamous) - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) + writer.name("lifeExpectancy") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.lifeExpectancy) + + writer.name("race") + Race_ResponseAdapter.toJson(writer, customScalarAdapters, value.race) } } object AsWookie2 : Adapter { - val RESPONSE_NAMES: List = listOf("race", "friends", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "race", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestOperation.AsWookie2 { + var __typename: String? = null var race: Race? = null var friends: List? = null - var __typename: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> race = Race_ResponseAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend2.obj().list().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> race = Race_ResponseAdapter.fromJson(reader, customScalarAdapters) + 2 -> friends = Friend2.obj().list().fromJson(reader, customScalarAdapters) else -> break } } return TestOperation.AsWookie2( + __typename = __typename!!, race = race!!, - friends = friends!!, - __typename = __typename!! + friends = friends!! ) } @@ -454,14 +454,14 @@ object TestOperation_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestOperation.AsWookie2 ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + writer.name("race") Race_ResponseAdapter.toJson(writer, customScalarAdapters, value.race) writer.name("friends") Friend2.obj().list().toJson(writer, customScalarAdapters, value.friends) - - writer.name("__typename") - StringAdapter.toJson(writer, customScalarAdapters, value.__typename) } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/TestQuery.kt.expected index e171a33fdfe..ef345c25123 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/TestQuery.kt.expected @@ -50,9 +50,9 @@ class TestQuery : Query { ) data class AsBar( - val bar: String, val __typename: String, - val foo: String + val foo: String, + val bar: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 97ce557f921..3d31d3aaf60 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -101,27 +101,27 @@ object TestQuery_ResponseAdapter { } object AsBar : Adapter { - val RESPONSE_NAMES: List = listOf("bar", "__typename", "foo") + val RESPONSE_NAMES: List = listOf("__typename", "foo", "bar") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsBar { - var bar: String? = null var __typename: String? = null var foo: String? = null + var bar: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> bar = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> foo = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> foo = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> bar = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsBar( - bar = bar!!, __typename = __typename!!, - foo = foo!! + foo = foo!!, + bar = bar!! ) } @@ -130,14 +130,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsBar ) { - writer.name("bar") - StringAdapter.toJson(writer, customScalarAdapters, value.bar) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("foo") StringAdapter.toJson(writer, customScalarAdapters, value.foo) + + writer.name("bar") + StringAdapter.toJson(writer, customScalarAdapters, value.bar) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/TestQuery.kt.expected index 138a4fc3151..9d229d9e286 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/TestQuery.kt.expected @@ -48,21 +48,26 @@ data class TestQuery( * The ID of the character */ val id: String, - /** - * The name of the character - */ - val name: String, /** * Synthetic field for inline fragment on Human */ - val asHumanIfWithDetailsAndNotSkipHumanDetails: AsHumanIfWithDetailsAndNotSkipHumanDetails?, + val asHuman: AsHuman?, /** * Synthetic field for inline fragment on Droid */ - val asDroidIfWithDetails: AsDroidIfWithDetails? + val asDroid: AsDroid?, + /** + * Synthetic field for inline fragment on Character + */ + val asCharacter: AsCharacter? ) - data class AsHumanIfWithDetailsAndNotSkipHumanDetails( + data class AsHuman( + val __typename: String, + /** + * The ID of the character + */ + val id: String, /** * What this human calls themselves */ @@ -70,15 +75,15 @@ data class TestQuery( /** * The home planet of the human, or null if unknown */ - val homePlanet: String?, + val homePlanet: String? + ) + + data class AsDroid( val __typename: String, /** * The ID of the character */ - val id: String - ) - - data class AsDroidIfWithDetails( + val id: String, /** * What others call this droid */ @@ -86,12 +91,19 @@ data class TestQuery( /** * This droid's primary function */ - val primaryFunction: String?, + val primaryFunction: String? + ) + + data class AsCharacter( val __typename: String, /** * The ID of the character */ - val id: String + val id: String, + /** + * The name of the character + */ + val name: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/adapter/TestQuery_ResponseAdapter.kt.expected index b7bf7ca1cb9..3369ec9859a 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -53,19 +53,17 @@ object TestQuery_ResponseAdapter { } object Hero : Adapter { - val RESPONSE_NAMES: List = listOf("__typename", "id", "name") + val RESPONSE_NAMES: List = listOf("__typename", "id") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.Hero { var __typename: String? = null var id: String? = null - var name: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } @@ -75,25 +73,32 @@ object TestQuery_ResponseAdapter { } reader.rewind() - var asHumanIfWithDetailsAndNotSkipHumanDetails: TestQuery.AsHumanIfWithDetailsAndNotSkipHumanDetails? = null + var asHuman: TestQuery.AsHuman? = null if (and(possibleTypes("Human"),and(variable("withDetails"),not(variable("skipHumanDetails")))).evaluate(emptySet(), __typename)) { - asHumanIfWithDetailsAndNotSkipHumanDetails = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsHumanIfWithDetailsAndNotSkipHumanDetails.fromJson(reader, + asHuman = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsHuman.fromJson(reader, customScalarAdapters) } reader.rewind() - var asDroidIfWithDetails: TestQuery.AsDroidIfWithDetails? = null + var asDroid: TestQuery.AsDroid? = null if (and(possibleTypes("Droid"),variable("withDetails")).evaluate(emptySet(), __typename)) { - asDroidIfWithDetails = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsDroidIfWithDetails.fromJson(reader, + asDroid = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsDroid.fromJson(reader, + customScalarAdapters) + } + + reader.rewind() + var asCharacter: TestQuery.AsCharacter? = null + if (and(possibleTypes("Droid","Human"),variable("withDetails")).evaluate(emptySet(), __typename)) { + asCharacter = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsCharacter.fromJson(reader, customScalarAdapters) } return TestQuery.Hero( __typename = __typename, id = id!!, - name = name!!, - asHumanIfWithDetailsAndNotSkipHumanDetails = asHumanIfWithDetailsAndNotSkipHumanDetails, - asDroidIfWithDetails = asDroidIfWithDetails + asHuman = asHuman, + asDroid = asDroid, + asCharacter = asCharacter ) } @@ -108,113 +113,155 @@ object TestQuery_ResponseAdapter { writer.name("id") StringAdapter.toJson(writer, customScalarAdapters, value.id) - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) + if (value.asHuman != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsHuman.toJson(writer, + customScalarAdapters, value.asHuman) + } - if (value.asHumanIfWithDetailsAndNotSkipHumanDetails != null) { - com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsHumanIfWithDetailsAndNotSkipHumanDetails.toJson(writer, - customScalarAdapters, value.asHumanIfWithDetailsAndNotSkipHumanDetails) + if (value.asDroid != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsDroid.toJson(writer, + customScalarAdapters, value.asDroid) } - if (value.asDroidIfWithDetails != null) { - com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsDroidIfWithDetails.toJson(writer, - customScalarAdapters, value.asDroidIfWithDetails) + if (value.asCharacter != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.AsCharacter.toJson(writer, + customScalarAdapters, value.asCharacter) } } } - object AsHumanIfWithDetailsAndNotSkipHumanDetails : - Adapter { - val RESPONSE_NAMES: List = listOf("name", "homePlanet", "__typename", "id") + object AsHuman : Adapter { + val RESPONSE_NAMES: List = listOf("__typename", "id", "name", "homePlanet") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): - TestQuery.AsHumanIfWithDetailsAndNotSkipHumanDetails { - var name: String? = null - var homePlanet: String? = null + TestQuery.AsHuman { var __typename: String? = null var id: String? = null + var name: String? = null + var homePlanet: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } - return TestQuery.AsHumanIfWithDetailsAndNotSkipHumanDetails( - name = name!!, - homePlanet = homePlanet, + return TestQuery.AsHuman( __typename = __typename!!, - id = id!! + id = id!!, + name = name!!, + homePlanet = homePlanet ) } override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, - value: TestQuery.AsHumanIfWithDetailsAndNotSkipHumanDetails + value: TestQuery.AsHuman ) { - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) - - writer.name("homePlanet") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("id") StringAdapter.toJson(writer, customScalarAdapters, value.id) + + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("homePlanet") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) } } - object AsDroidIfWithDetails : Adapter { - val RESPONSE_NAMES: List = listOf("name", "primaryFunction", "__typename", "id") + object AsDroid : Adapter { + val RESPONSE_NAMES: List = listOf("__typename", "id", "name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): - TestQuery.AsDroidIfWithDetails { - var name: String? = null - var primaryFunction: String? = null + TestQuery.AsDroid { var __typename: String? = null var id: String? = null + var name: String? = null + var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } - return TestQuery.AsDroidIfWithDetails( - name = name!!, - primaryFunction = primaryFunction, + return TestQuery.AsDroid( __typename = __typename!!, - id = id!! + id = id!!, + name = name!!, + primaryFunction = primaryFunction ) } override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, - value: TestQuery.AsDroidIfWithDetails + value: TestQuery.AsDroid ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) + writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) writer.name("primaryFunction") NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) + } + } + + object AsCharacter : Adapter { + val RESPONSE_NAMES: List = listOf("__typename", "id", "name") + + override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): + TestQuery.AsCharacter { + var __typename: String? = null + var id: String? = null + var name: String? = null + while(true) { + when (reader.selectName(RESPONSE_NAMES)) { + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + else -> break + } + } + + return TestQuery.AsCharacter( + __typename = __typename!!, + id = id!!, + name = name!! + ) + } + + override fun toJson( + writer: JsonWriter, + customScalarAdapters: CustomScalarAdapters, + value: TestQuery.AsCharacter + ) { writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("id") StringAdapter.toJson(writer, customScalarAdapters, value.id) + + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/TestQuery.kt.expected index 4a5f50a6667..eb6fcc2850d 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/TestQuery.kt.expected @@ -50,17 +50,17 @@ data class TestQuery( /** * Synthetic field for inline fragment on Human */ - val onHumanIfWithDetailsAndNotSkipHumanDetails: OnHumanIfWithDetailsAndNotSkipHumanDetails?, + val onHuman: OnHuman?, /** * Synthetic field for inline fragment on Droid */ - val onDroidIfWithDetails: OnDroidIfWithDetails?, + val onDroid: OnDroid?, /** * Synthetic field for inline fragment on Character */ - val onCharacterIfWithDetails: OnCharacterIfWithDetails? + val onCharacter: OnCharacter? ) { - data class OnHumanIfWithDetailsAndNotSkipHumanDetails( + data class OnHuman( /** * What this human calls themselves */ @@ -71,7 +71,7 @@ data class TestQuery( val homePlanet: String? ) - data class OnDroidIfWithDetails( + data class OnDroid( /** * What others call this droid */ @@ -82,7 +82,7 @@ data class TestQuery( val primaryFunction: String? ) - data class OnCharacterIfWithDetails( + data class OnCharacter( /** * The name of the character */ diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/adapter/TestQuery_ResponseAdapter.kt.expected index c000a77c2f8..a020dc6f894 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/operationBased/adapter/TestQuery_ResponseAdapter.kt.expected @@ -72,32 +72,32 @@ object TestQuery_ResponseAdapter { } reader.rewind() - var onHumanIfWithDetailsAndNotSkipHumanDetails: TestQuery.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails? = null + var onHuman: TestQuery.Data.Hero.OnHuman? = null if (and(possibleTypes("Human"),and(variable("withDetails"),not(variable("skipHumanDetails")))).evaluate(emptySet(), __typename)) { - onHumanIfWithDetailsAndNotSkipHumanDetails = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails.fromJson(reader, + onHuman = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnHuman.fromJson(reader, customScalarAdapters) } reader.rewind() - var onDroidIfWithDetails: TestQuery.Data.Hero.OnDroidIfWithDetails? = null + var onDroid: TestQuery.Data.Hero.OnDroid? = null if (and(possibleTypes("Droid"),variable("withDetails")).evaluate(emptySet(), __typename)) { - onDroidIfWithDetails = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnDroidIfWithDetails.fromJson(reader, + onDroid = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnDroid.fromJson(reader, customScalarAdapters) } reader.rewind() - var onCharacterIfWithDetails: TestQuery.Data.Hero.OnCharacterIfWithDetails? = null + var onCharacter: TestQuery.Data.Hero.OnCharacter? = null if (and(possibleTypes("Droid","Human"),variable("withDetails")).evaluate(emptySet(), __typename)) { - onCharacterIfWithDetails = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnCharacterIfWithDetails.fromJson(reader, + onCharacter = com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnCharacter.fromJson(reader, customScalarAdapters) } return TestQuery.Data.Hero( __typename = __typename, id = id!!, - onHumanIfWithDetailsAndNotSkipHumanDetails = onHumanIfWithDetailsAndNotSkipHumanDetails, - onDroidIfWithDetails = onDroidIfWithDetails, - onCharacterIfWithDetails = onCharacterIfWithDetails + onHuman = onHuman, + onDroid = onDroid, + onCharacter = onCharacter ) } @@ -112,28 +112,27 @@ object TestQuery_ResponseAdapter { writer.name("id") StringAdapter.toJson(writer, customScalarAdapters, value.id) - if (value.onHumanIfWithDetailsAndNotSkipHumanDetails != null) { - com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails.toJson(writer, - customScalarAdapters, value.onHumanIfWithDetailsAndNotSkipHumanDetails) + if (value.onHuman != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnHuman.toJson(writer, + customScalarAdapters, value.onHuman) } - if (value.onDroidIfWithDetails != null) { - com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnDroidIfWithDetails.toJson(writer, - customScalarAdapters, value.onDroidIfWithDetails) + if (value.onDroid != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnDroid.toJson(writer, + customScalarAdapters, value.onDroid) } - if (value.onCharacterIfWithDetails != null) { - com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnCharacterIfWithDetails.toJson(writer, - customScalarAdapters, value.onCharacterIfWithDetails) + if (value.onCharacter != null) { + com.example.inline_fragment_with_include_directive.adapter.TestQuery_ResponseAdapter.Data.Hero.OnCharacter.toJson(writer, + customScalarAdapters, value.onCharacter) } } - object OnHumanIfWithDetailsAndNotSkipHumanDetails : - Adapter { + object OnHuman : Adapter { val RESPONSE_NAMES: List = listOf("name", "homePlanet") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): - TestQuery.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails { + TestQuery.Data.Hero.OnHuman { var name: String? = null var homePlanet: String? = null @@ -145,7 +144,7 @@ object TestQuery_ResponseAdapter { } } - return TestQuery.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails( + return TestQuery.Data.Hero.OnHuman( name = name!!, homePlanet = homePlanet ) @@ -154,7 +153,7 @@ object TestQuery_ResponseAdapter { override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, - value: TestQuery.Data.Hero.OnHumanIfWithDetailsAndNotSkipHumanDetails + value: TestQuery.Data.Hero.OnHuman ) { writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) @@ -164,11 +163,11 @@ object TestQuery_ResponseAdapter { } } - object OnDroidIfWithDetails : Adapter { + object OnDroid : Adapter { val RESPONSE_NAMES: List = listOf("name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): - TestQuery.Data.Hero.OnDroidIfWithDetails { + TestQuery.Data.Hero.OnDroid { var name: String? = null var primaryFunction: String? = null @@ -180,7 +179,7 @@ object TestQuery_ResponseAdapter { } } - return TestQuery.Data.Hero.OnDroidIfWithDetails( + return TestQuery.Data.Hero.OnDroid( name = name!!, primaryFunction = primaryFunction ) @@ -189,7 +188,7 @@ object TestQuery_ResponseAdapter { override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, - value: TestQuery.Data.Hero.OnDroidIfWithDetails + value: TestQuery.Data.Hero.OnDroid ) { writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) @@ -199,11 +198,11 @@ object TestQuery_ResponseAdapter { } } - object OnCharacterIfWithDetails : Adapter { + object OnCharacter : Adapter { val RESPONSE_NAMES: List = listOf("name") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): - TestQuery.Data.Hero.OnCharacterIfWithDetails { + TestQuery.Data.Hero.OnCharacter { var name: String? = null while(true) { @@ -213,7 +212,7 @@ object TestQuery_ResponseAdapter { } } - return TestQuery.Data.Hero.OnCharacterIfWithDetails( + return TestQuery.Data.Hero.OnCharacter( name = name!! ) } @@ -221,7 +220,7 @@ object TestQuery_ResponseAdapter { override fun toJson( writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, - value: TestQuery.Data.Hero.OnCharacterIfWithDetails + value: TestQuery.Data.Hero.OnCharacter ) { writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/TestQuery.kt.expected index bf05c84eeb1..ad897e17a59 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/TestQuery.kt.expected @@ -56,6 +56,11 @@ class TestQuery : Query { ) data class AsHuman( + val __typename: String, + /** + * The name of the character + */ + val name: String, /** * Height in the preferred unit, default is meters */ @@ -63,12 +68,7 @@ class TestQuery : Query { /** * This human's friends, or an empty list if they have none */ - val friends: List?, - val __typename: String, - /** - * The name of the character - */ - val name: String + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -83,6 +83,11 @@ class TestQuery : Query { } data class AsDroid( + val __typename: String, + /** + * The name of the character + */ + val name: String, /** * This droid's primary function */ @@ -90,12 +95,7 @@ class TestQuery : Query { /** * This droid's friends, or an empty list if they have none */ - val friends: List?, - val __typename: String, - /** - * The name of the character - */ - val name: String + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/adapter/TestQuery_ResponseAdapter.kt.expected index be07ff4081f..311b21f31a0 100644 --- a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -120,31 +120,31 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "height", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var height: Double? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend.obj().nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) + 3 -> friends = Friend.obj().nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + height = height, + friends = friends ) } @@ -153,17 +153,17 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - - writer.name("friends") - Friend.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) + + writer.name("friends") + Friend.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) } } @@ -199,31 +199,31 @@ object TestQuery_ResponseAdapter { } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "primaryFunction", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var primaryFunction: String? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var primaryFunction: String? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend1.obj().nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> friends = Friend1.obj().nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - primaryFunction = primaryFunction, - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + primaryFunction = primaryFunction, + friends = friends ) } @@ -232,17 +232,17 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - - writer.name("friends") - Friend1.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) + + writer.name("friends") + Friend1.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) } } diff --git a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/TestQuery.kt.expected index 1e3f45eac73..4ce017eb284 100644 --- a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/TestQuery.kt.expected @@ -55,9 +55,9 @@ class TestQuery : Query { ) data class AsB( - val fieldB1: String?, val __typename: String, - val fieldA1: String? + val fieldA1: String?, + val fieldB1: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/adapter/TestQuery_ResponseAdapter.kt.expected index b70df2429fd..6da6066015c 100644 --- a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -148,27 +148,27 @@ object TestQuery_ResponseAdapter { } object AsB : Adapter { - val RESPONSE_NAMES: List = listOf("fieldB1", "__typename", "fieldA1") + val RESPONSE_NAMES: List = listOf("__typename", "fieldA1", "fieldB1") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsB { - var fieldB1: String? = null var __typename: String? = null var fieldA1: String? = null + var fieldB1: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> fieldA1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldA1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsB( - fieldB1 = fieldB1, __typename = __typename!!, - fieldA1 = fieldA1 + fieldA1 = fieldA1, + fieldB1 = fieldB1 ) } @@ -177,14 +177,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsB ) { - writer.name("fieldB1") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("fieldA1") NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldA1) + + writer.name("fieldB1") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/GetHuman.kt.expected b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/GetHuman.kt.expected index ede9b7d379c..39dff3a65ed 100644 --- a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/GetHuman.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/GetHuman.kt.expected @@ -54,8 +54,8 @@ class GetHuman : Query { ) data class AsHuman( - val height: Double, - val __typename: String + val __typename: String, + val height: Double ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/adapter/GetHuman_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/adapter/GetHuman_ResponseAdapter.kt.expected index c87cfc05f85..2e2ff8e013e 100644 --- a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/adapter/GetHuman_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/compat/adapter/GetHuman_ResponseAdapter.kt.expected @@ -143,24 +143,24 @@ object GetHuman_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetHuman.AsHuman { - var height: Double? = null var __typename: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = DoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> height = DoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return GetHuman.AsHuman( - height = height!!, - __typename = __typename!! + __typename = __typename!!, + height = height!! ) } @@ -169,11 +169,11 @@ object GetHuman_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: GetHuman.AsHuman ) { - writer.name("height") - DoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("height") + DoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/measurements b/apollo-compiler/src/test/graphql/com/example/measurements index 19dd3496e99..a8348d013c5 100644 --- a/apollo-compiler/src/test/graphql/com/example/measurements +++ b/apollo-compiler/src/test/graphql/com/example/measurements @@ -1,152 +1,152 @@ Test: CodegenModels: Total LOC: Codegen (ms): -aggregate all 95786 2.37s 78.4s -aggregate responseBased 29358 698ms 21.3s -aggregate operationBased 26301 669ms 20.5s -aggregate compat 27733 585ms 21.3s -aggregate no-fragments 12394 414ms 15.2s +aggregate all 95844 2.15s 76.4s +aggregate responseBased 29358 656ms 21.4s +aggregate operationBased 26300 649ms 20.9s +aggregate compat 27792 521ms 21.1s +aggregate no-fragments 12394 325ms 13.0s -fragment_with_inline_fragment responseBased 2245 83 1.91s -nested_named_fragments responseBased 1577 28 628ms -fragment_with_inline_fragment compat 1406 31 1.29s -nested_named_fragments compat 1370 19 523ms -unique_type_name responseBased 1261 21 511ms -nested_named_fragments operationBased 1245 22 527ms -named_fragment_delegate responseBased 1221 27 647ms -root_query_fragment_with_nested_fragments responseBased 1149 21 502ms -fragment_with_inline_fragment operationBased 1137 34 960ms -unique_type_name compat 1082 17 465ms -root_query_fragment_with_nested_fragments compat 1060 16 478ms -fragment_used_twice responseBased 1041 31 850ms -union_inline_fragments operationBased 1035 19 476ms -union_inline_fragments responseBased 1028 15 458ms -unique_type_name operationBased 1023 16 485ms -nested_conditional_inline responseBased 1012 17 490ms -simple_fragment_with_inline_fragments responseBased 1011 14 452ms -fragments_with_type_condition responseBased 1007 23 742ms -inline_fragment_intersection responseBased 1000 30 963ms -union_inline_fragments compat 987 10 472ms -root_query_fragment_with_nested_fragments operationBased 975 13 475ms -inline_fragment_intersection compat 968 19 667ms -mutation_create_review responseBased 960 25 758ms -fragment_used_twice compat 937 29 856ms -nested_conditional_inline compat 932 14 466ms -named_fragment_delegate compat 901 22 538ms -inline_fragment_intersection operationBased 898 26 738ms -multiple_fragments responseBased 870 23 635ms -nested_conditional_inline operationBased 864 20 473ms -named_fragment_with_variables responseBased 862 17 498ms -named_fragment_delegate operationBased 861 23 547ms -mutation_create_review_semantic_naming responseBased 835 19 573ms -input_object_type responseBased 834 38 675ms -named_fragment_with_variables compat 830 15 462ms -fragments_with_type_condition compat 820 19 675ms -fragment_used_twice operationBased 805 31 801ms -fragment_spread_with_nested_fields responseBased 800 47 1.12s -simple_fragment responseBased 786 14 422ms -simple_fragment_with_inline_fragments compat 762 10 364ms -named_fragment_inside_inline_fragment operationBased 752 21 449ms -multiple_fragments compat 750 13 470ms -inline_fragments_with_friends responseBased 747 24 620ms -named_fragment_with_variables operationBased 743 15 483ms -named_fragment_inside_inline_fragment compat 742 13 489ms -two_heroes_with_friends responseBased 742 11 393ms -root_query_inline_fragment operationBased 737 9 406ms -inline_fragment_merge_fields operationBased 735 37 739ms -fragments_with_type_condition operationBased 732 21 593ms -simple_fragment compat 728 12 399ms -inline_fragments_with_friends compat 727 21 759ms -nested_field_with_multiple_fieldsets responseBased 721 14 451ms -named_fragment_inside_inline_fragment responseBased 704 12 429ms -root_query_inline_fragment responseBased 699 9 389ms -inline_fragments_with_friends operationBased 695 29 672ms -fragment_spread_with_include_directive compat 693 24 837ms -nested_field_with_multiple_fieldsets operationBased 693 13 426ms -simple_fragment_with_inline_fragments operationBased 686 10 379ms -fragment_spread_with_nested_fields compat 681 32 1.16s -root_query_inline_fragment compat 667 10 397ms -fragments_same_type_condition responseBased 665 20 618ms -multiple_fragments operationBased 662 17 410ms -fragment_spread_with_include_directive operationBased 649 24 882ms -fragment_spread_with_nested_fields operationBased 641 23 847ms -simple_fragment operationBased 640 9 368ms -fragments_same_type_condition compat 634 18 507ms -nested_field_with_multiple_fieldsets compat 621 8 390ms -inline_fragment_with_include_directive operationBased 606 18 590ms -simple_inline_fragment operationBased 605 9 350ms -inline_fragment_with_include_directive compat 597 14 793ms -named_fragment_without_implementation compat 597 11 361ms -fragments_same_type_condition operationBased 590 14 502ms -named_fragment_without_implementation responseBased 588 12 376ms -simple_inline_fragment responseBased 585 8 333ms -union_fragment compat 582 8 320ms -inline_fragment_inside_inline_fragment compat 577 13 535ms -hero_details responseBased 567 17 531ms -simple_inline_fragment compat 562 6 333ms -union_fragment responseBased 561 7 319ms -inline_fragment_merge_fields compat 554 11 671ms -inline_fragment_merge_fields responseBased 554 18 680ms -named_fragment_without_implementation operationBased 553 8 424ms -not_all_combinations_are_needed compat 550 7 367ms -inline_fragment_inside_inline_fragment operationBased 543 12 516ms -inline_fragment_inside_inline_fragment responseBased 538 12 561ms -fieldset_with_multiple_super compat 535 20 861ms -test_inline responseBased 534 9 353ms -union_fragment operationBased 531 10 330ms -fragment_with_multiple_fieldsets responseBased 527 14 521ms -typename_always_first responseBased 518 7 321ms -root_query_fragment compat 509 8 350ms -fieldset_with_multiple_super operationBased 507 23 881ms -typename_always_first operationBased 505 7 337ms -typename_always_first compat 505 6 318ms -root_query_fragment responseBased 503 9 314ms -reserved_kotlin_keywords responseBased 500 8 397ms -not_all_combinations_are_needed operationBased 499 13 370ms -fieldset_with_multiple_super responseBased 494 18 768ms -hero_details_semantic_naming responseBased 491 12 480ms -input_object_variable_and_argument responseBased 489 16 589ms -hero_name responseBased 477 11 537ms -hero_with_review responseBased 477 14 466ms -reserved_kotlin_keywords compat 477 6 371ms -test_inline compat 476 9 337ms -fragment_with_multiple_fieldsets compat 470 15 511ms -reserved_kotlin_keywords operationBased 470 7 342ms -deprecation responseBased 469 21 1.03s -introspection_query responseBased 466 14 446ms -not_all_combinations_are_needed responseBased 466 10 412ms -root_query_fragment operationBased 465 7 329ms -hero_name_query_long_name responseBased 464 12 394ms -inline_fragment_for_non_optional_field responseBased 450 9 415ms -test_inline operationBased 449 12 317ms -path_vs_flat_accessors responseBased 446 7 352ms -hero_name compat 444 10 457ms -variable_default_value responseBased 436 7 320ms -inline_fragment_type_coercion responseBased 432 10 437ms -path_vs_flat_accessors compat 429 6 318ms -inline_fragment_for_non_optional_field compat 421 9 397ms -recursive_selection responseBased 421 9 318ms -fragment_with_multiple_fieldsets operationBased 419 14 560ms -optional responseBased 419 8 328ms -field_with_include_directive responseBased 417 16 750ms -hero_name operationBased 417 11 429ms -path_vs_flat_accessors operationBased 415 10 342ms -custom_scalar_type responseBased 408 26 1.14s -inline_fragment_type_coercion compat 408 16 497ms -inline_fragment_for_non_optional_field operationBased 404 13 395ms -inline_fragment_type_coercion operationBased 394 12 499ms -interface_always_nested responseBased 392 15 471ms -two_heroes_unique responseBased 392 5 283ms -interface_on_interface responseBased 387 8 404ms -starships responseBased 382 6 286ms -interface_always_nested compat 377 8 478ms -enum_field responseBased 376 20 652ms -antlr_tokens responseBased 375 33 1.19s -interface_on_interface compat 365 10 403ms -arguments_hardcoded responseBased 363 25 1.10s -interface_always_nested operationBased 363 11 399ms -interface_on_interface operationBased 358 7 433ms -operation_id_generator responseBased 325 9 283ms -merged_include responseBased 324 6 384ms -nonnull responseBased 309 4 326ms -subscriptions responseBased 298 5 263ms -case_sensitive_enum responseBased 217 17 793ms -empty responseBased 138 6 497ms \ No newline at end of file +fragment_with_inline_fragment responseBased 2245 71 1.39s +nested_named_fragments responseBased 1577 33 731ms +fragment_with_inline_fragment compat 1406 37 975ms +nested_named_fragments compat 1370 20 648ms +unique_type_name responseBased 1261 23 777ms +nested_named_fragments operationBased 1245 19 591ms +named_fragment_delegate responseBased 1221 21 737ms +root_query_fragment_with_nested_fragments responseBased 1149 22 596ms +fragment_with_inline_fragment operationBased 1137 54 795ms +unique_type_name compat 1082 29 594ms +root_query_fragment_with_nested_fragments compat 1060 20 575ms +fragment_used_twice responseBased 1041 25 886ms +union_inline_fragments operationBased 1035 26 612ms +union_inline_fragments responseBased 1028 18 614ms +unique_type_name operationBased 1023 19 577ms +nested_conditional_inline responseBased 1012 15 619ms +simple_fragment_with_inline_fragments responseBased 1011 18 580ms +fragments_with_type_condition responseBased 1007 21 672ms +inline_fragment_intersection responseBased 1000 18 660ms +union_inline_fragments compat 987 13 827ms +root_query_fragment_with_nested_fragments operationBased 975 22 563ms +inline_fragment_intersection compat 968 17 719ms +mutation_create_review responseBased 960 22 684ms +fragment_used_twice compat 937 26 679ms +nested_conditional_inline compat 932 11 590ms +named_fragment_delegate compat 901 13 556ms +inline_fragment_intersection operationBased 898 20 731ms +multiple_fragments responseBased 870 23 685ms +nested_conditional_inline operationBased 864 19 548ms +named_fragment_with_variables responseBased 862 22 554ms +named_fragment_delegate operationBased 861 16 592ms +mutation_create_review_semantic_naming responseBased 835 18 622ms +input_object_type responseBased 834 25 572ms +named_fragment_with_variables compat 830 14 639ms +fragments_with_type_condition compat 820 18 614ms +fragment_used_twice operationBased 805 22 686ms +fragment_spread_with_nested_fields responseBased 800 24 670ms +simple_fragment responseBased 786 12 433ms +simple_fragment_with_inline_fragments compat 762 13 508ms +named_fragment_inside_inline_fragment operationBased 752 20 544ms +multiple_fragments compat 750 15 705ms +inline_fragments_with_friends responseBased 747 23 519ms +named_fragment_with_variables operationBased 743 24 643ms +named_fragment_inside_inline_fragment compat 742 11 455ms +two_heroes_with_friends responseBased 742 13 438ms +root_query_inline_fragment operationBased 737 13 508ms +inline_fragment_merge_fields operationBased 735 13 576ms +fragments_with_type_condition operationBased 732 20 554ms +simple_fragment compat 728 11 403ms +inline_fragments_with_friends compat 727 9 560ms +nested_field_with_multiple_fieldsets responseBased 721 11 513ms +named_fragment_inside_inline_fragment responseBased 704 15 515ms +root_query_inline_fragment responseBased 699 22 496ms +inline_fragments_with_friends operationBased 695 10 559ms +fragment_spread_with_include_directive compat 693 24 869ms +nested_field_with_multiple_fieldsets operationBased 693 16 508ms +simple_fragment_with_inline_fragments operationBased 686 12 456ms +fragment_spread_with_nested_fields compat 681 16 546ms +root_query_inline_fragment compat 667 9 475ms +fragments_same_type_condition responseBased 665 15 502ms +multiple_fragments operationBased 662 19 614ms +inline_fragment_with_include_directive compat 656 9 493ms +fragment_spread_with_include_directive operationBased 649 26 774ms +fragment_spread_with_nested_fields operationBased 641 33 658ms +simple_fragment operationBased 640 11 380ms +fragments_same_type_condition compat 634 11 492ms +nested_field_with_multiple_fieldsets compat 621 8 453ms +inline_fragment_with_include_directive operationBased 605 13 465ms +simple_inline_fragment operationBased 605 11 411ms +named_fragment_without_implementation compat 597 9 464ms +fragments_same_type_condition operationBased 590 12 598ms +named_fragment_without_implementation responseBased 588 9 416ms +simple_inline_fragment responseBased 585 8 368ms +union_fragment compat 582 8 443ms +inline_fragment_inside_inline_fragment compat 577 8 450ms +hero_details responseBased 567 12 459ms +simple_inline_fragment compat 562 7 399ms +union_fragment responseBased 561 12 402ms +inline_fragment_merge_fields compat 554 8 522ms +inline_fragment_merge_fields responseBased 554 15 486ms +named_fragment_without_implementation operationBased 553 9 423ms +not_all_combinations_are_needed compat 550 9 397ms +inline_fragment_inside_inline_fragment operationBased 543 10 471ms +inline_fragment_inside_inline_fragment responseBased 538 8 447ms +fieldset_with_multiple_super compat 535 17 701ms +test_inline responseBased 534 10 419ms +union_fragment operationBased 531 9 412ms +fragment_with_multiple_fieldsets responseBased 527 24 573ms +typename_always_first responseBased 518 7 408ms +root_query_fragment compat 509 7 358ms +fieldset_with_multiple_super operationBased 507 26 893ms +typename_always_first operationBased 505 11 386ms +typename_always_first compat 505 7 374ms +root_query_fragment responseBased 503 8 341ms +reserved_kotlin_keywords responseBased 500 9 375ms +not_all_combinations_are_needed operationBased 499 8 386ms +fieldset_with_multiple_super responseBased 494 18 605ms +hero_details_semantic_naming responseBased 491 10 480ms +input_object_variable_and_argument responseBased 489 11 480ms +hero_name responseBased 477 13 655ms +hero_with_review responseBased 477 9 491ms +reserved_kotlin_keywords compat 477 6 354ms +test_inline compat 476 6 370ms +fragment_with_multiple_fieldsets compat 470 11 409ms +reserved_kotlin_keywords operationBased 470 9 360ms +deprecation responseBased 469 14 519ms +introspection_query responseBased 466 12 884ms +not_all_combinations_are_needed responseBased 466 8 359ms +root_query_fragment operationBased 465 7 361ms +hero_name_query_long_name responseBased 464 16 464ms +inline_fragment_for_non_optional_field responseBased 450 7 435ms +test_inline operationBased 449 12 351ms +path_vs_flat_accessors responseBased 446 10 347ms +hero_name compat 444 9 551ms +variable_default_value responseBased 436 8 424ms +inline_fragment_type_coercion responseBased 432 9 388ms +path_vs_flat_accessors compat 429 6 374ms +inline_fragment_for_non_optional_field compat 421 9 387ms +recursive_selection responseBased 421 8 330ms +fragment_with_multiple_fieldsets operationBased 419 11 436ms +optional responseBased 419 6 339ms +field_with_include_directive responseBased 417 20 817ms +hero_name operationBased 417 8 509ms +path_vs_flat_accessors operationBased 415 6 372ms +custom_scalar_type responseBased 408 14 679ms +inline_fragment_type_coercion compat 408 6 413ms +inline_fragment_for_non_optional_field operationBased 404 7 370ms +inline_fragment_type_coercion operationBased 394 6 384ms +interface_always_nested responseBased 392 7 525ms +two_heroes_unique responseBased 392 6 310ms +interface_on_interface responseBased 387 7 677ms +starships responseBased 382 6 318ms +interface_always_nested compat 377 7 363ms +enum_field responseBased 376 10 464ms +antlr_tokens responseBased 375 15 527ms +interface_on_interface compat 365 7 400ms +arguments_hardcoded responseBased 363 14 529ms +interface_always_nested operationBased 363 9 375ms +interface_on_interface operationBased 358 14 479ms +operation_id_generator responseBased 325 5 300ms +merged_include responseBased 324 11 503ms +nonnull responseBased 309 7 306ms +subscriptions responseBased 298 7 292ms +case_sensitive_enum responseBased 217 8 462ms +empty responseBased 138 4 307ms \ No newline at end of file diff --git a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/TestQuery.kt.expected index a25f0279d56..6944d043c66 100644 --- a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/TestQuery.kt.expected @@ -59,15 +59,15 @@ data class TestQuery( ) data class AsHuman1( - /** - * This human's friends, or an empty list if they have none - */ - val friends: List?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * This human's friends, or an empty list if they have none + */ + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -85,27 +85,27 @@ data class TestQuery( ) data class AsHuman( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) data class AsDroid( - /** - * This droid's friends, or an empty list if they have none - */ - val friends: List?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * This droid's friends, or an empty list if they have none + */ + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -123,15 +123,15 @@ data class TestQuery( ) data class AsHuman2( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/adapter/TestQuery_ResponseAdapter.kt.expected index e5d9381e971..7be2b218fd1 100644 --- a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -117,28 +117,28 @@ object TestQuery_ResponseAdapter { } object AsHuman1 : Adapter { - val RESPONSE_NAMES: List = listOf("friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman1 { - var friends: List? = null var __typename: String? = null var name: String? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> friends = Friend.obj(true).nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> friends = Friend.obj(true).nullable().list().nullable().fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman1( - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + friends = friends ) } @@ -147,15 +147,15 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman1 ) { - writer.name("friends") - Friend.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, - value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("friends") + Friend.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, + value.friends) } } @@ -212,27 +212,27 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null var __typename: String? = null var name: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, __typename = __typename!!, - name = name!! + name = name!!, + height = height ) } @@ -241,40 +241,40 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var friends: List? = null var __typename: String? = null var name: String? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> friends = Friend1.obj(true).nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> friends = Friend1.obj(true).nullable().list().nullable().fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + friends = friends ) } @@ -283,15 +283,15 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("friends") - Friend1.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, - value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("friends") + Friend1.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, + value.friends) } } @@ -348,27 +348,27 @@ object TestQuery_ResponseAdapter { } object AsHuman2 : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman2 { - var height: Double? = null var __typename: String? = null var name: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman2( - height = height, __typename = __typename!!, - name = name!! + name = name!!, + height = height ) } @@ -377,14 +377,14 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman2 ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/TestQuery.kt.expected index 39c92c3d99c..efe41154ce0 100644 --- a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/TestQuery.kt.expected @@ -56,20 +56,20 @@ class TestQuery : Query { ) data class AsImpl2( - val scalar2: String?, val __typename: String, - val scalar1: String? + val scalar1: String?, + val scalar2: String? ) data class AsImpl1( - val iface2: Iface21?, - val __typename: String + val __typename: String, + val iface2: Iface21? ) data class Iface21( val __typename: String, - val scalar3: String?, val scalar1: String?, + val scalar3: String?, /** * Synthetic field for inline fragment on Impl2 */ @@ -77,11 +77,11 @@ class TestQuery : Query { ) data class AsImpl21( - val scalar4: String?, - val scalar2: String?, val __typename: String, + val scalar1: String?, val scalar3: String?, - val scalar1: String? + val scalar2: String?, + val scalar4: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 34ac3dbc4d3..1cddd76eb2c 100644 --- a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -154,27 +154,27 @@ object TestQuery_ResponseAdapter { } object AsImpl2 : Adapter { - val RESPONSE_NAMES: List = listOf("scalar2", "__typename", "scalar1") + val RESPONSE_NAMES: List = listOf("__typename", "scalar1", "scalar2") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsImpl2 { - var scalar2: String? = null var __typename: String? = null var scalar1: String? = null + var scalar2: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> scalar2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> scalar2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsImpl2( - scalar2 = scalar2, __typename = __typename!!, - scalar1 = scalar1 + scalar1 = scalar1, + scalar2 = scalar2 ) } @@ -183,36 +183,36 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsImpl2 ) { - writer.name("scalar2") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar2) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("scalar1") NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar1) + + writer.name("scalar2") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar2) } } object AsImpl1 : Adapter { - val RESPONSE_NAMES: List = listOf("iface2", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "iface2") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsImpl1 { - var iface2: TestQuery.Iface21? = null var __typename: String? = null + var iface2: TestQuery.Iface21? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> iface2 = Iface21.obj(true).nullable().fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> iface2 = Iface21.obj(true).nullable().fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsImpl1( - iface2 = iface2, - __typename = __typename!! + __typename = __typename!!, + iface2 = iface2 ) } @@ -221,28 +221,28 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsImpl1 ) { - writer.name("iface2") - Iface21.obj(true).nullable().toJson(writer, customScalarAdapters, value.iface2) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("iface2") + Iface21.obj(true).nullable().toJson(writer, customScalarAdapters, value.iface2) } } object Iface21 : Adapter { - val RESPONSE_NAMES: List = listOf("__typename", "scalar3", "scalar1") + val RESPONSE_NAMES: List = listOf("__typename", "scalar1", "scalar3") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.Iface21 { var __typename: String? = null - var scalar3: String? = null var scalar1: String? = null + var scalar3: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> scalar3 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 2 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 1 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> scalar3 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } @@ -260,8 +260,8 @@ object TestQuery_ResponseAdapter { return TestQuery.Iface21( __typename = __typename, - scalar3 = scalar3, scalar1 = scalar1, + scalar3 = scalar3, asImpl2 = asImpl2 ) } @@ -274,12 +274,12 @@ object TestQuery_ResponseAdapter { writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) - writer.name("scalar3") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar3) - writer.name("scalar1") NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar1) + writer.name("scalar3") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar3) + if (value.asImpl2 != null) { com.example.nested_field_with_multiple_fieldsets.adapter.TestQuery_ResponseAdapter.AsImpl21.toJson(writer, customScalarAdapters, value.asImpl2) @@ -288,34 +288,34 @@ object TestQuery_ResponseAdapter { } object AsImpl21 : Adapter { - val RESPONSE_NAMES: List = listOf("scalar4", "scalar2", "__typename", "scalar3", - "scalar1") + val RESPONSE_NAMES: List = listOf("__typename", "scalar1", "scalar3", "scalar2", + "scalar4") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsImpl21 { - var scalar4: String? = null - var scalar2: String? = null var __typename: String? = null - var scalar3: String? = null var scalar1: String? = null + var scalar3: String? = null + var scalar2: String? = null + var scalar4: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> scalar4 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> scalar2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> scalar3 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 4 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> scalar1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 2 -> scalar3 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> scalar2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 4 -> scalar4 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsImpl21( - scalar4 = scalar4, - scalar2 = scalar2, __typename = __typename!!, + scalar1 = scalar1, scalar3 = scalar3, - scalar1 = scalar1 + scalar2 = scalar2, + scalar4 = scalar4 ) } @@ -324,20 +324,20 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsImpl21 ) { - writer.name("scalar4") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar4) - - writer.name("scalar2") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar2) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + writer.name("scalar1") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar1) + writer.name("scalar3") NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar3) - writer.name("scalar1") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar1) + writer.name("scalar2") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar2) + + writer.name("scalar4") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.scalar4) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/TestQuery.kt.expected index c2d498024b2..6f027299438 100644 --- a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/TestQuery.kt.expected @@ -58,13 +58,13 @@ class TestQuery : Query { ) data class AsB( - val fieldB1: String?, - val __typename: String + val __typename: String, + val fieldB1: String? ) data class AsB1( - val fieldB2: String?, - val __typename: String + val __typename: String, + val fieldB2: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 3bb6df5d4a6..91f29eda894 100644 --- a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -155,24 +155,24 @@ object TestQuery_ResponseAdapter { } object AsB : Adapter { - val RESPONSE_NAMES: List = listOf("fieldB1", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "fieldB1") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsB { - var fieldB1: String? = null var __typename: String? = null + var fieldB1: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldB1 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsB( - fieldB1 = fieldB1, - __typename = __typename!! + __typename = __typename!!, + fieldB1 = fieldB1 ) } @@ -181,33 +181,33 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsB ) { - writer.name("fieldB1") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("fieldB1") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB1) } } object AsB1 : Adapter { - val RESPONSE_NAMES: List = listOf("fieldB2", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "fieldB2") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsB1 { - var fieldB2: String? = null var __typename: String? = null + var fieldB2: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> fieldB2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> fieldB2 = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsB1( - fieldB2 = fieldB2, - __typename = __typename!! + __typename = __typename!!, + fieldB2 = fieldB2 ) } @@ -216,11 +216,11 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsB1 ) { - writer.name("fieldB2") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB2) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("fieldB2") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.fieldB2) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/TestQuery.kt.expected index c9e61dc29b5..d2ba2e4aa86 100644 --- a/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/TestQuery.kt.expected @@ -60,11 +60,11 @@ class TestQuery : Query { ) data class AsCharacter( + val __typename: String, /** * The name of the character */ - val name: String, - val __typename: String + val name: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 893c0008a00..554d1da5f9a 100644 --- a/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/reserved_kotlin_keywords/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -139,24 +139,24 @@ object TestQuery_ResponseAdapter { } object AsCharacter : Adapter { - val RESPONSE_NAMES: List = listOf("name", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "name") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsCharacter { - var name: String? = null var __typename: String? = null + var name: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsCharacter( - name = name!!, - __typename = __typename!! + __typename = __typename!!, + name = name!! ) } @@ -165,11 +165,11 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsCharacter ) { - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/TestQuery.kt.expected index 4b96c411112..858443ea1bd 100644 --- a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/TestQuery.kt.expected @@ -60,10 +60,6 @@ class TestQuery : Query { } data class AsHuman( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The name of the character @@ -72,7 +68,11 @@ class TestQuery : Query { /** * The movies this character appears in */ - val appearsIn: List + val appearsIn: List, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) { fun appearsInFilterNotNull(): List = appearsIn.filterNotNull() } diff --git a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected index dd83bf13ac8..e19369ef0b4 100644 --- a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -127,31 +127,31 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "name", "appearsIn") + val RESPONSE_NAMES: List = listOf("__typename", "name", "appearsIn", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null var __typename: String? = null var name: String? = null var appearsIn: List? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> appearsIn = Episode_ResponseAdapter.nullable().list().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> appearsIn = Episode_ResponseAdapter.nullable().list().fromJson(reader, customScalarAdapters) + 3 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, __typename = __typename!!, name = name!!, - appearsIn = appearsIn!! + appearsIn = appearsIn!!, + height = height ) } @@ -160,9 +160,6 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) @@ -172,6 +169,9 @@ object TestQuery_ResponseAdapter { writer.name("appearsIn") Episode_ResponseAdapter.nullable().list().toJson(writer, customScalarAdapters, value.appearsIn) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } diff --git a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetails.kt.expected b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetails.kt.expected index 5d857c1ca47..a44a3cfbe28 100644 --- a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetails.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetails.kt.expected @@ -37,26 +37,26 @@ data class HeroDetails( ) data class AsHuman( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) data class AsDroid( - /** - * This droid's primary function - */ - val primaryFunction: String?, val __typename: String, /** * The name of the character */ - val name: String + val name: String, + /** + * This droid's primary function + */ + val primaryFunction: String? ) } diff --git a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetailsImpl_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetailsImpl_ResponseAdapter.kt.expected index b8e31eb41a4..a666bf8a8cc 100644 --- a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetailsImpl_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/compat/fragment/HeroDetailsImpl_ResponseAdapter.kt.expected @@ -128,27 +128,27 @@ object HeroDetailsImpl_ResponseAdapter { object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsHuman { - var height: Double? = null var __typename: String? = null var name: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsHuman( - height = height, __typename = __typename!!, - name = name!! + name = name!!, + height = height ) } @@ -157,40 +157,40 @@ object HeroDetailsImpl_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsDroid { - var primaryFunction: String? = null var __typename: String? = null var name: String? = null + var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsDroid( - primaryFunction = primaryFunction, __typename = __typename!!, - name = name!! + name = name!!, + primaryFunction = primaryFunction ) } @@ -199,14 +199,14 @@ object HeroDetailsImpl_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: com.example.simple_fragment_with_inline_fragments.fragment.HeroDetails.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/TestQuery.kt.expected index 57e12cf454b..8516e9703a0 100644 --- a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/TestQuery.kt.expected @@ -59,10 +59,6 @@ class TestQuery : Query { ) data class AsHuman( - /** - * Height in the preferred unit, default is meters - */ - val height: Double?, val __typename: String, /** * The ID of the character @@ -71,14 +67,14 @@ class TestQuery : Query { /** * The name of the character */ - val name: String + val name: String, + /** + * Height in the preferred unit, default is meters + */ + val height: Double? ) data class AsDroid( - /** - * This droid's primary function - */ - val primaryFunction: String?, val __typename: String, /** * The ID of the character @@ -87,7 +83,11 @@ class TestQuery : Query { /** * The name of the character */ - val name: String + val name: String, + /** + * This droid's primary function + */ + val primaryFunction: String? ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 8ad3ed0bb65..adc9a4f8ed8 100644 --- a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -123,30 +123,30 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename", "id", "name") + val RESPONSE_NAMES: List = listOf("__typename", "id", "name", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null var __typename: String? = null var id: String? = null var name: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> id = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, __typename = __typename!!, id = id!!, - name = name!! + name = name!!, + height = height ) } @@ -155,9 +155,6 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) @@ -166,34 +163,37 @@ object TestQuery_ResponseAdapter { writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "__typename", "id", "name") + val RESPONSE_NAMES: List = listOf("__typename", "id", "name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var primaryFunction: String? = null var __typename: String? = null var id: String? = null var name: String? = null + var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> id = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - primaryFunction = primaryFunction, __typename = __typename!!, id = id!!, - name = name!! + name = name!!, + primaryFunction = primaryFunction ) } @@ -202,9 +202,6 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) @@ -213,6 +210,9 @@ object TestQuery_ResponseAdapter { writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/test_inline/compat/GetPage.kt.expected b/apollo-compiler/src/test/graphql/com/example/test_inline/compat/GetPage.kt.expected index 2f59a335826..cb67caa3d74 100644 --- a/apollo-compiler/src/test/graphql/com/example/test_inline/compat/GetPage.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/test_inline/compat/GetPage.kt.expected @@ -51,13 +51,13 @@ class GetPage : Query { ) data class AsParticularCollection( - val items: List, - val __typename: String + val __typename: String, + val items: List ) data class Item1( - val __typename: String, val title: String, + val __typename: String, /** * Synthetic field for inline fragment on ParticularItem */ @@ -65,9 +65,9 @@ class GetPage : Query { ) data class AsParticularItem( - val image: String, + val title: String, val __typename: String, - val title: String + val image: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/test_inline/compat/adapter/GetPage_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/test_inline/compat/adapter/GetPage_ResponseAdapter.kt.expected index e94eb661f8c..189839f2367 100644 --- a/apollo-compiler/src/test/graphql/com/example/test_inline/compat/adapter/GetPage_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/test_inline/compat/adapter/GetPage_ResponseAdapter.kt.expected @@ -130,24 +130,24 @@ object GetPage_ResponseAdapter { } object AsParticularCollection : Adapter { - val RESPONSE_NAMES: List = listOf("items", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "items") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetPage.AsParticularCollection { - var items: List? = null var __typename: String? = null + var items: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> items = Item1.obj(true).list().fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> items = Item1.obj(true).list().fromJson(reader, customScalarAdapters) else -> break } } return GetPage.AsParticularCollection( - items = items!!, - __typename = __typename!! + __typename = __typename!!, + items = items!! ) } @@ -156,26 +156,26 @@ object GetPage_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: GetPage.AsParticularCollection ) { - writer.name("items") - Item1.obj(true).list().toJson(writer, customScalarAdapters, value.items) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("items") + Item1.obj(true).list().toJson(writer, customScalarAdapters, value.items) } } object Item1 : Adapter { - val RESPONSE_NAMES: List = listOf("__typename", "title") + val RESPONSE_NAMES: List = listOf("title", "__typename") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetPage.Item1 { - var __typename: String? = null var title: String? = null + var __typename: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> title = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> title = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } @@ -192,8 +192,8 @@ object GetPage_ResponseAdapter { } return GetPage.Item1( - __typename = __typename, title = title!!, + __typename = __typename, asParticularItem = asParticularItem ) } @@ -203,12 +203,12 @@ object GetPage_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: GetPage.Item1 ) { - writer.name("__typename") - StringAdapter.toJson(writer, customScalarAdapters, value.__typename) - writer.name("title") StringAdapter.toJson(writer, customScalarAdapters, value.title) + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + if (value.asParticularItem != null) { com.example.test_inline.adapter.GetPage_ResponseAdapter.AsParticularItem.toJson(writer, customScalarAdapters, value.asParticularItem) @@ -217,27 +217,27 @@ object GetPage_ResponseAdapter { } object AsParticularItem : Adapter { - val RESPONSE_NAMES: List = listOf("image", "__typename", "title") + val RESPONSE_NAMES: List = listOf("title", "__typename", "image") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GetPage.AsParticularItem { - var image: String? = null - var __typename: String? = null var title: String? = null + var __typename: String? = null + var image: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> image = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> title = StringAdapter.fromJson(reader, customScalarAdapters) 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> title = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> image = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return GetPage.AsParticularItem( - image = image!!, + title = title!!, __typename = __typename!!, - title = title!! + image = image!! ) } @@ -246,14 +246,14 @@ object GetPage_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: GetPage.AsParticularItem ) { - writer.name("image") - StringAdapter.toJson(writer, customScalarAdapters, value.image) + writer.name("title") + StringAdapter.toJson(writer, customScalarAdapters, value.title) writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) - writer.name("title") - StringAdapter.toJson(writer, customScalarAdapters, value.title) + writer.name("image") + StringAdapter.toJson(writer, customScalarAdapters, value.image) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/TestQuery.kt.expected index 29ad861a3a6..ed98171d8e9 100644 --- a/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/TestQuery.kt.expected @@ -52,19 +52,19 @@ class TestQuery : Query { ) data class AsHuman( + val __typename: String, /** * Height in the preferred unit, default is meters */ - val height: Double?, - val __typename: String + val height: Double? ) data class AsDroid( + val __typename: String, /** * What others call this droid */ val name: String, - val __typename: String, /** * This droid's primary function */ diff --git a/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 657336b37ca..89d04ac60ae 100644 --- a/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/typename_always_first/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -117,24 +117,24 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var height: Double? = null var __typename: String? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - height = height, - __typename = __typename!! + __typename = __typename!!, + height = height ) } @@ -143,35 +143,35 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("name", "__typename", "primaryFunction") + val RESPONSE_NAMES: List = listOf("__typename", "name", "primaryFunction") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var name: String? = null var __typename: String? = null + var name: String? = null var primaryFunction: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) 2 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - name = name!!, __typename = __typename!!, + name = name!!, primaryFunction = primaryFunction ) } @@ -181,12 +181,12 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) + writer.name("primaryFunction") NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) } diff --git a/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/TestQuery.kt.expected index 1574aab27ff..63f93de9243 100644 --- a/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/TestQuery.kt.expected @@ -60,11 +60,11 @@ class TestQuery : Query { } data class AsStarship( + val __typename: String, /** * The ID of the starship */ - val id: String, - val __typename: String + val id: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected index 108f8df7806..069ba0ba0a4 100644 --- a/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/union_fragment/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -149,24 +149,24 @@ object TestQuery_ResponseAdapter { } object AsStarship : Adapter { - val RESPONSE_NAMES: List = listOf("id", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "id") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsStarship { - var id: String? = null var __typename: String? = null + var id: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> id = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsStarship( - id = id!!, - __typename = __typename!! + __typename = __typename!!, + id = id!! ) } @@ -175,11 +175,11 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsStarship ) { - writer.name("id") - StringAdapter.toJson(writer, customScalarAdapters, value.id) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("id") + StringAdapter.toJson(writer, customScalarAdapters, value.id) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/TestQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/TestQuery.kt.expected index 30ff687ffb8..d8d5bc0bbf5 100644 --- a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/TestQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/TestQuery.kt.expected @@ -53,6 +53,7 @@ class TestQuery : Query { ) data class AsCharacter( + val __typename: String, /** * The ID of the character */ @@ -64,8 +65,7 @@ class TestQuery : Query { /** * The friends of the character, or an empty list if they have none */ - val friends: List?, - val __typename: String + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -87,6 +87,11 @@ class TestQuery : Query { ) data class AsHuman( + val __typename: String, + /** + * The name of the character + */ + val name: String, /** * The home planet of the human, or null if unknown */ @@ -94,12 +99,7 @@ class TestQuery : Query { /** * This human's friends, or an empty list if they have none */ - val friends: List?, - val __typename: String, - /** - * The name of the character - */ - val name: String + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -113,6 +113,11 @@ class TestQuery : Query { ) data class AsDroid( + val __typename: String, + /** + * The name of the character + */ + val name: String, /** * This droid's primary function */ @@ -120,12 +125,7 @@ class TestQuery : Query { /** * This droid's friends, or an empty list if they have none */ - val friends: List?, - val __typename: String, - /** - * The name of the character - */ - val name: String + val friends: List? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } @@ -138,11 +138,11 @@ class TestQuery : Query { ) data class AsStarship( + val __typename: String, /** * The name of the starship */ - val name: String, - val __typename: String + val name: String ) companion object { diff --git a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/adapter/TestQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/adapter/TestQuery_ResponseAdapter.kt.expected index dd65111a734..6d54829f72d 100644 --- a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/compat/adapter/TestQuery_ResponseAdapter.kt.expected @@ -114,31 +114,31 @@ object TestQuery_ResponseAdapter { } object AsCharacter : Adapter { - val RESPONSE_NAMES: List = listOf("id", "name", "friends", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "id", "name", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsCharacter { + var __typename: String? = null var id: String? = null var name: String? = null var friends: List? = null - var __typename: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> id = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 2 -> friends = Friend2.obj(true).nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> id = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> friends = Friend2.obj(true).nullable().list().nullable().fromJson(reader, customScalarAdapters) - 3 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsCharacter( + __typename = __typename!!, id = id!!, name = name!!, - friends = friends, - __typename = __typename!! + friends = friends ) } @@ -147,6 +147,9 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsCharacter ) { + writer.name("__typename") + StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + writer.name("id") StringAdapter.toJson(writer, customScalarAdapters, value.id) @@ -156,9 +159,6 @@ object TestQuery_ResponseAdapter { writer.name("friends") Friend2.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - - writer.name("__typename") - StringAdapter.toJson(writer, customScalarAdapters, value.__typename) } } @@ -228,31 +228,31 @@ object TestQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("homePlanet", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "homePlanet", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsHuman { - var homePlanet: String? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var homePlanet: String? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend.obj().nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> homePlanet = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> friends = Friend.obj().nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsHuman( - homePlanet = homePlanet, - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + homePlanet = homePlanet, + friends = friends ) } @@ -261,17 +261,17 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsHuman ) { - writer.name("homePlanet") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) - - writer.name("friends") - Friend.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("homePlanet") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.homePlanet) + + writer.name("friends") + Friend.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) } } @@ -311,31 +311,31 @@ object TestQuery_ResponseAdapter { } object AsDroid : Adapter { - val RESPONSE_NAMES: List = listOf("primaryFunction", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "primaryFunction", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsDroid { - var primaryFunction: String? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var primaryFunction: String? = null + var friends: List? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend1.obj().nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> primaryFunction = NullableStringAdapter.fromJson(reader, customScalarAdapters) + 3 -> friends = Friend1.obj().nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsDroid( - primaryFunction = primaryFunction, - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + primaryFunction = primaryFunction, + friends = friends ) } @@ -344,17 +344,17 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsDroid ) { - writer.name("primaryFunction") - NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) - - writer.name("friends") - Friend1.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("primaryFunction") + NullableStringAdapter.toJson(writer, customScalarAdapters, value.primaryFunction) + + writer.name("friends") + Friend1.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) } } @@ -388,24 +388,24 @@ object TestQuery_ResponseAdapter { } object AsStarship : Adapter { - val RESPONSE_NAMES: List = listOf("name", "__typename") + val RESPONSE_NAMES: List = listOf("__typename", "name") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): TestQuery.AsStarship { - var name: String? = null var __typename: String? = null + var name: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) - 1 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return TestQuery.AsStarship( - name = name!!, - __typename = __typename!! + __typename = __typename!!, + name = name!! ) } @@ -414,11 +414,11 @@ object TestQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: TestQuery.AsStarship ) { - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) + + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) } } } diff --git a/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/HeroDetailQuery.kt.expected b/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/HeroDetailQuery.kt.expected index c4f4f03d913..a147bb1a78f 100644 --- a/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/HeroDetailQuery.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/HeroDetailQuery.kt.expected @@ -66,24 +66,28 @@ class HeroDetailQuery : Query { ) data class AsHuman( + val __typename: String, /** - * Height in the preferred unit, default is meters + * The name of the character */ - val height: Double?, + val name: String, /** - * This human's friends, or an empty list if they have none + * The friends of the character, or an empty list if they have none */ val friends: List?, - val __typename: String, /** - * The name of the character + * Height in the preferred unit, default is meters */ - val name: String + val height: Double? ) { fun friendsFilterNotNull(): List? = friends?.filterNotNull() } data class Friend2( + /** + * The name of the character + */ + val name: String, /** * The movies this character appears in */ @@ -91,11 +95,7 @@ class HeroDetailQuery : Query { /** * The friends of the character, or an empty list if they have none */ - val friends: List?, - /** - * The name of the character - */ - val name: String + val friends: List? ) { fun appearsInFilterNotNull(): List = appearsIn.filterNotNull() diff --git a/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/adapter/HeroDetailQuery_ResponseAdapter.kt.expected b/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/adapter/HeroDetailQuery_ResponseAdapter.kt.expected index 6fda9b658df..5f83288db7f 100644 --- a/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/adapter/HeroDetailQuery_ResponseAdapter.kt.expected +++ b/apollo-compiler/src/test/graphql/com/example/unique_type_name/compat/adapter/HeroDetailQuery_ResponseAdapter.kt.expected @@ -144,31 +144,31 @@ object HeroDetailQuery_ResponseAdapter { } object AsHuman : Adapter { - val RESPONSE_NAMES: List = listOf("height", "friends", "__typename", "name") + val RESPONSE_NAMES: List = listOf("__typename", "name", "friends", "height") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.unique_type_name.HeroDetailQuery.AsHuman { - var height: Double? = null - var friends: List? = null var __typename: String? = null var name: String? = null + var friends: List? = null + var height: Double? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) - 1 -> friends = Friend2.obj().nullable().list().nullable().fromJson(reader, + 0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 2 -> friends = Friend2.obj().nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters) - 3 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 3 -> height = NullableDoubleAdapter.fromJson(reader, customScalarAdapters) else -> break } } return com.example.unique_type_name.HeroDetailQuery.AsHuman( - height = height, - friends = friends, __typename = __typename!!, - name = name!! + name = name!!, + friends = friends, + height = height ) } @@ -177,44 +177,44 @@ object HeroDetailQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: com.example.unique_type_name.HeroDetailQuery.AsHuman ) { - writer.name("height") - NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) - - writer.name("friends") - Friend2.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - writer.name("__typename") StringAdapter.toJson(writer, customScalarAdapters, value.__typename) writer.name("name") StringAdapter.toJson(writer, customScalarAdapters, value.name) + + writer.name("friends") + Friend2.obj().nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) + + writer.name("height") + NullableDoubleAdapter.toJson(writer, customScalarAdapters, value.height) } } object Friend2 : Adapter { - val RESPONSE_NAMES: List = listOf("appearsIn", "friends", "name") + val RESPONSE_NAMES: List = listOf("name", "appearsIn", "friends") override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.example.unique_type_name.HeroDetailQuery.Friend2 { + var name: String? = null var appearsIn: List? = null var friends: List? = null - var name: String? = null while(true) { when (reader.selectName(RESPONSE_NAMES)) { - 0 -> appearsIn = Episode_ResponseAdapter.nullable().list().fromJson(reader, + 0 -> name = StringAdapter.fromJson(reader, customScalarAdapters) + 1 -> appearsIn = Episode_ResponseAdapter.nullable().list().fromJson(reader, customScalarAdapters) - 1 -> friends = Friend1.obj(true).nullable().list().nullable().fromJson(reader, + 2 -> friends = Friend1.obj(true).nullable().list().nullable().fromJson(reader, customScalarAdapters) - 2 -> name = StringAdapter.fromJson(reader, customScalarAdapters) else -> break } } return com.example.unique_type_name.HeroDetailQuery.Friend2( + name = name!!, appearsIn = appearsIn!!, - friends = friends, - name = name!! + friends = friends ) } @@ -223,6 +223,9 @@ object HeroDetailQuery_ResponseAdapter { customScalarAdapters: CustomScalarAdapters, value: com.example.unique_type_name.HeroDetailQuery.Friend2 ) { + writer.name("name") + StringAdapter.toJson(writer, customScalarAdapters, value.name) + writer.name("appearsIn") Episode_ResponseAdapter.nullable().list().toJson(writer, customScalarAdapters, value.appearsIn) @@ -230,9 +233,6 @@ object HeroDetailQuery_ResponseAdapter { writer.name("friends") Friend1.obj(true).nullable().list().nullable().toJson(writer, customScalarAdapters, value.friends) - - writer.name("name") - StringAdapter.toJson(writer, customScalarAdapters, value.name) } } diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt index 0cdf2461f15..78ac2d3fb6d 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt @@ -193,7 +193,7 @@ abstract class DefaultApolloExtension( } private fun registerService(service: DefaultService) { - check(services.find { it.name == name } == null) { + check(services.find { it.name == service.name } == null) { "There is already a service named $name, please use another name" } services.add(service) diff --git a/apollo-graphql-ast/src/main/kotlin/com/apollographql/apollo3/ast/transformation/merge_trivial_inline_fragments.kt b/apollo-graphql-ast/src/main/kotlin/com/apollographql/apollo3/ast/transformation/merge_trivial_inline_fragments.kt index 590e428bcc3..430a2ee7fae 100644 --- a/apollo-graphql-ast/src/main/kotlin/com/apollographql/apollo3/ast/transformation/merge_trivial_inline_fragments.kt +++ b/apollo-graphql-ast/src/main/kotlin/com/apollographql/apollo3/ast/transformation/merge_trivial_inline_fragments.kt @@ -17,7 +17,7 @@ fun List.mergeTrivialInlineFragments(schema: Schema, rawTypename: } is GQLFragmentSpread -> listOf(it) is GQLInlineFragment -> { - if (it.typeCondition.name == rawTypename) { + if (it.typeCondition.name == rawTypename && it.directives.isEmpty()) { it.selectionSet.selections.mergeTrivialInlineFragments(schema, rawTypename) } else { listOf( diff --git a/apollo-normalized-cache-api/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/CacheResolver.kt b/apollo-normalized-cache-api/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/CacheResolver.kt index 6d85398fb39..c27710b1f64 100644 --- a/apollo-normalized-cache-api/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/CacheResolver.kt +++ b/apollo-normalized-cache-api/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/CacheResolver.kt @@ -2,20 +2,11 @@ package com.apollographql.apollo3.cache.normalized import com.apollographql.apollo3.api.CompiledArgument import com.apollographql.apollo3.api.CompiledField -import com.apollographql.apollo3.api.CompiledListType import com.apollographql.apollo3.api.CompiledNamedType -import com.apollographql.apollo3.api.CompiledNotNullType import com.apollographql.apollo3.api.Executable -import com.apollographql.apollo3.api.InterfaceType -import com.apollographql.apollo3.api.ObjectType -import com.apollographql.apollo3.api.Optional -import com.apollographql.apollo3.api.UnionType import com.apollographql.apollo3.exception.CacheMissException -import com.apollographql.apollo3.api.isCompound import com.apollographql.apollo3.api.keyFields import com.apollographql.apollo3.api.leafType -import kotlin.jvm.JvmField -import kotlin.jvm.JvmStatic import kotlin.jvm.JvmSuppressWildcards open class CacheResolver { diff --git a/apollo-normalized-cache/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/Normalizer.kt b/apollo-normalized-cache/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/Normalizer.kt index e345bd515c0..135d4ed2c76 100644 --- a/apollo-normalized-cache/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/Normalizer.kt +++ b/apollo-normalized-cache/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/Normalizer.kt @@ -8,7 +8,7 @@ import com.apollographql.apollo3.api.CompiledNotNullType import com.apollographql.apollo3.api.CompiledSelection import com.apollographql.apollo3.api.CompiledType import com.apollographql.apollo3.api.Executable -import com.apollographql.apollo3.api.isCompound +import com.apollographql.apollo3.api.isComposite import com.apollographql.apollo3.cache.normalized.CacheKey import com.apollographql.apollo3.cache.normalized.Record @@ -111,7 +111,7 @@ class Normalizer( } } // Check for [isCompound] as we don't want to build a record for json scalars - type is CompiledNamedType && type.isCompound() -> { + type is CompiledNamedType && type.isComposite() -> { check(value is Map<*, *>) buildRecord(value as Map, path, type, selections) } diff --git a/composite/tests/models-compat/build.gradle.kts b/composite/tests/models-compat/build.gradle.kts index caa43e1bb59..57635496280 100644 --- a/composite/tests/models-compat/build.gradle.kts +++ b/composite/tests/models-compat/build.gradle.kts @@ -24,8 +24,19 @@ kotlin { } apollo { - srcDir(file("../models-fixtures/graphql")) - packageName.set("codegen.models") - generateFragmentImplementations.set(true) - codegenModels.set("compat") + service("service") { + srcDir(file("../models-fixtures/graphql")) + packageName.set("codegen.models") + generateFragmentImplementations.set(true) + codegenModels.set("compat") + } + + file("src/commonTest/kotlin/test").listFiles()!! + .filter { it.isDirectory } + .forEach { + service(it.name) { + srcDir(it) + packageName.set(it.name) + } + } } \ No newline at end of file diff --git a/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/ConditionalInlineFragmentTest.kt b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/ConditionalInlineFragmentTest.kt new file mode 100644 index 00000000000..53ab4421c26 --- /dev/null +++ b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/ConditionalInlineFragmentTest.kt @@ -0,0 +1,24 @@ +package test.conditional_inline_fragment + +import conditional_inline_fragment.GetFieldQuery +import kotlin.test.Test + +class ConditionalInlineFragmentTest { + @Test + fun test() { + /** + * This test makes sure that the inline fragment is not merged since it has an include condition + * Just compiling is enough, so it could in theory be a compiler test but they are so big that it would + * be easy to miss a change in the class structure and parameters + */ + GetFieldQuery.Data( + __typename = "Query", + field1 = "banana", + asQuery = GetFieldQuery.AsQuery( + __typename = "Query", + field1 = "banana", + field2 = "croissant" + ) + ) + } +} \ No newline at end of file diff --git a/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/operations.graphql b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/operations.graphql new file mode 100644 index 00000000000..75bdf605de7 --- /dev/null +++ b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/operations.graphql @@ -0,0 +1,6 @@ +query GetField($withDetails: Boolean!) { + field1 + ... on Query @include(if: $withDetails){ + field2 + } +} \ No newline at end of file diff --git a/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/schema.graphqls b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/schema.graphqls new file mode 100644 index 00000000000..c3fe9e2ca90 --- /dev/null +++ b/composite/tests/models-compat/src/commonTest/kotlin/test/conditional_inline_fragment/graphql/schema.graphqls @@ -0,0 +1,4 @@ +type Query { + field1: String! + field2: String! +} \ No newline at end of file diff --git a/design-docs/Glossary.md b/design-docs/Glossary.md index 7a2c8188524..3af71ae63eb 100644 --- a/design-docs/Glossary.md +++ b/design-docs/Glossary.md @@ -30,7 +30,7 @@ This is the shape of the actual json as returned by the server. A given query ca A leaf type -### Compound type +### Composite type A type that contains sub fields. It is an interface, object or union type