Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
iartemiev opened this issue Mar 24, 2023 · 0 comments
Open
4 tasks done
Labels
amplify-codegen Issues on amplify-codegen bug Something isn't working DataStore model-gen Issues on datastore model generation p2

Comments

@iartemiev
Copy link
Contributor

iartemiev commented Mar 24, 2023

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • 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

  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify-codegen Issues on amplify-codegen bug Something isn't working DataStore model-gen Issues on datastore model generation p2
Projects
None yet
Development

No branches or pull requests

2 participants