|
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.firebase.dataconnect |
| 18 | + |
| 19 | +// Googlers see go/dataconnect:sdk:partial-errors for design details. |
| 20 | + |
| 21 | +/** The data and errors provided by the backend in the response message. */ |
| 22 | +public interface DataConnectOperationFailureResponse<Data> { |
| 23 | + |
| 24 | + /** |
| 25 | + * The raw, un-decoded data provided by the backend in the response message. Will be `null` if, |
| 26 | + * and only if, the backend explicitly sent null for the data or if the data was not present in |
| 27 | + * the response. |
| 28 | + * |
| 29 | + * Otherwise, the values in the map will be one of the following: |
| 30 | + * * `null` |
| 31 | + * * [String] |
| 32 | + * * [Boolean] |
| 33 | + * * [Double] |
| 34 | + * * [List] containing any of the types in this list of types |
| 35 | + * * [Map] with [String] keys and values of of the types in this list of types |
| 36 | + * |
| 37 | + * Consider using [toJson] to get a higher-level object. |
| 38 | + */ |
| 39 | + public val rawData: Map<String, Any?>? |
| 40 | + |
| 41 | + /** |
| 42 | + * The list of errors provided by the backend in the response message; may be empty. |
| 43 | + * |
| 44 | + * See https://spec.graphql.org/draft/#sec-Errors for details. |
| 45 | + */ |
| 46 | + public val errors: List<ErrorInfo> |
| 47 | + |
| 48 | + /** |
| 49 | + * The successfully-decoded [rawData], if any. |
| 50 | + * |
| 51 | + * Will be `null` if [rawData] is `null`, or if decoding the [rawData] failed. |
| 52 | + */ |
| 53 | + public val data: Data? |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns a string representation of this object, useful for debugging. |
| 57 | + * |
| 58 | + * The string representation is _not_ guaranteed to be stable and may change without notice at any |
| 59 | + * time. Therefore, the only recommended usage of the returned string is debugging and/or logging. |
| 60 | + * Namely, parsing the returned string or storing the returned string in non-volatile storage |
| 61 | + * should generally be avoided in order to be robust in case that the string representation |
| 62 | + * changes. |
| 63 | + * |
| 64 | + * @return a string representation of this object, which includes the class name and the values of |
| 65 | + * all public properties. |
| 66 | + */ |
| 67 | + override fun toString(): String |
| 68 | + |
| 69 | + /** |
| 70 | + * Information about the error, as provided in the response payload from the backend. |
| 71 | + * |
| 72 | + * See https://spec.graphql.org/draft/#sec-Errors for details. |
| 73 | + */ |
| 74 | + public interface ErrorInfo { |
| 75 | + /** The error's message. */ |
| 76 | + public val message: String |
| 77 | + |
| 78 | + /** The path of the field in the response data to which this error relates. */ |
| 79 | + public val path: List<PathSegment> |
| 80 | + |
| 81 | + /** |
| 82 | + * Compares this object with another object for equality. |
| 83 | + * |
| 84 | + * @param other The object to compare to this for equality. |
| 85 | + * @return true if, and only if, the other object is an instance of the same implementation of |
| 86 | + * [ErrorInfo] whose public properties compare equal using the `==` operator to the |
| 87 | + * corresponding properties of this object. |
| 88 | + */ |
| 89 | + override fun equals(other: Any?): Boolean |
| 90 | + |
| 91 | + /** |
| 92 | + * Calculates and returns the hash code for this object. |
| 93 | + * |
| 94 | + * The hash code is _not_ guaranteed to be stable across application restarts. |
| 95 | + * |
| 96 | + * @return the hash code for this object, that incorporates the values of this object's public |
| 97 | + * properties. |
| 98 | + */ |
| 99 | + override fun hashCode(): Int |
| 100 | + |
| 101 | + /** |
| 102 | + * Returns a string representation of this object, useful for debugging. |
| 103 | + * |
| 104 | + * The string representation is _not_ guaranteed to be stable and may change without notice at |
| 105 | + * any time. Therefore, the only recommended usage of the returned string is debugging and/or |
| 106 | + * logging. Namely, parsing the returned string or storing the returned string in non-volatile |
| 107 | + * storage should generally be avoided in order to be robust in case that the string |
| 108 | + * representation changes. |
| 109 | + * |
| 110 | + * @return a string representation of this object, suitable for logging the error indicated by |
| 111 | + * this object; it will include the path formatted into a human-readable string (if the path is |
| 112 | + * not empty), and the message. |
| 113 | + */ |
| 114 | + override fun toString(): String |
| 115 | + |
| 116 | + /** The "segment" of a path to a field in the response data. */ |
| 117 | + public sealed interface PathSegment { |
| 118 | + |
| 119 | + /** A named field in a path to a field in the response data. */ |
| 120 | + @JvmInline |
| 121 | + public value class Field(public val field: String) : PathSegment { |
| 122 | + |
| 123 | + /** |
| 124 | + * Returns a string representation of this object, useful for debugging. |
| 125 | + * |
| 126 | + * The string representation is _not_ guaranteed to be stable and may change without notice |
| 127 | + * at any time. Therefore, the only recommended usage of the returned string is debugging |
| 128 | + * and/or logging. Namely, parsing the returned string or storing the returned string in |
| 129 | + * non-volatile storage should generally be avoided in order to be robust in case that the |
| 130 | + * string representation changes. |
| 131 | + * |
| 132 | + * @return returns simply [field]. |
| 133 | + */ |
| 134 | + override fun toString(): String = field |
| 135 | + } |
| 136 | + |
| 137 | + /** An index of a list in a path to a field in the response data. */ |
| 138 | + @JvmInline |
| 139 | + public value class ListIndex(public val index: Int) : PathSegment { |
| 140 | + /** |
| 141 | + * Returns a string representation of this object, useful for debugging. |
| 142 | + * |
| 143 | + * The string representation is _not_ guaranteed to be stable and may change without notice |
| 144 | + * at any time. Therefore, the only recommended usage of the returned string is debugging |
| 145 | + * and/or logging. Namely, parsing the returned string or storing the returned string in |
| 146 | + * non-volatile storage should generally be avoided in order to be robust in case that the |
| 147 | + * string representation changes. |
| 148 | + * |
| 149 | + * @return returns simply the string representation of [index]. |
| 150 | + */ |
| 151 | + override fun toString(): String = index.toString() |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | +} |
0 commit comments