// // Copyright Amazon.com Inc. or its affiliates. // All Rights Reserved. // // SPDX-License-Identifier: Apache-2.0 // import Foundation import Combine import XCTest @testable import Amplify import AWSPluginsCore extension AWSDataStoreLazyLoadPostCommentWithCompositeKeyTests { func testPostSelectionSets() { setUpModelRegistrationOnly(withModels: PostCommentWithCompositeKeyModels()) continueAfterFailure = true let post = Post(title: "title") // Create let createRequest = GraphQLRequest.createMutation(of: post, modelSchema: Post.schema) let createDocument = """ mutation CreatePostWithCompositeKey($input: CreatePostWithCompositeKeyInput!) { createPostWithCompositeKey(input: $input) { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(createRequest.document, createDocument) // Update let updateRequest = GraphQLRequest.updateMutation(of: post, modelSchema: Post.schema) let updateDocument = """ mutation UpdatePostWithCompositeKey($input: UpdatePostWithCompositeKeyInput!) { updatePostWithCompositeKey(input: $input) { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(updateRequest.document, updateDocument) // Delete let deleteRequest = GraphQLRequest.deleteMutation(of: post, modelSchema: Post.schema) let deleteDocument = """ mutation DeletePostWithCompositeKey($input: DeletePostWithCompositeKeyInput!) { deletePostWithCompositeKey(input: $input) { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(deleteRequest.document, deleteDocument) // onCreate let onCreateRequest = GraphQLRequest.subscription(to: Post.self, subscriptionType: .onCreate) let onCreateDocument = """ subscription OnCreatePostWithCompositeKey { onCreatePostWithCompositeKey { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onCreateRequest.document, onCreateDocument) // onUpdate let onUpdateRequest = GraphQLRequest.subscription(to: Post.self, subscriptionType: .onUpdate) let onUpdateDocument = """ subscription OnUpdatePostWithCompositeKey { onUpdatePostWithCompositeKey { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onUpdateRequest.document, onUpdateDocument) // onDelete let onDeleteRequest = GraphQLRequest.subscription(to: Post.self, subscriptionType: .onDelete) let onDeleteDocument = """ subscription OnDeletePostWithCompositeKey { onDeletePostWithCompositeKey { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onDeleteRequest.document, onDeleteDocument) // SyncQuery let syncRequest = GraphQLRequest.syncQuery(modelType: Post.self) let syncDocument = """ query SyncPostWithCompositeKeys($limit: Int) { syncPostWithCompositeKeys(limit: $limit) { items { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } nextToken startedAt } } """ XCTAssertEqual(syncRequest.document, syncDocument) } func testCommentSelectionSets() { setUpModelRegistrationOnly(withModels: PostCommentWithCompositeKeyModels()) continueAfterFailure = true let post = Post(title: "title") let comment = Comment(content: "content", post: post) // Create let createRequest = GraphQLRequest.createMutation(of: comment, modelSchema: Comment.schema) let createDocument = """ mutation CreateCommentWithCompositeKey($input: CreateCommentWithCompositeKeyInput!) { createCommentWithCompositeKey(input: $input) { id content createdAt updatedAt post { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(createRequest.document, createDocument) // Update let updateRequest = GraphQLRequest.updateMutation(of: comment, modelSchema: Comment.schema) let updateDocument = """ mutation UpdateCommentWithCompositeKey($input: UpdateCommentWithCompositeKeyInput!) { updateCommentWithCompositeKey(input: $input) { id content createdAt updatedAt post { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(updateRequest.document, updateDocument) // Delete let deleteRequest = GraphQLRequest.deleteMutation(of: comment, modelSchema: Comment.schema) let deleteDocument = """ mutation DeleteCommentWithCompositeKey($input: DeleteCommentWithCompositeKeyInput!) { deleteCommentWithCompositeKey(input: $input) { id content createdAt updatedAt post { id title createdAt updatedAt __typename _version _deleted _lastChangedAt } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(deleteRequest.document, deleteDocument) // onCreate let onCreateRequest = GraphQLRequest.subscription(to: Comment.schema, subscriptionType: .onCreate) let onCreateDocument = """ subscription OnCreateCommentWithCompositeKey { onCreateCommentWithCompositeKey { id content createdAt updatedAt post { id title __typename _deleted } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onCreateRequest.document, onCreateDocument) // onUpdate let onUpdateRequest = GraphQLRequest.subscription(to: Comment.self, subscriptionType: .onUpdate) let onUpdateDocument = """ subscription OnUpdateCommentWithCompositeKey { onUpdateCommentWithCompositeKey { id content createdAt updatedAt post { id title __typename _deleted } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onUpdateRequest.document, onUpdateDocument) // onDelete let onDeleteRequest = GraphQLRequest.subscription(to: Comment.self, subscriptionType: .onDelete) let onDeleteDocument = """ subscription OnDeleteCommentWithCompositeKey { onDeleteCommentWithCompositeKey { id content createdAt updatedAt post { id title __typename _deleted } __typename _version _deleted _lastChangedAt } } """ XCTAssertEqual(onDeleteRequest.document, onDeleteDocument) // SyncQuery let syncRequest = GraphQLRequest.syncQuery(modelType: Comment.self) let syncDocument = """ query SyncCommentWithCompositeKeys($limit: Int) { syncCommentWithCompositeKeys(limit: $limit) { items { id content createdAt updatedAt post { id title __typename _deleted } __typename _version _deleted _lastChangedAt } nextToken startedAt } } """ XCTAssertEqual(syncRequest.document, syncDocument) } }