aws-amplify / aws-amplify/amplify-codegen

GSI creation with @index doesn't set default value for `name` property

Open
#561 0 comments 0 reactions 0 assignees View on GitHub
amplify-codegen bug DataStore model-gen p2
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/main/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?

_No response_

### If applicable, what version of Node.js are you using?

_No response_

### Amplify CLI Version

11.0.3

### What operating system are you using?

macOS

### Amplify Codegen Command

codegen models

### Describe the bug

If I annotate a field in my model type with the `@index` directive without supplying a value for `name`, the generated MIPR also omits the name field. This causes DataStore to incorrectly treat the key attribute as a primary key, as the presence/absence of the `name` field in the MIPR is the only way DataStore can distinguish between PKs and GSIs. Inability to distinguish between these types of keys causes unexpected behavior DataStore.

Example:
```gql
type Post @model {
id: ID!
title: String! @index
}
```

Generates
```json
{
"type": "key",
"properties": {
"fields": [
"title"
]
}
}
```

### Expected behavior

Codegen should default the `name` to the query field generated by the GQL transformer. For example, for the schema above, it would be `PostByTitle` or `byTitle`.

```json
{
"type": "key",
"properties": {
"name": "byTitle",
"fields": [
"title"
]
}
}
```

### Reproduction steps

1. Generate MIPR with the included schema

### GraphQL schema(s)

```graphql
# Put schemas below this line
type Post @model {
id: ID!
title: String! @index
}
```

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

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.