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

[feature request] Add join table identification to the introspection schema

Open hein-j opened this issue 2 years ago • 0 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?

No response

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

No response

Amplify CLI Version

10.7.3

What operating system are you using?

Mac

Amplify Codegen Command

other codegen <subcommand> (please mention in the issue)

Describe the bug

This is a feature request

Currently, there is no 100% sure way of telling whether a model is a join table from the introspection schema.

Definition of "join table" here: Given the schema:

type User @model {
  id: ID!
  Entries: [Entry] @hasMany(indexName: "byUser", fields: ["id"])
  Images: [Image] @hasMany(indexName: "byUser", fields: ["id"])
  Dogs: [Dog] @manyToMany(relationName: "UserDog")
}

type Entry @model  {
  id: ID!
  userID: ID! @index(name: "byUser")
  User: User @belongsTo(fields: ["userID"])
  Images: [Image] @hasMany(indexName: "byEntry", fields: ["id"])
}

type Image @model {
  id: ID!
  userID: ID! @index(name: "byUser")
  entryID: ID! @index(name: "byEntry")
  User: User! @belongsTo(fields: ["userID"])
  Entry: Entry! @belongsTo(fields: ["entryID"])
}

type Dog @model {
  Users: [User] @manyToMany(relationName: "UserDog")
}

UserDog should be identified as a join table and Image should not be.

Expected behavior

Request: In the schema produced by running amplify codegen model-introspection --output-dir example...

  1. Mark join table models with a property like isJoinTable: true
  2. Add an identification to the model introspection schema so that it can be distinguished from a) the MIPR and b) previous versions of itself. Example: isIntrospection: true, version: 1.1.0 (or does the version field there currently already serve as this indicator?)

Reproduction steps

N/A

GraphQL schema(s)

No response

Log output

No response

Additional information

No response

hein-j avatar Feb 17 '23 17:02 hein-j