-
Couldn't load subscription status.
- Fork 224
feat(datastore): LazyModel Implementation #2174
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db36074 to
3ebefdd
Compare
3ebefdd to
81df154
Compare
81df154 to
c17464d
Compare
c17464d to
b28edbb
Compare
b28edbb to
2a25311
Compare
69074a7 to
9bbbf5a
Compare
f733791 to
d621f0f
Compare
This was referenced Oct 14, 2022
d621f0f to
69b5b0b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Table of Contents:
Description of changes:
This PR is the first of a series of PRs for lazy loading, and consists of the LazyModel implementation for DataStore and API.
Codegen
The first hand written swift model types is included here using the following bi-directional has-many belongs-to schema from the V2 Transformer tests:
DataStore LazyModel
When querying for a child model, like Comment, the FK value of Post is retrieve as part of the SQL query for Comment. This FK value of the Post is stored in the LazyModel.
API LazyModel
When querying for a child model, like Comment, the selection set created will be nested one level, with the nested level containing only the identifiers of the model, in this case just the identifiers of the Post.
Lazy Load will use the identifiers and construct a customized GraphQL request with the variables containing the map of identifiers.
Lazy Loading composite keys
Loading composite key for both the DataStore and API 's LazyModel ModelProvider has some challenges. For DataStore, the identifier stored will be "@@PrimaryKey" --> "[FK value]" which is in the format of "[identifier1]#[identifier2]". Later when this is loaded, the value gets used as a predicate into DataStore, specifically the predicate construction will look like this:
fields("@@primaryKey").eq("[identifier1]#[identifier2]")For API, the LazyModel is decoded from the GraphQL data so the identifiers map extends to all scenarios:
When the data is loaded, the map is translated to the input object, and the document contains references to the input object's values and their type, looking like this:
Eager Loading a LazyModel instance
The decoders require to have an ordering among them, we can technically always put the API model decoder and DataSore model decoder first so that when it attempts to use the decoders, and both are registered on the model decoder registry, then if it is successfully in decoding, it would have attempted DataStore before API. Both decoders are successful in decoding eager loaded models, so either providers can be created. However, if the payload can be decoded to the notLoaded LazyModel then we may have a problem where the lazy load will call into the incorrectly decoded model provider
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.