Repository: apollographql/apollo-kotlin
Pull request #4384 (2022-09-13 13:05:54)

Add a CacheAndNetwork policy test to the pagination (incubating) tests.
Also migrate these tests to Data Builders.

netlify[bot]: ### <span aria-hidden="true">✅</span> Deploy Preview for *apollo-android-docs* canceled.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | c8c123e8e26a8076bc8f2fa6b0d101bceb6e0460 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-android-docs/deploys/6320803338938a000aa74c3f |

Patch:
diff --git a/ROADMAP.md b/ROADMAP.md
index 0e03d530b7..c166ccfa9f 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -1,6 +1,6 @@
 # 🔮 Apollo Kotlin Roadmap
 
-**Last updated: Aug 2022**
+**Last updated: Sept 2022**
 
 For up to date release notes, refer to the project [Change Log](https://github.com/apollographql/apollo-kotlin/blob/main/CHANGELOG.md).
 
@@ -15,9 +15,9 @@ For up to date release notes, refer to the project [Change Log](https://github.c
 
 ## Upcoming Releases
 
-### 3.6
+### Release TBD
 
-- Release 3.6 will focus on adding support for the `@defer` directive as well as adding `schemaBased` test builders. See Github [3.6 Milestone](https://github.com/apollographql/apollo-kotlin/milestone/23) for more details.
+- This release will focus on providing better Java support in Apollo Kotlin.  See Github [Java Support Release TBD](https://github.com/apollographql/apollo-kotlin/milestone/25) for more details.
 
 ## Longer Term
 
@@ -25,14 +25,14 @@ For up to date release notes, refer to the project [Change Log](https://github.c
 
 The declarative cache makes working with the cache and defining unique object ids easier. We also want to include helpers to handle with common cases like pagination, garbage collection and eviction. Follow [#2331](https://github.com/apollographql/apollo-kotlin/issues/2331) for a high level overview. The current focus is on cache control and expiration. You can read more in [the cache control design document](https://github.com/apollographql/apollo-kotlin/pull/4009).
 
-### Test APIs
-
-Apollo Kotlin 3 introduces [test builders](https://www.apollographql.com/docs/kotlin/testing/test-builders/) as a new type-safe way to build test data. While this is working, it generates a lot of code, making it hard to include in main source sets. This can be problematic in some cases like Jetpack Compose `@Preview` for an example. We are investigating generating schema-based test builders for simpler and more lightweight APIs.
-
 ### Rel 1.0 Android Studio Plugin
 
 Currently there is no plugin for Android Studio for Apollo GraphQL. We'd like to offer better support for Android developers who wish to use our Kotlin Client.
 
+### Better support for Jetpack Compose
+
+[Jetpack Compose](https://developer.android.com/jetpack/compose) is a declarative UI framework for building Android UIs written in Kotlin. We'd like to offer better support for Android developers who wish to use Jetpack Compose with our Kotlin Client.
+
 ### `release-2.x` branch
 
 `release-2.x` is the Apollo Android `2.x` branch. Major security issues or fixes will get new releases.
diff --git a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/internal/DeferredJsonMerger.kt b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/internal/DeferredJsonMerger.kt
index 83acb0f79e..51aa867a80 100644
--- a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/internal/DeferredJsonMerger.kt
+++ b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/internal/DeferredJsonMerger.kt
@@ -34,6 +34,14 @@ class DeferredJsonMerger {
   var hasNext: Boolean = true
     private set
 
+  /**
+   * A payload can sometimes have no `incremental` field, e.g. when the server couldn't predict if there were more data after the last
+   * emitted payload. This field allows to test for this in order to ignore such payloads.
+   * See https://github.com/apollographql/router/issues/1687.
+   */
+  var isEmptyPayload: Boolean = false
+    private set
+
   fun merge(payload: BufferedSource): JsonMap {
     val payloadMap = jsonToMap(payload)
     return merge(payloadMap)
@@ -48,7 +56,10 @@ class DeferredJsonMerger {
     }
 
     val incrementalList = payload["incremental"] as? List<JsonMap>
-    if (incrementalList != null) {
+    if (incrementalList == null) {
+      isEmptyPayload = true
+    } else {
+      isEmptyPayload = false
       val mergedErrors = mutableListOf<JsonMap>()
       val mergedExtensions = mutableListOf<JsonMap>()
       for (incrementalItem in incrementalList) {
@@ -131,6 +142,7 @@ class DeferredJsonMerger {
     _merged.clear()
     _mergedFragmentIds.clear()
     hasNext = true
+    isEmptyPayload = false
   }
 }
 
diff --git a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt
index 37b60b68f9..bc7107e1aa 100644
--- a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt
+++ b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt
@@ -23,6 +23,7 @@ import com.apollographql.apollo3.network.NetworkTransport
 import com.benasher44.uuid.Uuid
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.emitAll
+import kotlinx.coroutines.flow.filterNot
 import kotlinx.coroutines.flow.flow
 import kotlinx.coroutines.flow.map
 
@@ -110,19 +111,21 @@ private constructor(
       httpResponse: HttpResponse,
   ): Flow<ApolloResponse<D>> {
     val jsonMerger = DeferredJsonMerger()
-    return multipartBodyFlow(httpResponse).map { part ->
-      try {
-        val merged = jsonMerger.merge(part)
-        val deferredFragmentIds = jsonMerger.mergedFragmentIds
-        val isLast = !jsonMerger.hasNext
-        operation.parseJsonResponse(
-            jsonReader = merged.jsonReader(),
-            customScalarAdapters = customScalarAdapters.withDeferredFragmentIds(deferredFragmentIds)
-        ).newBuilder().isLast(isLast).build()
-      } catch (e: Exception) {
-        throw wrapThrowableIfNeeded(e)
-      }
-    }
+    return multipartBodyFlow(httpResponse)
+        .map { part ->
+          try {
+            val merged = jsonMerger.merge(part)
+            val deferredFragmentIds = jsonMerger.mergedFragmentIds
+            val isLast = !jsonMerger.hasNext
+            operation.parseJsonResponse(
+                jsonReader = merged.jsonReader(),
+                customScalarAdapters = customScalarAdapters.withDeferredFragmentIds(deferredFragmentIds)
+            ).newBuilder().isLast(isLast).build()
+          } catch (e: Exception) {
+            throw wrapThrowableIfNeeded(e)
+          }
+        }
+        .filterNot { jsonMerger.isEmptyPayload }
   }
 
   private fun <D : Operation.Data> ApolloResponse<D>.withHttpInfo(
diff --git a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/LoggingInterceptor.kt b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/LoggingInterceptor.kt
index 49311df78f..0284842831 100644
--- a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/LoggingInterceptor.kt
+++ b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/LoggingInterceptor.kt
@@ -10,7 +10,7 @@ import kotlin.jvm.JvmOverloads
 /**
  * An interceptor that logs requests and responses.
  *
- * @param level the level of logging. Caution: when uploading files, setting this to [Level.BODY] will cause the files to
+ * @param [level] the level of logging. Caution: when uploading files, setting this to [Level.BODY] will cause the files to
  * be fully loaded into memory, which may cause OutOfMemoryErrors.
  */
 class LoggingInterceptor(
@@ -21,9 +21,56 @@ class LoggingInterceptor(
   constructor(log: (String) -> Unit = { println(it) }) : this(level = Level.BODY, log = log)
 
   enum class Level {
+    /** No logs. */
     NONE,
+
+    /**
+     * Logs HTTP method, request target, and response code.
+     *
+     * Example:
+     * ```
+     * Post /graphql
+     *
+     * HTTP: 200
+     * ```
+     */
     BASIC,
+    
+    /**
+     * Logs HTTP method, request target, response code, and headers.
+     *
+     * Example:
+     * ```
+     * Post /graphql
+     * X-APOLLO-OPERATION-ID: 9311
+     * Accept: multipart/mixed; deferSpec=20220824, application/json
+     * [end of headers]
+     *
+     * HTTP: 200
+     * Content-Type: application/json; charset=utf-8
+     * Content-Length: 2716
+     * [end of headers]
+     * ```
+     */
     HEADERS,
+     
+    /**
+     * Logs HTTP method, request target, response code, headers, and bodies.
+     *
+     * Example:
+     * ```
+     * Post /graphql
+     * X-APOLLO-OPERATION-ID: 9311
+     * [end of headers]
+     * {"operationName":"LaunchList","variables":{"cursor":"1584533760"},"query":"query LaunchList($cursor: String)}
+     *
+     * HTTP: 200
+     * Content-Type: application/json; charset=utf-8
+     * Content-Length: 2716
+     * [end of headers]
+     * {"data":{"launches":{"cursor":"1544033760","hasMore":true,"launches":[...]}}}
+     * ```
+     */
     BODY,
   }
 
diff --git a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/ws/WebSocketNetworkTransport.kt b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/ws/WebSocketNetworkTransport.kt
index 49b66a4d5d..683d8b2105 100644
--- a/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/ws/WebSocketNetworkTransport.kt
+++ b/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/ws/WebSocketNetworkTransport.kt
@@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.MutableSharedFlow
 import kotlinx.coroutines.flow.asSharedFlow
 import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.filterNot
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.onCompletion
 import kotlinx.coroutines.flow.onSubscription
@@ -303,12 +304,15 @@ private constructor(
           }
           apolloResponse
         }
+
         is OperationError -> throw SubscriptionOperationException(request.operation.name(), response.payload)
         is NetworkError -> throw ApolloNetworkException("Network error while executing ${request.operation.name()}", response.cause)
 
         // Cannot happen as these events are filtered out upstream
         is OperationComplete, is GeneralError -> error("Unexpected event $response")
       }
+    }.filterNot {
+      deferredJsonMerger.isEmptyPayload
     }.onCompletion {
       messages.send(StopOperation(request))
     }


Test patch:
diff --git a/apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferJsonMergerTest.kt b/apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferredJsonMergerTest.kt
similarity index 86%
rename from apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferJsonMergerTest.kt
rename to apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferredJsonMergerTest.kt
index 5b06a81f20..f858e6daaf 100644
--- a/apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferJsonMergerTest.kt
+++ b/apollo-runtime/src/commonTest/kotlin/com/apollographql/apollo3/internal/DeferredJsonMergerTest.kt
@@ -9,13 +9,15 @@ import com.apollographql.apollo3.api.json.readAny
 import okio.Buffer
 import kotlin.test.Test
 import kotlin.test.assertEquals
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
 
-class DeferJsonMergerTest {
-  @Test
-  fun mergeJsonSingleIncrementalItem() {
-      val deferredJsonMerger = DeferredJsonMerger()
+class DeferredJsonMergerTest {
+    @Test
+    fun mergeJsonSingleIncrementalItem() {
+        val deferredJsonMerger = DeferredJsonMerger()
 
-      val payload1 = """
+        val payload1 = """
       {
         "data": {
           "computers": [
@@ -352,14 +354,14 @@ class DeferJsonMergerTest {
         ]
       }
     """
-      deferredJsonMerger.merge(payload5.buffer())
-      assertEquals(jsonToMap(mergedPayloads_1_2_3_4_5), deferredJsonMerger.merged)
-      assertEquals(setOf(
-          DeferredFragmentIdentifier(path = listOf("computers", 0), label = "query:Query1:0"),
-          DeferredFragmentIdentifier(path = listOf("computers", 1), label = "query:Query1:0"),
-          DeferredFragmentIdentifier(path = listOf("computers", 1, "screen"), label = "fragment:ComputerFields:0"),
-      ), deferredJsonMerger.mergedFragmentIds)
-  }
+        deferredJsonMerger.merge(payload5.buffer())
+        assertEquals(jsonToMap(mergedPayloads_1_2_3_4_5), deferredJsonMerger.merged)
+        assertEquals(setOf(
+            DeferredFragmentIdentifier(path = listOf("computers", 0), label = "query:Query1:0"),
+            DeferredFragmentIdentifier(path = listOf("computers", 1), label = "query:Query1:0"),
+            DeferredFragmentIdentifier(path = listOf("computers", 1, "screen"), label = "fragment:ComputerFields:0"),
+        ), deferredJsonMerger.mergedFragmentIds)
+    }
 
     @Test
     fun mergeJsonMultipleIncrementalItems() {
@@ -624,6 +626,81 @@ class DeferJsonMergerTest {
             DeferredFragmentIdentifier(path = listOf("computers", 1, "screen"), label = "fragment:ComputerFields:0"),
         ), deferredJsonMerger.mergedFragmentIds)
     }
+
+    @Test
+    fun emptyPayloads() {
+        val deferredJsonMerger = DeferredJsonMerger()
+
+        val payload1 = """
+      {
+        "data": {
+          "computers": [
+            {
+              "id": "Computer1",
+              "screen": {
+                "isTouch": true
+              }
+            },
+            {
+              "id": "Computer2",
+              "screen": {
+                "isTouch": false
+              }
+            }
+          ]
+        },
+        "hasNext": true
+      }
+    """
+        deferredJsonMerger.merge(payload1.buffer())
+        assertFalse(deferredJsonMerger.isEmptyPayload)
+
+        val payload2 = """
+      {
+        "hasNext": true
+      }
+    """
+        deferredJsonMerger.merge(payload2.buffer())
+        assertTrue(deferredJsonMerger.isEmptyPayload)
+
+        val payload3 = """
+      {
+        "incremental": [
+          {
+            "data": {
+              "cpu": "386",
+              "year": 1993,
+              "screen": {
+                "resolution": "640x480"
+              }
+            },
+            "path": [
+              "computers",
+              0
+            ],
+            "label": "query:Query1:0",
+            "extensions": {
+              "duration": {
+                "amount": 100,
+                "unit": "ms"
+              }
+            }
+          }
+        ],
+        "hasNext": true
+      }
+    """
+        deferredJsonMerger.merge(payload3.buffer())
+        assertFalse(deferredJsonMerger.isEmptyPayload)
+
+        val payload4 = """
+      {
+        "hasNext": false
+      }
+    """
+        deferredJsonMerger.merge(payload4.buffer())
+        assertTrue(deferredJsonMerger.isEmptyPayload)
+    }
 }
 
 private fun String.buffer() = Buffer().writeUtf8(this)
diff --git a/tests/defer/README.md b/tests/defer/README.md
index f592d552d8..ba3ebf7c4d 100644
--- a/tests/defer/README.md
+++ b/tests/defer/README.md
@@ -1,5 +1,4 @@
 # Tests related to `@defer`
 
-At the moment the tests use `StreamingNSURLSessionHttpEngine` on Apple targets, which requires
-the [new Memory Manager](https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md). It is enabled on this
-project in `gradle.propertis`.
+Note: on Apple targets, the client is configured to use `StreamingNSURLSessionHttpEngine` which supports chunked
+encoding.  
diff --git a/tests/defer/src/commonMain/graphql/base/operation.graphql b/tests/defer/src/commonMain/graphql/base/operation.graphql
index a8f3dfb722..c7a2489148 100644
--- a/tests/defer/src/commonMain/graphql/base/operation.graphql
+++ b/tests/defer/src/commonMain/graphql/base/operation.graphql
@@ -62,3 +62,12 @@ subscription WithFragmentSpreadsSubscription {
 fragment CounterFields on Counter{
   valueTimesTwo
 }
+
+query SimpleDeferQuery {
+  computers {
+    id
+    ... on Computer @defer {
+      cpu
+    }
+  }
+}
diff --git a/tests/defer/src/commonTest/kotlin/test/DeferTest.kt b/tests/defer/src/commonTest/kotlin/test/DeferTest.kt
index 069e01ff62..ba9b353ec6 100644
--- a/tests/defer/src/commonTest/kotlin/test/DeferTest.kt
+++ b/tests/defer/src/commonTest/kotlin/test/DeferTest.kt
@@ -11,6 +11,7 @@ import com.apollographql.apollo3.mpp.currentTimeMillis
 import com.apollographql.apollo3.mpp.platform
 import com.apollographql.apollo3.testing.internal.runTest
 import com.benasher44.uuid.uuid4
+import defer.SimpleDeferQuery
 import defer.WithFragmentSpreadsQuery
 import defer.WithInlineFragmentsQuery
 import defer.fragment.ComputerFields
@@ -285,4 +286,34 @@ class DeferTest {
     }
     job.cancel()
   }
+
+  @Test
+  fun emptyPayloadsAreIgnored() = runTest(before = { setUp() }, after = { tearDown() }) {
+    val jsonWithEmptyPayload = listOf(
+        """{"data":{"computers":[{"__typename":"Computer","id":"computer1"}]},"hasNext":true}""",
+        """{"incremental": [{"data":{"cpu":"386"},"path":["computers",0]}],"hasNext":true}""",
+        """{"hasNext":false}""",
+    )
+    val jsonWithoutEmptyPayload = listOf(
+        """{"data":{"computers":[{"__typename":"Computer","id":"computer1"}]},"hasNext":true}""",
+        """{"incremental": [{"data":{"cpu":"386"},"path":["computers",0]}],"hasNext":false}""",
+    )
+
+    val expectedDataList = listOf(
+        SimpleDeferQuery.Data(
+            listOf(SimpleDeferQuery.Computer("Computer", "computer1", null))
+        ),
+        SimpleDeferQuery.Data(
+            listOf(SimpleDeferQuery.Computer("Computer", "computer1", SimpleDeferQuery.OnComputer("386")))
+        ),
+    )
+
+    mockServer.enqueueMultipart(jsonWithEmptyPayload)
+    var actualDataList = apolloClient.query(SimpleDeferQuery()).toFlow().toList().map { it.dataAssertNoErrors }
+    assertEquals(expectedDataList, actualDataList)
+
+    mockServer.enqueueMultipart(jsonWithoutEmptyPayload)
+    actualDataList = apolloClient.query(SimpleDeferQuery()).toFlow().toList().map { it.dataAssertNoErrors }
+    assertEquals(expectedDataList, actualDataList)
+  }
 }
diff --git a/tests/pagination/build.gradle.kts b/tests/pagination/build.gradle.kts
index d2a8dacdfd..008a0427a6 100644
--- a/tests/pagination/build.gradle.kts
+++ b/tests/pagination/build.gradle.kts
@@ -32,7 +32,7 @@ apollo {
   service("pagination") {
     packageName.set("pagination")
     sourceFolder.set("pagination")
-    generateTestBuilders.set(true)
+    generateDataBuilders.set(true)
   }
   service("embed") {
     packageName.set("embed")
diff --git a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt
index ae39149a85..a622149c93 100644
--- a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt
+++ b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt
@@ -1,17 +1,27 @@
 package pagination
 
+import com.apollographql.apollo3.ApolloClient
 import com.apollographql.apollo3.api.Optional
 import com.apollographql.apollo3.cache.normalized.ApolloStore
+import com.apollographql.apollo3.cache.normalized.FetchPolicy
 import com.apollographql.apollo3.cache.normalized.api.ConnectionMetadataGenerator
 import com.apollographql.apollo3.cache.normalized.api.ConnectionRecordMerger
 import com.apollographql.apollo3.cache.normalized.api.FieldPolicyApolloResolver
 import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
 import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
 import com.apollographql.apollo3.cache.normalized.api.TypePolicyCacheKeyGenerator
+import com.apollographql.apollo3.cache.normalized.fetchPolicy
+import com.apollographql.apollo3.cache.normalized.normalizedCache
 import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
+import com.apollographql.apollo3.testing.QueueTestNetworkTransport
+import com.apollographql.apollo3.testing.enqueueTestResponse
 import com.apollographql.apollo3.testing.internal.runTest
-import pagination.test.UsersCursorBasedQuery_TestBuilder.Data
+import kotlinx.coroutines.flow.toList
+import pagination.type.buildUser
+import pagination.type.buildUserConnection
+import pagination.type.buildUserEdge
 import kotlin.test.Test
+import kotlin.test.assertContentEquals
 import kotlin.test.assertEquals
 
 class CursorBasedPaginationTest {
@@ -48,17 +58,17 @@ class CursorBasedPaginationTest {
     // First page
     val query1 = UsersCursorBasedQuery(first = Optional.Present(2))
     val data1 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
@@ -73,17 +83,17 @@ class CursorBasedPaginationTest {
     // Page after
     val query2 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx43"))
     val data2 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
@@ -93,29 +103,29 @@ class CursorBasedPaginationTest {
     apolloStore.writeOperation(query2, data2)
     dataFromStore = apolloStore.readOperation(query1)
     var expectedData = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
@@ -128,17 +138,17 @@ class CursorBasedPaginationTest {
     // Page after
     val query3 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx45"))
     val data3 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -148,41 +158,41 @@ class CursorBasedPaginationTest {
     apolloStore.writeOperation(query3, data3)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -195,17 +205,17 @@ class CursorBasedPaginationTest {
     // Page before
     val query4 = UsersCursorBasedQuery(last = Optional.Present(2), before = Optional.Present("xx42"))
     val data4 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx40"
-              node = node {
+              node = buildUser {
                 id = "40"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx41"
-              node = node {
+              node = buildUser {
                 id = "41"
               }
             },
@@ -215,53 +225,53 @@ class CursorBasedPaginationTest {
     apolloStore.writeOperation(query4, data4)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx40"
-              node = node {
+              node = buildUser {
                 id = "40"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx41"
-              node = node {
+              node = buildUser {
                 id = "41"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -274,17 +284,17 @@ class CursorBasedPaginationTest {
     // Non-contiguous page (should reset)
     val query5 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx50"))
     val data5 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx50"
-              node = node {
+              node = buildUser {
                 id = "50"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx51"
-              node = node {
+              node = buildUser {
                 id = "51"
               }
             },
@@ -299,7 +309,7 @@ class CursorBasedPaginationTest {
     // Empty page (should keep previous result)
     val query6 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx51"))
     val data6 = UsersCursorBasedQuery.Data {
-      usersCursorBased = usersCursorBased {
+      usersCursorBased = buildUserConnection {
         edges = emptyList()
       }
     }
@@ -308,5 +318,130 @@ class CursorBasedPaginationTest {
     assertEquals(data5, dataFromStore)
     assertChainedCachesAreEqual(apolloStore)
   }
+
+  @Test
+  fun cacheAndNetworkPolicy() = runTest {
+    val apolloClient = ApolloClient.Builder()
+        .networkTransport(QueueTestNetworkTransport())
+        .normalizedCache(
+            normalizedCacheFactory = MemoryCacheFactory(),
+            cacheKeyGenerator = TypePolicyCacheKeyGenerator,
+            metadataGenerator = ConnectionMetadataGenerator(setOf("UserConnection")),
+            apolloResolver = FieldPolicyApolloResolver,
+            recordMerger = ConnectionRecordMerger
+        )
+        .build()
+
+    // First page
+    val query1 = UsersCursorBasedQuery(first = Optional.Present(2))
+    val data1 = UsersCursorBasedQuery.Data {
+      usersCursorBased = buildUserConnection {
+        edges = listOf(
+            buildUserEdge {
+              cursor = "xx42"
+              node = buildUser {
+                id = "42"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx43"
+              node = buildUser {
+                id = "43"
+              }
+            },
+        )
+      }
+    }
+    apolloClient.enqueueTestResponse(query1, data1)
+    var resultData = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlow().toList().map { it.data }
+    // Cache: nothing
+    // Network: data1
+    assertContentEquals(listOf(data1), resultData)
+
+
+    // Page after
+    val query2 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx43"))
+    val data2 = UsersCursorBasedQuery.Data {
+      usersCursorBased = buildUserConnection {
+        edges = listOf(
+            buildUserEdge {
+              cursor = "xx44"
+              node = buildUser {
+                id = "44"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx45"
+              node = buildUser {
+                id = "45"
+              }
+            },
+        )
+      }
+    }
+    apolloClient.enqueueTestResponse(query2, data2)
+    resultData = apolloClient.query(query2).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlow().toList().map { it.data }
+    // Cache: data1
+    // Network: data2
+    assertContentEquals(listOf(data1, data2), resultData)
+
+
+    // Page after
+    val query3 = UsersCursorBasedQuery(first = Optional.Present(2), after = Optional.Present("xx45"))
+    val data3 = UsersCursorBasedQuery.Data {
+      usersCursorBased = buildUserConnection {
+        edges = listOf(
+            buildUserEdge {
+              cursor = "xx46"
+              node = buildUser {
+                id = "46"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx47"
+              node = buildUser {
+                id = "47"
+              }
+            },
+        )
+      }
+    }
+    apolloClient.enqueueTestResponse(query3, data3)
+    resultData = apolloClient.query(query3).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlow().toList().map { it.data }
+    // Cache: data1 merged with data2
+    val data1MergedWith2 = UsersCursorBasedQuery.Data {
+      usersCursorBased = buildUserConnection {
+        edges = listOf(
+            buildUserEdge {
+              cursor = "xx42"
+              node = buildUser {
+                id = "42"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx43"
+              node = buildUser {
+                id = "43"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx44"
+              node = buildUser {
+                id = "44"
+              }
+            },
+            buildUserEdge {
+              cursor = "xx45"
+              node = buildUser {
+                id = "45"
+              }
+            },
+        )
+      }
+    }
+    // Network: data3
+    assertContentEquals(listOf(data1MergedWith2, data3), resultData)
+  }
+
 }
 
diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt
index 0c35134e5c..3b0de65af9 100644
--- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt
+++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt
@@ -11,7 +11,7 @@ import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
 import com.apollographql.apollo3.cache.normalized.api.TypePolicyCacheKeyGenerator
 import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
 import com.apollographql.apollo3.testing.internal.runTest
-import pagination.test.UsersOffsetBasedWithArrayQuery_TestBuilder.Data
+import pagination.type.buildUser
 import kotlin.math.max
 import kotlin.math.min
 import kotlin.test.Test
@@ -52,8 +52,8 @@ class OffsetBasedWithArrayPaginationTest {
     val query1 = UsersOffsetBasedWithArrayQuery(offset = Optional.Present(42), limit = Optional.Present(2))
     val data1 = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "42" },
-          usersOffsetBasedWithArray { id = "43" },
+          buildUser { id = "42" },
+          buildUser { id = "43" },
       )
     }
     apolloStore.writeOperation(query1, data1)
@@ -65,18 +65,18 @@ class OffsetBasedWithArrayPaginationTest {
     val query2 = UsersOffsetBasedWithArrayQuery(offset = Optional.Present(44), limit = Optional.Present(2))
     val data2 = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "44" },
-          usersOffsetBasedWithArray { id = "45" },
+          buildUser { id = "44" },
+          buildUser { id = "45" },
       )
     }
     apolloStore.writeOperation(query2, data2)
     dataFromStore = apolloStore.readOperation(query1)
     var expectedData = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "42" },
-          usersOffsetBasedWithArray { id = "43" },
-          usersOffsetBasedWithArray { id = "44" },
-          usersOffsetBasedWithArray { id = "45" },
+          buildUser { id = "42" },
+          buildUser { id = "43" },
+          buildUser { id = "44" },
+          buildUser { id = "45" },
       )
     }
     assertEquals(expectedData, dataFromStore)
@@ -86,20 +86,20 @@ class OffsetBasedWithArrayPaginationTest {
     val query3 = UsersOffsetBasedWithArrayQuery(offset = Optional.Present(44), limit = Optional.Present(3))
     val data3 = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "44" },
-          usersOffsetBasedWithArray { id = "45" },
-          usersOffsetBasedWithArray { id = "46" },
+          buildUser { id = "44" },
+          buildUser { id = "45" },
+          buildUser { id = "46" },
       )
     }
     apolloStore.writeOperation(query3, data3)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "42" },
-          usersOffsetBasedWithArray { id = "43" },
-          usersOffsetBasedWithArray { id = "44" },
-          usersOffsetBasedWithArray { id = "45" },
-          usersOffsetBasedWithArray { id = "46" },
+          buildUser { id = "42" },
+          buildUser { id = "43" },
+          buildUser { id = "44" },
+          buildUser { id = "45" },
+          buildUser { id = "46" },
       )
     }
     assertEquals(expectedData, dataFromStore)
@@ -109,21 +109,21 @@ class OffsetBasedWithArrayPaginationTest {
     val query4 = UsersOffsetBasedWithArrayQuery(offset = Optional.Present(40), limit = Optional.Present(2))
     val data4 = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "40" },
-          usersOffsetBasedWithArray { id = "41" },
+          buildUser { id = "40" },
+          buildUser { id = "41" },
       )
     }
     apolloStore.writeOperation(query4, data4)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "40" },
-          usersOffsetBasedWithArray { id = "41" },
-          usersOffsetBasedWithArray { id = "42" },
-          usersOffsetBasedWithArray { id = "43" },
-          usersOffsetBasedWithArray { id = "44" },
-          usersOffsetBasedWithArray { id = "45" },
-          usersOffsetBasedWithArray { id = "46" },
+          buildUser { id = "40" },
+          buildUser { id = "41" },
+          buildUser { id = "42" },
+          buildUser { id = "43" },
+          buildUser { id = "44" },
+          buildUser { id = "45" },
+          buildUser { id = "46" },
       )
     }
     assertEquals(expectedData, dataFromStore)
@@ -133,8 +133,8 @@ class OffsetBasedWithArrayPaginationTest {
     val query5 = UsersOffsetBasedWithArrayQuery(offset = Optional.Present(50), limit = Optional.Present(2))
     val data5 = UsersOffsetBasedWithArrayQuery.Data {
       usersOffsetBasedWithArray = listOf(
-          usersOffsetBasedWithArray { id = "50" },
-          usersOffsetBasedWithArray { id = "51" },
+          buildUser { id = "50" },
+          buildUser { id = "51" },
       )
     }
     apolloStore.writeOperation(query5, data5)
diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt
index 1b4e15cdca..b87bf0808a 100644
--- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt
+++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt
@@ -14,7 +14,8 @@ import com.apollographql.apollo3.cache.normalized.api.internal.OptimisticCache
 import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
 import com.apollographql.apollo3.testing.internal.runTest
 import com.squareup.sqldelight.internal.AtomicBoolean
-import pagination.test.UsersOffsetBasedWithPageQuery_TestBuilder.Data
+import pagination.type.buildUser
+import pagination.type.buildUserPage
 import kotlin.math.max
 import kotlin.math.min
 import kotlin.test.Test
@@ -55,10 +56,10 @@ class OffsetBasedWithPagePaginationTest {
     // First page
     val query1 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(42), limit = Optional.Present(2))
     val data1 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "42" },
-            user { id = "43" },
+            buildUser { id = "42" },
+            buildUser { id = "43" },
         )
       }
     }
@@ -70,22 +71,22 @@ class OffsetBasedWithPagePaginationTest {
     // Page after
     val query2 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(44), limit = Optional.Present(2))
     val data2 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "44" },
-            user { id = "45" },
+            buildUser { id = "44" },
+            buildUser { id = "45" },
         )
       }
     }
     apolloStore.writeOperation(query2, data2)
     dataFromStore = apolloStore.readOperation(query1)
     var expectedData = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "42" },
-            user { id = "43" },
-            user { id = "44" },
-            user { id = "45" },
+            buildUser { id = "42" },
+            buildUser { id = "43" },
+            buildUser { id = "44" },
+            buildUser { id = "45" },
         )
       }
     }
@@ -95,24 +96,24 @@ class OffsetBasedWithPagePaginationTest {
     // Page in the middle
     val query3 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(44), limit = Optional.Present(3))
     val data3 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "44" },
-            user { id = "45" },
-            user { id = "46" },
+            buildUser { id = "44" },
+            buildUser { id = "45" },
+            buildUser { id = "46" },
         )
       }
     }
     apolloStore.writeOperation(query3, data3)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "42" },
-            user { id = "43" },
-            user { id = "44" },
-            user { id = "45" },
-            user { id = "46" },
+            buildUser { id = "42" },
+            buildUser { id = "43" },
+            buildUser { id = "44" },
+            buildUser { id = "45" },
+            buildUser { id = "46" },
         )
       }
     }
@@ -122,25 +123,25 @@ class OffsetBasedWithPagePaginationTest {
     // Page before
     val query4 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(40), limit = Optional.Present(2))
     val data4 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "40" },
-            user { id = "41" },
+            buildUser { id = "40" },
+            buildUser { id = "41" },
         )
       }
     }
     apolloStore.writeOperation(query4, data4)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "40" },
-            user { id = "41" },
-            user { id = "42" },
-            user { id = "43" },
-            user { id = "44" },
-            user { id = "45" },
-            user { id = "46" },
+            buildUser { id = "40" },
+            buildUser { id = "41" },
+            buildUser { id = "42" },
+            buildUser { id = "43" },
+            buildUser { id = "44" },
+            buildUser { id = "45" },
+            buildUser { id = "46" },
         )
       }
     }
@@ -150,10 +151,10 @@ class OffsetBasedWithPagePaginationTest {
     // Non-contiguous page (should reset)
     val query5 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(50), limit = Optional.Present(2))
     val data5 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = listOf(
-            user { id = "50" },
-            user { id = "51" },
+            buildUser { id = "50" },
+            buildUser { id = "51" },
         )
       }
     }
@@ -165,7 +166,7 @@ class OffsetBasedWithPagePaginationTest {
     // Empty page (should keep previous result)
     val query6 = UsersOffsetBasedWithPageQuery(offset = Optional.Present(52), limit = Optional.Present(2))
     val data6 = UsersOffsetBasedWithPageQuery.Data {
-      usersOffsetBasedWithPage = usersOffsetBasedWithPage {
+      usersOffsetBasedWithPage = buildUserPage {
         users = emptyList()
       }
     }
diff --git a/tests/pagination/src/commonTest/kotlin/TypePolicyConnectionFieldsTest.kt b/tests/pagination/src/commonTest/kotlin/TypePolicyConnectionFieldsTest.kt
index 1408ac2691..48b46949fe 100644
--- a/tests/pagination/src/commonTest/kotlin/TypePolicyConnectionFieldsTest.kt
+++ b/tests/pagination/src/commonTest/kotlin/TypePolicyConnectionFieldsTest.kt
@@ -11,7 +11,9 @@ import com.apollographql.apollo3.cache.normalized.api.TypePolicyCacheKeyGenerato
 import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
 import com.apollographql.apollo3.testing.internal.runTest
 import pagination.pagination.Pagination
-import pagination.test.WithTypePolicyDirectiveQuery_TestBuilder.Data
+import pagination.type.buildUser
+import pagination.type.buildUserConnection2
+import pagination.type.buildUserEdge
 import kotlin.test.Test
 import kotlin.test.assertEquals
 
@@ -49,17 +51,17 @@ class TypePolicyConnectionFieldsTest {
     // First page
     val query1 = WithTypePolicyDirectiveQuery(first = Optional.Present(2))
     val data1 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
@@ -74,17 +76,17 @@ class TypePolicyConnectionFieldsTest {
     // Page after
     val query2 = WithTypePolicyDirectiveQuery(first = Optional.Present(2), after = Optional.Present("xx43"))
     val data2 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
@@ -94,29 +96,29 @@ class TypePolicyConnectionFieldsTest {
     apolloStore.writeOperation(query2, data2)
     dataFromStore = apolloStore.readOperation(query1)
     var expectedData = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
@@ -129,17 +131,17 @@ class TypePolicyConnectionFieldsTest {
     // Page after
     val query3 = WithTypePolicyDirectiveQuery(first = Optional.Present(2), after = Optional.Present("xx45"))
     val data3 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -149,41 +151,41 @@ class TypePolicyConnectionFieldsTest {
     apolloStore.writeOperation(query3, data3)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -196,17 +198,17 @@ class TypePolicyConnectionFieldsTest {
     // Page before
     val query4 = WithTypePolicyDirectiveQuery(last = Optional.Present(2), before = Optional.Present("xx42"))
     val data4 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx40"
-              node = node {
+              node = buildUser {
                 id = "40"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx41"
-              node = node {
+              node = buildUser {
                 id = "41"
               }
             },
@@ -216,53 +218,53 @@ class TypePolicyConnectionFieldsTest {
     apolloStore.writeOperation(query4, data4)
     dataFromStore = apolloStore.readOperation(query1)
     expectedData = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx40"
-              node = node {
+              node = buildUser {
                 id = "40"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx41"
-              node = node {
+              node = buildUser {
                 id = "41"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx42"
-              node = node {
+              node = buildUser {
                 id = "42"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx43"
-              node = node {
+              node = buildUser {
                 id = "43"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx44"
-              node = node {
+              node = buildUser {
                 id = "44"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx45"
-              node = node {
+              node = buildUser {
                 id = "45"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx46"
-              node = node {
+              node = buildUser {
                 id = "46"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx47"
-              node = node {
+              node = buildUser {
                 id = "47"
               }
             },
@@ -275,17 +277,17 @@ class TypePolicyConnectionFieldsTest {
     // Non-contiguous page (should reset)
     val query5 = WithTypePolicyDirectiveQuery(first = Optional.Present(2), after = Optional.Present("xx50"))
     val data5 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = listOf(
-            edge {
+            buildUserEdge {
               cursor = "xx50"
-              node = node {
+              node = buildUser {
                 id = "50"
               }
             },
-            edge {
+            buildUserEdge {
               cursor = "xx51"
-              node = node {
+              node = buildUser {
                 id = "51"
               }
             },
@@ -300,7 +302,7 @@ class TypePolicyConnectionFieldsTest {
     // Empty page (should keep previous result)
     val query6 = WithTypePolicyDirectiveQuery(first = Optional.Present(2), after = Optional.Present("xx51"))
     val data6 = WithTypePolicyDirectiveQuery.Data {
-      usersCursorBased2 = usersCursorBased2 {
+      usersCursorBased2 = buildUserConnection2 {
         edges = emptyList()
       }
     }