-
Notifications
You must be signed in to change notification settings - Fork 62
feat(amplify-codegen): iOS LazyReference and ModelPath #504
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
b86af71
to
94cc68b
Compare
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #504 +/- ##
==========================================
+ Coverage 85.51% 85.69% +0.17%
==========================================
Files 148 148
Lines 7263 7374 +111
Branches 1909 1958 +49
==========================================
+ Hits 6211 6319 +108
- Misses 956 959 +3
Partials 96 96
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
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.
As discussed previously, we need a feature flag or a library version check for ios lazy loading. In either case we need to keep both old and new codegen implementations. This is a TODO for the PR. Apart from it, I have some comments below.
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
`self._${fieldName} = LazyReference(${fieldName})`, | ||
[ | ||
{ | ||
name: `_ ${this.getFieldName(field)}`, |
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.
I notice there is a space after the underline. Is this space intentional or should it be _${this.getFieldName(field)}
instead?
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.
thsi is intentional for the mutating function:
public mutating func setPost(_ post: Post4V2?) {
self._post = LazyModel(element: post)
}
the _
represents the unnamed parameter to avoid duplication of "post" in the call site. Developers don't have to specific that it is a post that they're passing in:setPost(post)
. without it, will be setPost(post: post)
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.
Apart from the Feature Flag thing that we discussed offline, one general question I have is that I see conditional changes based on ConnectionIsHasOneOrBelongsTo
but nothing for HasManyOrBelongsTo
. Can you please explain the disparity or intention?
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts
Outdated
Show resolved
Hide resolved
@phani-srikar This is because LazyReference only encapsulates hasOne and belongsTo associations. We have already shipped iOS support for "Lazy" list that is the |
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.
LGTM ⚽
18b3146
1bf0601
to
1c6f4eb
Compare
Rebased from Our options are
Update the amplify project's cli.json's |
...-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/appsync-swift-visitor.test.ts
Outdated
Show resolved
Hide resolved
6145ece
This can be merged in! thanks for the review @AaronZyLee @phani-srikar @drochetti 🙌 |
`self._${fieldName} = LazyReference(${fieldName})`, | ||
[ | ||
{ | ||
name: `_ ${this.getFieldName(field)}`, |
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.
reference: _
sets the call site to not require the parameter name
Table of contents
Instructions
To run this without the feature flag, use the branch from
lawmicha.codegen
(https://github.com/aws-amplify/amplify-codegen/tree/lawmicha.codegen), runyarn setup-dev
and in your projectamplify-dev codegen models
Alternatively, for the latest changes,
This is because the feature flag has not been merged in to the CLI repo.
3. run
yarn setup-dev
4. Back in your amplify project, use
amplify-dev codegen models
instead.Description of Changes
Schema example
Before
After
If post is required on the comment
if post is optional on the comment
developer call pattern:
When the association is required, then nil cannot be passed in to remove the association, it will only allow setting it with another model
Full Schema Example
Post Swift file
Post Swift Schema file
Comment Swift file
Comment Schema file
Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.