amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

`amplify codegen models` generates model types marked as syncable when they shouldn't be

Open danrivett opened this issue 3 years ago • 2 comments

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

  1. Create a GraphQL schema such as the above
  2. Run amplify codegen models
  3. Inspect schema.js and notice that the Comment model type has a syncable value of true not false.

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.js in order to get something useable in DataStore.
  • aws-amplify/amplify-cli/issues/3114
    • A DataStore error which is a direct result of the incorrect syncable value being generated by amplify codegen models

danrivett avatar Mar 10 '22 03:03 danrivett

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.

phani-srikar avatar Mar 14 '22 17:03 phani-srikar

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.

alharris-at avatar May 10 '22 18:05 alharris-at