-
Notifications
You must be signed in to change notification settings - Fork 640
feat: dataconnect: DataConnectOperationException added to support partial errors #6794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9b4331a
DataConnectOperationException added
dconeybe 77ce8df
DataConnectGrpcClient.kt: re-write OperationResult.deserialize() to u…
dconeybe f51a55a
DataConnectGrpcClientUnitTest.kt: add unit tests for OperationResult.…
dconeybe 14d0c5b
OperationExecutionErrorsIntegrationTest.kt added
dconeybe b81e610
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe b09555b
CHANGELOG.md: entry added
dconeybe 25fd751
CHANGELOG.md: update PR number in changelog entry
dconeybe 3165b90
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe 9c02c16
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe 2adcf59
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe d036552
DataConnectPathSegment.kt created, which is DataConnectOperationFailu…
dconeybe d23cdcf
fix test compilation errors
dconeybe 5d9fb2f
emulator.sh: add line: export FIREBASE_DATACONNECT_POSTGRESQL_STRING=…
dconeybe 06f187c
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe da229ee
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe 17384f8
firebase-dataconnect.gradle.kts: remove line: compileOnly(libs.kotlin…
dconeybe 3b00fb4
Remove JsonObject stuff
dconeybe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 262 additions & 0 deletions
262
...oidTest/kotlin/com/google/firebase/dataconnect/OperationExecutionErrorsIntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.dataconnect | ||
|
||
import com.google.firebase.dataconnect.testutil.DataConnectIntegrationTestBase | ||
import com.google.firebase.dataconnect.testutil.schemas.PersonSchema | ||
import com.google.firebase.dataconnect.testutil.schemas.PersonSchema.CreatePersonMutation | ||
import com.google.firebase.dataconnect.testutil.schemas.PersonSchema.GetPersonQuery | ||
import com.google.firebase.dataconnect.testutil.shouldSatisfy | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.matchers.collections.shouldHaveAtLeastSize | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.map | ||
import io.kotest.property.arbitrary.next | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationException | ||
import kotlinx.serialization.serializer | ||
import org.junit.Test | ||
|
||
class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase() { | ||
|
||
private val personSchema: PersonSchema by lazy { PersonSchema(dataConnectFactory) } | ||
private val dataConnect: FirebaseDataConnect by lazy { personSchema.dataConnect } | ||
|
||
@Test | ||
fun executeQueryFailsWithNullDataNonEmptyErrors() = runTest { | ||
val queryRef = | ||
dataConnect.query( | ||
operationName = GetPersonQuery.operationName, | ||
variables = Arb.incompatibleVariables().next(rs), | ||
dataDeserializer = serializer<GetPersonQuery.Data>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { queryRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedMessageSubstringCaseSensitive = "jwdbzka4k5", | ||
expectedCause = null, | ||
expectedRawData = null, | ||
expectedData = null, | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun executeMutationFailsWithNullDataNonEmptyErrors() = runTest { | ||
val mutationRef = | ||
dataConnect.mutation( | ||
operationName = CreatePersonMutation.operationName, | ||
variables = Arb.incompatibleVariables().next(rs), | ||
dataDeserializer = serializer<CreatePersonMutation.Data>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { mutationRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedCause = null, | ||
expectedRawData = null, | ||
expectedData = null, | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun executeQueryFailsWithNonNullDataEmptyErrorsButDecodingResponseDataFails() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val queryRef = | ||
dataConnect.query( | ||
operationName = GetPersonQuery.operationName, | ||
variables = GetPersonQuery.Variables(id), | ||
dataDeserializer = serializer<IncompatibleData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { queryRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "decoding data from the server's response failed", | ||
expectedCause = SerializationException::class, | ||
expectedRawData = mapOf("person" to null), | ||
expectedData = null, | ||
expectedErrors = emptyList(), | ||
) | ||
} | ||
|
||
@Test | ||
fun executeMutationFailsWithNonNullDataEmptyErrorsButDecodingResponseDataFails() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val name = Arb.alphanumericString().next() | ||
val mutationRef = | ||
dataConnect.mutation( | ||
operationName = CreatePersonMutation.operationName, | ||
variables = CreatePersonMutation.Variables(id, name), | ||
dataDeserializer = serializer<IncompatibleData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { mutationRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "decoding data from the server's response failed", | ||
expectedCause = SerializationException::class, | ||
expectedRawData = mapOf("person_insert" to mapOf("id" to id)), | ||
expectedData = null, | ||
expectedErrors = emptyList(), | ||
) | ||
} | ||
|
||
@Test | ||
fun executeQueryFailsWithNonNullDataNonEmptyErrorsDecodingSucceeds() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val name = Arb.alphanumericString().next() | ||
personSchema.createPerson(CreatePersonMutation.Variables(id, name)).execute() | ||
val queryRef = | ||
dataConnect.query( | ||
operationName = "getPersonWithPartialFailure", | ||
variables = GetPersonWithPartialFailureVariables(id), | ||
dataDeserializer = serializer<GetPersonWithPartialFailureData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { queryRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedMessageSubstringCaseSensitive = "c8azjdwz2x", | ||
expectedCause = null, | ||
expectedRawData = mapOf("person1" to mapOf("name" to name), "person2" to null), | ||
expectedData = GetPersonWithPartialFailureData(name), | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingSucceeds() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val name = Arb.alphanumericString().next() | ||
val mutationRef = | ||
dataConnect.mutation( | ||
operationName = "createPersonWithPartialFailure", | ||
variables = CreatePersonWithPartialFailureVariables(id = id, name = name), | ||
dataDeserializer = serializer<CreatePersonWithPartialFailureData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { mutationRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedMessageSubstringCaseSensitive = "ecxpjy4qfy", | ||
expectedCause = null, | ||
expectedRawData = mapOf("person1" to mapOf("id" to id), "person2" to null), | ||
expectedData = CreatePersonWithPartialFailureData(id), | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun executeQueryFailsWithNonNullDataNonEmptyErrorsDecodingFails() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val name = Arb.alphanumericString().next() | ||
personSchema.createPerson(CreatePersonMutation.Variables(id, name)).execute() | ||
val queryRef = | ||
dataConnect.query( | ||
operationName = "getPersonWithPartialFailure", | ||
variables = GetPersonWithPartialFailureVariables(id), | ||
dataDeserializer = serializer<IncompatibleData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { queryRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedMessageSubstringCaseSensitive = "c8azjdwz2x", | ||
expectedCause = null, | ||
expectedRawData = mapOf("person1" to mapOf("name" to name), "person2" to null), | ||
expectedData = null, | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Test | ||
fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingFails() = runTest { | ||
val id = Arb.alphanumericString().next() | ||
val name = Arb.alphanumericString().next() | ||
val mutationRef = | ||
dataConnect.mutation( | ||
operationName = "createPersonWithPartialFailure", | ||
variables = CreatePersonWithPartialFailureVariables(id = id, name = name), | ||
dataDeserializer = serializer<IncompatibleData>(), | ||
variablesSerializer = serializer(), | ||
optionsBuilder = {}, | ||
) | ||
|
||
val exception = shouldThrow<DataConnectOperationException> { mutationRef.execute() } | ||
|
||
exception.shouldSatisfy( | ||
expectedMessageSubstringCaseInsensitive = "operation encountered errors", | ||
expectedMessageSubstringCaseSensitive = "ecxpjy4qfy", | ||
expectedCause = null, | ||
expectedRawData = mapOf("person1" to mapOf("id" to id), "person2" to null), | ||
expectedData = null, | ||
errorsValidator = { it.shouldHaveAtLeastSize(1) }, | ||
) | ||
} | ||
|
||
@Serializable private data class IncompatibleVariables(val jwdbzka4k5: String) | ||
|
||
@Serializable private data class IncompatibleData(val btzjhbfz7h: String) | ||
|
||
private fun Arb.Companion.incompatibleVariables(string: Arb<String> = Arb.alphanumericString()) = | ||
string.map { IncompatibleVariables(it) } | ||
|
||
@Serializable private data class GetPersonWithPartialFailureVariables(val id: String) | ||
|
||
@Serializable | ||
private data class GetPersonWithPartialFailureData(val person1: Person, val person2: Nothing?) { | ||
constructor(person1Name: String) : this(Person(person1Name), null) | ||
|
||
@Serializable private data class Person(val name: String) | ||
} | ||
|
||
@Serializable | ||
private data class CreatePersonWithPartialFailureVariables(val id: String, val name: String) | ||
|
||
@Serializable | ||
private data class CreatePersonWithPartialFailureData( | ||
val person1: Person, | ||
val person2: Nothing? | ||
) { | ||
constructor(person1Id: String) : this(Person(person1Id), null) | ||
|
||
@Serializable private data class Person(val id: String) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.