Skip to content

Commit b1fbf5a

Browse files
authored
test(datastore): Subscription selectionset for primarykeys only (#3063)
1 parent 2ad710f commit b1fbf5a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage:
2-
branch: main
2+
branch: v1
33
status:
44
project:
55
default:

AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLSubscriptionTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,45 @@ class GraphQLSubscriptionTests: XCTestCase {
161161
XCTAssertNil(document.variables)
162162
}
163163

164+
/// - Given: a `Model` type Comment
165+
/// - When:
166+
/// - the model has nested association
167+
/// - the subscription is of type `.onCreate`
168+
/// - Then:
169+
/// - check if the generated GraphQL document is a valid subscription
170+
/// - the nested field contain only required fields
171+
func testOnCreateGraphQLSubscriptionWithPrimaryKeyOnly() {
172+
173+
var documentBuilder = ModelBasedGraphQLDocumentBuilder(modelSchema: Comment.schema,
174+
operationType: .subscription,
175+
primaryKeysOnly: true)
176+
documentBuilder.add(decorator: DirectiveNameDecorator(type: .onCreate))
177+
documentBuilder.add(decorator: ConflictResolutionDecorator(graphQLType: .subscription,
178+
primaryKeysOnly: true))
179+
let document = documentBuilder.build()
180+
let expectedQueryDocument = """
181+
subscription OnCreateComment {
182+
onCreateComment {
183+
id
184+
content
185+
createdAt
186+
post {
187+
id
188+
__typename
189+
_deleted
190+
}
191+
__typename
192+
_version
193+
_deleted
194+
_lastChangedAt
195+
}
196+
}
197+
"""
198+
XCTAssertEqual(document.name, "onCreateComment")
199+
XCTAssertEqual(document.stringValue, expectedQueryDocument)
200+
XCTAssertNil(document.variables)
201+
}
202+
164203
/// - Given: a `Model` type
165204
/// - When:
166205
/// - the model has no eager loaded associations

0 commit comments

Comments
 (0)