-
Notifications
You must be signed in to change notification settings - Fork 222
test(datastore): Lazy loading integration tests #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d621f0f
to
69b5b0b
Compare
79c51a2
to
252a5d4
Compare
if let id = modelValue as? String, | ||
(field.name == ModelIdentifierFormat.Custom.sqlColumnName || // this is the `@@primaryKey` (CPK) | ||
(schema.primaryKey.fields.count == 1 // or there's only one primary key (not composite key) | ||
&& schema.primaryKey.indexOfField(named: field.name) != nil)) { // and this field is the primary key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug where lazy List was not being created due to field.primaryKey
of the generated code was not returning true for Post4V2. this change can be applied directly on main
and cherry picked over to v1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if case .collection = modelField.type { // skip all "has-many" | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug where collections's are being set to nil
in the GraphQL input, so for example, when creating a Post and saving it through DataStore. the sync process will translate the post to the GraphQL input variables containing
{
"id": "postid123",
"comments": null
}
The problem is this fails as there's no input type "comments". We should skip has-many relationships like in this code snippet. This can be done in main
and v1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3109798
to
b26516a
Compare
…n update, removal association on update) - allow updates from a model with not loaded lazy model. the identifier gets extracted out from the not loaded state and persisted in SQL. eager load on save continues to get the loaded model back for the sync to AppSync - ModelDecorator on update mutations will add `nil` for the targetName fields because updates may remove associations from models. - allow lazy model to be decoded as a notLoaded state with empty identifier. this is when there is no data to load in the associated data, and simply is not set yet. for example creating a comment and saving it, without a post attached. this is for optional associations - update some of the codegenerated types to allow setting a `nil` value to represent the removal use case. - start adding some many-to-many tests
Issue #, if available:
Table of Contents:
Description of changes:
This PR consists of the integration tests against a live backend using the expected codegenerated models for a variety of schemas being tested.
DataStore.save API will persist the data using the SQL adapter, then query for the data. The queried data as part of the save API call will continue to be eager loaded as the model is needed for syncing to the cloud. If the data is lazy loaded, then there's a problem model only containing the SQL identifier information
@@primaryKey
column value. We might be able to allow lazy loading on the save data flow with some more changes to the implementation.DataStore.query API will allow lazy loading of SQL data
Check points: (check or cross out if not relevant)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.