aws-amplify / aws-amplify/amplify-codegen

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

Open
#397 2 comments 0 reactions 0 assignees View on GitHub
feature-request model-gen p3
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### 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](https://github.com/aws-amplify/amplify-codegen/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-codegen/blob/master/CONTRIBUTING.md#bugs).
- [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:

```graphql
type Comment @model(subscriptions: null) {
id: ID!
content: String
todo: Todo @connection(name: "TodoComments")
}
```

(Taken from the official docs [here](https://docs.amplify.aws/cli-legacy/graphql-transformer/examples/#filter-subscriptions-by-model-fields-andor-relations))

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](https://github.com/aws-amplify/amplify-js/issues/6260#issuecomment-831155632) a solution, and I confirmed it does work, however we should really fix the root cause, which I believe is [here](https://github.com/aws-amplify/amplify-codegen/blob/master/packages/appsync-modelgen-plugin/src/visitors/appsync-json-metadata-visitor.ts#L196).

### 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](https://github.com/aws-amplify/amplify-js/issues/6260#issuecomment-831080188) 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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.