Skip to content

Commit

Permalink
update rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 13, 2024
1 parent 8e41241 commit 62cb4f5
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ public class AppSyncListProvider<Element: Model>: ModelListProvider {
graphQLData: graphQLData,
apiName: apiName,
authMode: authMode
)
else {
) else {
throw CoreError.listOperation("""
The AppSync response return successfully, but could not decode to
AWSAppSyncListResponse from: \(graphQLData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public enum AppSyncModelMetadataUtils {
static func shouldAddMetadata(toModel graphQLData: JSONValue) -> Bool {
guard case let .object(modelJSON) = graphQLData,
case let .string(modelName) = modelJSON["__typename"],
ModelRegistry.modelSchema(from: modelName) != nil
else {
ModelRegistry.modelSchema(from: modelName) != nil else {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class IAMAuthInterceptor {
signingName: "appsync",
signingRegion: region,
date: Date()
)
else {
) else {
Amplify.Logging.error("Unable to sign request")
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class GraphQLScalarTests: GraphQLTestBase {
XCTAssertEqual(updatedModel, updatedContainer)

guard let queriedModel =
try await queryModel(request: .get(ScalarContainer.self, byId: container.id))
else {
try await queryModel(request: .get(ScalarContainer.self, byId: container.id)) else {
XCTFail("Failed to query model")
return
}
Expand Down Expand Up @@ -146,8 +145,7 @@ class GraphQLScalarTests: GraphQLTestBase {
guard let queriedModel = try await queryModel(request: .get(
ListStringContainer.self,
byId: container.id
))
else {
)) else {
XCTFail("Failed to query model")
return
}
Expand Down Expand Up @@ -188,8 +186,7 @@ class GraphQLScalarTests: GraphQLTestBase {
guard let queriedModel = try await queryModel(request: .get(
ListStringContainer.self,
byId: container.id
))
else {
)) else {
XCTFail("Failed to query model")
return
}
Expand Down Expand Up @@ -268,8 +265,7 @@ class GraphQLScalarTests: GraphQLTestBase {
guard let queriedModel = try await queryModel(request: .get(
NestedTypeTestModel.self,
byId: container.id
))
else {
)) else {
XCTFail("Failed to query model")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class GraphQLSyncCustomPrimaryKeyTests: XCTestCase {
/// Create order
let customerOrder = CustomerOrder(orderId: UUID().uuidString, email: "[email protected]")
guard let createMutationSyncResult = createCustomerOrder(customerOrder: customerOrder),
let createdCustomerOrder = createMutationSyncResult.model.instance as? CustomerOrder
else {
let createdCustomerOrder = createMutationSyncResult.model.instance as? CustomerOrder else {
XCTFail("Failed to create customer order")
return
}
Expand All @@ -61,8 +60,7 @@ class GraphQLSyncCustomPrimaryKeyTests: XCTestCase {
byId: createdCustomerOrder.id,
orderId: createdCustomerOrder.orderId
),
var queriedCustomerOrder = queryMutationSyncResult.model.instance as? CustomerOrder
else {
var queriedCustomerOrder = queryMutationSyncResult.model.instance as? CustomerOrder else {
XCTFail("Failed to query customer order")
return
}
Expand All @@ -76,8 +74,7 @@ class GraphQLSyncCustomPrimaryKeyTests: XCTestCase {
modelSchema: queriedCustomerOrder.schema,
version: queryMutationSyncResult.syncMetadata.version
),
let updatedCustomerOrder = updateMutationSyncResult.model.instance as? CustomerOrder
else {
let updatedCustomerOrder = updateMutationSyncResult.model.instance as? CustomerOrder else {
XCTFail("Failed to update customer order")
return
}
Expand All @@ -90,8 +87,7 @@ class GraphQLSyncCustomPrimaryKeyTests: XCTestCase {
modelSchema: updatedCustomerOrder.schema,
version: updateMutationSyncResult.syncMetadata.version
),
let deletedCustomerOrder = deleteMutationSyncResult.model.instance as? CustomerOrder
else {
let deletedCustomerOrder = deleteMutationSyncResult.model.instance as? CustomerOrder else {
XCTFail("Failed to update customer order")
return
}
Expand All @@ -104,8 +100,7 @@ class GraphQLSyncCustomPrimaryKeyTests: XCTestCase {
byId: deletedCustomerOrder.id,
orderId: deletedCustomerOrder.orderId
),
let queryDeletedCustomerOrder = queryAfterDeleteMutationSyncResult.model.instance as? CustomerOrder
else {
let queryDeletedCustomerOrder = queryAfterDeleteMutationSyncResult.model.instance as? CustomerOrder else {
XCTFail("Failed to query customer order")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ final class GraphQLPostPerson41Tests: AWSAPIPluginGen2GraphQLBaseTest {
request: .get(
Post.self,
byIdentifier: post.identifier
)).get()
else {
)).get() else {
print("Missing post")
// Code Snippet Ends
XCTFail("Missing post")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ final class GraphQLCartCustomer4Tests: AWSAPIPluginGen2GraphQLBaseTest {
request: .get(
Cart.self,
byIdentifier: existingCart.identifier
)).get()
else {
)).get() else {
print("Missing cart")
// Code Snippet Ends
XCTFail("Missing cart")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ final class GraphQLLazyLoadUserPostCommentTests: GraphQLLazyLoadBaseTest {
user.comments,
user.posts
] }
))
else {
)) else {
XCTFail("Could not perform nested query for User")
return
}
Expand All @@ -154,8 +153,7 @@ final class GraphQLLazyLoadUserPostCommentTests: GraphQLLazyLoadBaseTest {
Post.self,
byIdentifier: post.id,
includes: { post in [post.author, post.comments] }
))
else {
)) else {
XCTFail("Could not perform nested query for Post")
return
}
Expand All @@ -173,8 +171,7 @@ final class GraphQLLazyLoadUserPostCommentTests: GraphQLLazyLoadBaseTest {
Comment.self,
byIdentifier: comment.id,
includes: { comment in [comment.author, comment.post] }
))
else {
)) else {
XCTFail("Could not perform nested query for Comment")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ final class GraphQLLazyLoadPostTagTests: GraphQLLazyLoadBaseTest {
title: post.title
),
includes: { post in [post.tags] }
))
else {
)) else {
XCTFail("Could not perform nested query for Post")
return
}
Expand All @@ -144,8 +143,7 @@ final class GraphQLLazyLoadPostTagTests: GraphQLLazyLoadBaseTest {
name: tag.name
),
includes: { tag in [tag.posts] }
))
else {
)) else {
XCTFail("Could not perform nested query for Tag")
return
}
Expand All @@ -165,8 +163,7 @@ final class GraphQLLazyLoadPostTagTests: GraphQLLazyLoadBaseTest {
postTag.postWithTagsCompositeKey,
postTag.tagWithCompositeKey
] }
))
else {
)) else {
XCTFail("Could not perform nested query for PostTag")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ class GraphQLLazyLoadProjectTeam1Tests: GraphQLLazyLoadBaseTest {
name: team.name
),
includes: { team in [team.project]}
))
else {
)) else {
XCTFail("Could not perform nested query for Team")
return
}
Expand All @@ -154,8 +153,7 @@ class GraphQLLazyLoadProjectTeam1Tests: GraphQLLazyLoadBaseTest {
name: project.name
),
includes: { project in [project.team]}
))
else {
)) else {
XCTFail("Could not perform nested query for Project")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class GraphQLLazyLoadProjectTeam2Tests: GraphQLLazyLoadBaseTest {
name: project.name
),
includes: { project in [project.team]}
))
else {
)) else {
XCTFail("Could not perform nested query for Project")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class GraphQLLazyLoadProjectTeam5Tests: GraphQLLazyLoadBaseTest {
name: team.name
),
includes: { team in [team.project]}
))
else {
)) else {
XCTFail("Could not perform nested query for Team")
return
}
Expand All @@ -121,8 +120,7 @@ class GraphQLLazyLoadProjectTeam5Tests: GraphQLLazyLoadBaseTest {
name: project.name
),
includes: { project in [project.team]}
))
else {
)) else {
XCTFail("Could not perform nested query for Project")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class GraphQLLazyLoadProjectTeam6Tests: GraphQLLazyLoadBaseTest {
name: project.name
),
includes: { project in [project.team]}
))
else {
)) else {
XCTFail("Could not perform nested query for Project")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class AppSyncListPayloadTests: XCTestCase {
return
}
guard let postFilter = filter["postID"] as? [String: String],
let postId = postFilter["eq"]
else {
let postId = postFilter["eq"] else {
XCTFail("Could not retrieve filter values")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ class AppSyncListProviderTests: XCTestCase {
XCTAssertEqual(nextToken, "nextToken")
guard let filter = filterOptional,
let postFilter = filter["postID"] as? [String: String],
let postId = postFilter["eq"]
else {
let postId = postFilter["eq"] else {
XCTFail("Could not retrieve filter values")
return
}
Expand Down Expand Up @@ -207,8 +206,7 @@ class AppSyncListProviderTests: XCTestCase {
XCTFail("Should have failed")
} catch let coreError as CoreError {
guard case .listOperation(_, _, let underlyingError) = coreError,
(underlyingError as? APIError) != nil
else {
(underlyingError as? APIError) != nil else {
XCTFail("Unexpected error \(coreError)")
return
}
Expand Down Expand Up @@ -266,8 +264,7 @@ class AppSyncListProviderTests: XCTestCase {
XCTAssertEqual(nextToken, "nextToken")
guard let filter = filterOptional,
let postFilter = filter["postID"] as? [String: String],
let postId = postFilter["eq"]
else {
let postId = postFilter["eq"] else {
XCTFail("Could not retrieve filter values")
return
}
Expand Down Expand Up @@ -296,8 +293,7 @@ class AppSyncListProviderTests: XCTestCase {
XCTFail("Should have failed")
} catch let error as CoreError {
guard case .listOperation(_, _, let underlyingError) = error,
(underlyingError as? APIError) != nil
else {
(underlyingError as? APIError) != nil else {
XCTFail("Unexpected error \(error)")
return
}
Expand Down Expand Up @@ -334,8 +330,7 @@ class AppSyncListProviderTests: XCTestCase {
XCTFail("Should have failed")
} catch let error as CoreError {
guard case .listOperation(_, _, let underlyingError) = error,
(underlyingError as? GraphQLResponseError<JSONValue>) != nil
else {
(underlyingError as? GraphQLResponseError<JSONValue>) != nil else {
XCTFail("Unexpected error \(error)")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class ModelMetadataTests: XCTestCase {
case .array(let associatedFields) = associationData["appSyncAssociatedFields"],
case .array(let associatedIdentifiers) = associationData["appSyncAssociatedIdentifiers"],
case .string(let apiName) = associationData["apiName"],
case .string(let authMode) = associationData["authMode"]
else {
case .string(let authMode) = associationData["authMode"] else {
XCTFail("Missing association metadata for comments")
return
}
Expand All @@ -89,8 +88,7 @@ class ModelMetadataTests: XCTestCase {
case .array(let associatedFields) = associationData["appSyncAssociatedFields"],
case .array(let associatedIdentifiers) = associationData["appSyncAssociatedIdentifiers"],
case .string(let apiName) = associationData["apiName"],
case .string(let authMode) = associationData["authMode"]
else {
case .string(let authMode) = associationData["authMode"] else {
XCTFail("Missing association metadata for comments")
return
}
Expand All @@ -115,8 +113,7 @@ class ModelMetadataTests: XCTestCase {
let post = AppSyncModelMetadataUtils.addMetadata(toModel: json, apiName: "apiName", authMode: nil)
guard case .object(let postObject) = post,
case .string = postObject["id"],
case .string = postObject["title"]
else {
case .string = postObject["title"] else {
XCTFail("Should have exactly the number of fields in original json object")
return
}
Expand All @@ -134,8 +131,7 @@ class ModelMetadataTests: XCTestCase {
guard case .object(let postObject) = post,
case .string = postObject["id"],
case .string = postObject["title"],
case .string = postObject["__typename"]
else {
case .string = postObject["__typename"] else {
XCTFail("Should have exactly the number of fields in original json object")
return
}
Expand All @@ -151,8 +147,7 @@ class ModelMetadataTests: XCTestCase {
let post = AppSyncModelMetadataUtils.addMetadata(toModel: json, apiName: "apiName", authMode: nil)
guard case .object(let postObject) = post,
case .string = postObject["title"],
case .string = postObject["__typename"]
else {
case .string = postObject["__typename"] else {
XCTFail("Should have exactly the number of fields in original json object")
return
}
Expand All @@ -176,8 +171,7 @@ class ModelMetadataTests: XCTestCase {
guard case .object(let associationData) = post["comments"],
associationData["appSyncAssociatedField"] == nil,
associationData["appSyncAssociatedIdentifiers"] == nil,
associationData["apiName"] == nil
else {
associationData["apiName"] == nil else {
XCTFail("Nested levels of data should not have metadata added")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class GraphQLRequestToListQueryTests: XCTestCase {
let filterJSON = try? JSONSerialization.data(
withJSONObject: filter,
options: .prettyPrinted
)
else {
) else {
XCTFail("variables should contain a valid filter JSON")
return
}
Expand Down Expand Up @@ -169,8 +168,7 @@ class GraphQLRequestToListQueryTests: XCTestCase {
let filterJSON = try? JSONSerialization.data(
withJSONObject: filter,
options: .prettyPrinted
)
else {
) else {
XCTFail("variables should contain a valid filter JSON")
return
}
Expand Down

0 comments on commit 62cb4f5

Please sign in to comment.