From b598a9657dfdfba45d955a0c69b15c58283596c5 Mon Sep 17 00:00:00 2001 From: BoD Date: Mon, 22 Jul 2024 17:57:32 +0200 Subject: [PATCH 1/2] Fix tests included build --- .github/workflows/build-pull-request.yaml | 3 ++- gradle/libs.versions.toml | 5 +---- tests/build.gradle.kts | 8 +++++--- .../src/commonMain/graphql/operations.graphql | 8 +++++++- .../src/commonMain/graphql/schema.graphqls | 7 ++++++- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-pull-request.yaml b/.github/workflows/build-pull-request.yaml index 53ac625e..351addba 100644 --- a/.github/workflows/build-pull-request.yaml +++ b/.github/workflows/build-pull-request.yaml @@ -9,4 +9,5 @@ jobs: steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 - run: | - ./gradlew build + ./gradlew build + ./gradlew -p tests build diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index aeb14c70..ab706f35 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,15 +11,12 @@ androidx-sqlite = "2.3.1" [libraries] librarian = "com.gradleup.librarian:core:0.0.3" kgp = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-plugin" } -android-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "android-plugin" } apollo-api = { group = "com.apollographql.apollo", name = "apollo-api", version.ref = "apollo" } -apollo-gradle-plugin = { group = "com.apollographql.apollo", name = "apollo-gradle-plugin", version.ref = "apollo" } apollo-mpp-utils = { group = "com.apollographql.apollo", name = "apollo-mpp-utils", version.ref = "apollo" } apollo-testing-support = { group = "com.apollographql.apollo", name = "apollo-testing-support", version.ref = "apollo" } apollo-runtime = { group = "com.apollographql.apollo", name = "apollo-runtime", version.ref = "apollo" } apollo-mockserver = "com.apollographql.mockserver:apollo-mockserver:0.0.1" atomicfu-library = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicfu" } -atomicfu-plugin = { group = "org.jetbrains.kotlinx", name = "atomicfu-gradle-plugin", version.ref = "atomicfu" } coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1" kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test" } # the Kotlin plugin resolves the version kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit" } # the Kotlin plugin resolves the version @@ -29,7 +26,6 @@ uuid = "com.benasher44:uuid:0.8.2" sqldelight-android = { group = "app.cash.sqldelight", name = "android-driver", version.ref = "sqldelight" } sqldelight-jvm = { group = "app.cash.sqldelight", name = "sqlite-driver", version.ref = "sqldelight" } sqldelight-native = { group = "app.cash.sqldelight", name = "native-driver", version.ref = "sqldelight" } -sqldelight-plugin = { group = "app.cash.sqldelight", name = "gradle-plugin", version.ref = "sqldelight" } sqldelight-runtime = { group = "app.cash.sqldelight", name = "runtime", version.ref = "sqldelight" } sqldelight-sqlite = { group = "app.cash.sqldelight", name = "sqlite-dialect", version.ref = "sqldelight" } sqlite-jdbc = "org.xerial:sqlite-jdbc:3.43.2.0" @@ -45,3 +41,4 @@ android = { id = "com.android.library", version.ref = "android-plugin" } librarian = { id = "com.gradleup.librarian", version = "0.0.4" } atomicfu = { id = "org.jetbrains.kotlin.plugin.atomicfu", version.ref = "kotlin-plugin" } sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" } +apollo = { id = "com.apollographql.apollo", version.ref = "apollo" } diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index d2ddc452..c30fd794 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -3,7 +3,9 @@ buildscript { mavenCentral() google() } - dependencies { - classpath("build-logic:build-logic") - } +} + +plugins { + alias(libs.plugins.kotlin).apply(false) + alias(libs.plugins.apollo).apply(false) } diff --git a/tests/normalized-cache/src/commonMain/graphql/operations.graphql b/tests/normalized-cache/src/commonMain/graphql/operations.graphql index 79ac2378..5f2ca126 100644 --- a/tests/normalized-cache/src/commonMain/graphql/operations.graphql +++ b/tests/normalized-cache/src/commonMain/graphql/operations.graphql @@ -3,4 +3,10 @@ query GetUser { name email } -} \ No newline at end of file +} + +query RepositoryListQuery($first: Int = 15, $after: String) { + repositories(first: $first, after: $after) { + id + } +} diff --git a/tests/normalized-cache/src/commonMain/graphql/schema.graphqls b/tests/normalized-cache/src/commonMain/graphql/schema.graphqls index 3ada9e89..ab22e033 100644 --- a/tests/normalized-cache/src/commonMain/graphql/schema.graphqls +++ b/tests/normalized-cache/src/commonMain/graphql/schema.graphqls @@ -1,9 +1,14 @@ type Query { user: User + repositories(first: Int, after: String): [Repository] } type User { name: String! email: String! admin: Boolean -} \ No newline at end of file +} + +type Repository { + id: ID! +} From bd4bea83e5a695c6c0b1cdbd99a9fdfa539ec4f4 Mon Sep 17 00:00:00 2001 From: BoD Date: Mon, 22 Jul 2024 18:52:41 +0200 Subject: [PATCH 2/2] Fix normalization of variable default values --- .../api/OperationCacheExtensions.kt | 8 ++--- .../src/commonMain/graphql/schema.graphqls | 2 +- .../commonTest/kotlin/NormalizationTest.kt | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/OperationCacheExtensions.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/OperationCacheExtensions.kt index 9c24f110..f9124fdb 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/OperationCacheExtensions.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/OperationCacheExtensions.kt @@ -1,13 +1,9 @@ package com.apollographql.cache.normalized.api import com.apollographql.apollo.annotations.ApolloInternal -import com.apollographql.apollo.api.Adapter -import com.apollographql.apollo.api.CustomScalarAdapters -import com.apollographql.apollo.api.Executable -import com.apollographql.apollo.api.Operation +import com.apollographql.apollo.api.* import com.apollographql.apollo.api.json.MapJsonReader import com.apollographql.apollo.api.json.MapJsonWriter -import com.apollographql.apollo.api.variables import com.apollographql.cache.normalized.api.internal.CacheBatchReader import com.apollographql.cache.normalized.api.internal.Normalizer import kotlin.jvm.JvmOverloads @@ -33,7 +29,7 @@ fun Executable.normalize( ): Map { val writer = MapJsonWriter() adapter().toJson(writer, customScalarAdapters, data) - val variables = variables(customScalarAdapters) + val variables = variables(customScalarAdapters, withDefaultValues = true) @Suppress("UNCHECKED_CAST") return Normalizer(variables, rootKey, cacheKeyGenerator, metadataGenerator, fieldKeyGenerator, embeddedFieldsProvider) .normalize(writer.root() as Map, rootField().selections, rootField().type.rawType()) diff --git a/tests/normalized-cache/src/commonMain/graphql/schema.graphqls b/tests/normalized-cache/src/commonMain/graphql/schema.graphqls index ab22e033..c902e2c2 100644 --- a/tests/normalized-cache/src/commonMain/graphql/schema.graphqls +++ b/tests/normalized-cache/src/commonMain/graphql/schema.graphqls @@ -1,6 +1,6 @@ type Query { user: User - repositories(first: Int, after: String): [Repository] + repositories(first: Int, after: String): [Repository!]! } type User { diff --git a/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt b/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt new file mode 100644 index 00000000..c920a739 --- /dev/null +++ b/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt @@ -0,0 +1,36 @@ +package test + +import com.apollographql.apollo.ApolloClient +import com.apollographql.apollo.testing.QueueTestNetworkTransport +import com.apollographql.apollo.testing.enqueueTestResponse +import com.apollographql.apollo.testing.internal.runTest +import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.MemoryCacheFactory +import com.apollographql.cache.normalized.fetchPolicy +import com.apollographql.cache.normalized.normalizedCache +import sqlite.RepositoryListQuery +import kotlin.test.Test +import kotlin.test.assertEquals + +class NormalizationTest { + @Test + fun variableDefaultValuesTest() = runTest { + val apolloClient = ApolloClient.Builder() + .networkTransport(QueueTestNetworkTransport()) + .normalizedCache(MemoryCacheFactory()) + .build() + val query = RepositoryListQuery() + apolloClient.enqueueTestResponse( + query, + RepositoryListQuery.Data( + listOf(RepositoryListQuery.Repository("42")) + ) + ) + apolloClient.query(query).execute() + val response = apolloClient + .query(query) + .fetchPolicy(FetchPolicy.CacheOnly) + .execute() + assertEquals("42", response.data!!.repositories.first().id) + } +}