amplify-codegen
amplify-codegen copied to clipboard
`amplify codegen models` generates model types marked as syncable when they shouldn't be
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
How did you install the Amplify CLI?
npm -g i @aws-amplify/cli
If applicable, what version of Node.js are you using?
14.19.0
Amplify CLI Version
7.6.23
What operating system are you using?
Mac
Amplify Codegen Command
codegen models
Describe the bug
When a GraphQL schema contains an Amplify directive such as the following:
type Comment @model(subscriptions: null) {
id: ID!
content: String
todo: Todo @connection(name: "TodoComments")
}
(Taken from the official docs here)
This prevents Amplify from generating create, update and delete subscriptions, but it doesn't prevent Amplify DataStore from attempting to subscribe to those non-existent subscriptions. In order to do that the syncable field on the generated should be set to false.
Others have already had to jerry-rig a solution, and I confirmed it does work, however we should really fix the root cause, which I believe is here.
Expected behavior
amplify codegen models should generate a schema.js with syncable: false for all models with a @model(subscriptions: null) directive.
Reproduction steps
- Create a GraphQL schema such as the above
- Run
amplify codegen models - Inspect
schema.jsand notice that theCommentmodel type has asyncablevalue oftruenotfalse.
PR Supplied
See PR #398 for a fix for this issue.
GraphQL schema(s)
No response
Log output
No response
Additional information
This bug has been around a long time and has been reported in other issues such as:
- aws-amplify/amplify-js#6260
- @TheMoums even created a workaround to monkey-patch the generated
schema.jsin order to get something useable in DataStore.
- @TheMoums even created a workaround to monkey-patch the generated
- aws-amplify/amplify-cli/issues/3114
- A DataStore error which is a direct result of the incorrect
syncablevalue being generated byamplify codegen models
- A DataStore error which is a direct result of the incorrect
Hi @danrivett. Thanks for bringing this to our attention and also special thanks for your contribution. #398 looks good to me but I need to double check the behavior with Datastore library team before accepting it. We will keep you posted.
Thanks for the PR @danrivett, I'm going to flip these labels back, and discuss with the team in the short-term what interface changes or updates we need to support for first-class modeling of local-only, cloud-only, and syncable models without the syncable: null thing we'd done in that PR.