amplify-codegen
amplify-codegen copied to clipboard
GSI creation with @index doesn't set default value for `name` property
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?
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:
type Post @model {
id: ID!
title: String! @index
}
Generates
{
"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.
{
"type": "key",
"properties": {
"name": "byTitle",
"fields": [
"title"
]
}
}
Reproduction steps
- Generate MIPR with the included schema
GraphQL schema(s)
# 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