aws-amplify / amplify-ios

@@ -167,12 +167,14 @@
Loading
167 167
    case field(name: String,
168 168
               type: ModelFieldType,
169 169
               nullability: ModelFieldNullability,
170 +
               isReadOnly: Bool,
170 171
               association: ModelAssociation?,
171 172
               attributes: [ModelFieldAttribute],
172 173
               authRules: AuthRules)
173 174
174 175
    public static func field(_ key: CodingKey,
175 176
                             is nullability: ModelFieldNullability = .required,
177 +
                             isReadOnly: Bool = false,
176 178
                             ofType type: ModelFieldType = .string,
177 179
                             attributes: [ModelFieldAttribute] = [],
178 180
                             association: ModelAssociation? = nil,
@@ -180,6 +182,7 @@
Loading
180 182
        return .field(name: key.stringValue,
181 183
                      type: type,
182 184
                      nullability: nullability,
185 +
                      isReadOnly: isReadOnly,
183 186
                      association: association,
184 187
                      attributes: attributes,
185 188
                      authRules: authRules)
@@ -193,6 +196,7 @@
Loading
193 196
        return .field(name: name,
194 197
                      type: .string,
195 198
                      nullability: .required,
199 +
                      isReadOnly: false,
196 200
                      association: nil,
197 201
                      attributes: [.primaryKey],
198 202
                      authRules: [])
@@ -200,32 +204,38 @@
Loading
200 204
201 205
    public static func hasMany(_ key: CodingKey,
202 206
                               is nullability: ModelFieldNullability = .required,
207 +
                               isReadOnly: Bool = false,
203 208
                               ofType type: Model.Type,
204 209
                               associatedWith associatedKey: CodingKey) -> ModelFieldDefinition {
205 210
        return .field(key,
206 211
                      is: nullability,
212 +
                      isReadOnly: isReadOnly,
207 213
                      ofType: .collection(of: type),
208 214
                      association: .hasMany(associatedWith: associatedKey))
209 215
    }
210 216
211 217
    public static func hasOne(_ key: CodingKey,
212 218
                              is nullability: ModelFieldNullability = .required,
219 +
                              isReadOnly: Bool = false,
213 220
                              ofType type: Model.Type,
214 221
                              associatedWith associatedKey: CodingKey,
215 222
                              targetName: String? = nil) -> ModelFieldDefinition {
216 223
        return .field(key,
217 224
                      is: nullability,
225 +
                      isReadOnly: isReadOnly,
218 226
                      ofType: .model(type: type),
219 227
                      association: .hasOne(associatedWith: associatedKey, targetName: targetName))
220 228
    }
221 229
222 230
    public static func belongsTo(_ key: CodingKey,
223 231
                                 is nullability: ModelFieldNullability = .required,
232 +
                                 isReadOnly: Bool = false,
224 233
                                 ofType type: Model.Type,
225 234
                                 associatedWith associatedKey: CodingKey? = nil,
226 235
                                 targetName: String? = nil) -> ModelFieldDefinition {
227 236
        return .field(key,
228 237
                      is: nullability,
238 +
                      isReadOnly: isReadOnly,
229 239
                      ofType: .model(type: type),
230 240
                      association: .belongsTo(associatedWith: associatedKey, targetName: targetName))
231 241
    }
@@ -234,6 +244,7 @@
Loading
234 244
        guard case let .field(name,
235 245
                              type,
236 246
                              nullability,
247 +
                              isReadOnly,
237 248
                              association,
238 249
                              attributes,
239 250
                              authRules) = self else {
@@ -242,6 +253,7 @@
Loading
242 253
        return ModelField(name: name,
243 254
                          type: type,
244 255
                          isRequired: nullability.isRequired,
256 +
                          isReadOnly: isReadOnly,
245 257
                          isArray: type.isArray,
246 258
                          attributes: attributes,
247 259
                          association: association,

@@ -15,11 +15,16 @@
Loading
15 15
16 16
    /// Get the `Model` values as a `Dictionary` of `String` to `Any?` that can be
17 17
    /// used as the `input` of GraphQL related operations.
18 -
    func graphQLInput(_ modelSchema: ModelSchema) -> GraphQLInput {
18 +
    func graphQLInputForMutation(_ modelSchema: ModelSchema) -> GraphQLInput {
19 19
        var input: GraphQLInput = [:]
20 20
        modelSchema.fields.forEach {
21 21
            let modelField = $0.value
22 22
23 +
            // When the field is read-only don't add it to the GraphQL input object
24 +
            if modelField.isReadOnly {
25 +
                return
26 +
            }
27 +
23 28
            // TODO how to handle associations of type "many" (i.e. cascade save)?
24 29
            // This is not supported right now and might be added as a future feature
25 30
            if case .collection = modelField.type {

@@ -27,7 +27,7 @@
Loading
27 27
    public func decorate(_ document: SingleDirectiveGraphQLDocument,
28 28
                         modelSchema: ModelSchema) -> SingleDirectiveGraphQLDocument {
29 29
        var inputs = document.inputs
30 -
        var graphQLInput = model.graphQLInput(modelSchema)
30 +
        var graphQLInput = model.graphQLInputForMutation(modelSchema)
31 31
32 32
        if !modelSchema.authRules.isEmpty {
33 33
            modelSchema.authRules.forEach { authRule in

@@ -29,6 +29,7 @@
Loading
29 29
    public let name: String
30 30
    public let type: ModelFieldType
31 31
    public let isRequired: Bool
32 +
    public let isReadOnly: Bool
32 33
    public let isArray: Bool
33 34
    public let attributes: [ModelFieldAttribute]
34 35
    public let association: ModelAssociation?
@@ -41,6 +42,7 @@
Loading
41 42
    public init(name: String,
42 43
                type: ModelFieldType,
43 44
                isRequired: Bool = false,
45 +
                isReadOnly: Bool = false,
44 46
                isArray: Bool = false,
45 47
                attributes: [ModelFieldAttribute] = [],
46 48
                association: ModelAssociation? = nil,
@@ -48,6 +50,7 @@
Loading
48 50
        self.name = name
49 51
        self.type = type
50 52
        self.isRequired = isRequired
53 +
        self.isReadOnly = isReadOnly
51 54
        self.isArray = isArray
52 55
        self.attributes = attributes
53 56
        self.association = association
Files Coverage
Amplify 48.59%
AmplifyPlugins 62.78%
Project Totals (652 files) 59.31%
26119
API_plugin_unit_test
26117
Analytics_plugin_unit_test
26124
Predictions_plugin_unit_test
26125
DataStore_plugin_unit_test
26118
Predictions_plugin_unit_test
26121
Storage_plugin_unit_test
26123
Auth_plugin_unit_test
26120
AWSPluginsCore

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading