aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

Generates twice the connection ID #2431

Open juri-diener opened 6 months ago

juri-diener commented 6 months ago

How did you install the Amplify CLI?

npm

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

20.6.1

Amplify CLI Version

11.0.5

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

type User @model @auth(rules: [{ allow: private }]) {
  id: ID!
  name: String
  myOrg: Org @hasOne
  orgs: [Org] @manyToMany(relationName: "OrgUser")
}

type Org
  @model
  @auth(
    rules: [
      { allow: private, operations: [read] }
      { allow: groups, groups: ["Admins"] }
    ]
  ) {
  id: ID! @primaryKey(sortKeyFields: ["userID"])
  name: String!
  userID: ID!
  users: [User] @manyToMany(relationName: "OrgUser")
  user: User @belongsTo(fields: ["userID"])
}

So if I have this models with the relation ships. It creates for the createUserInput following:

id: ID
name: String
userMyOrgId: ID
userMyOrgUserID: ID

This is related both to the myOrg:Org @hasOne relation. If I remove the entire line, then both userMyOrgId and userMyOrgUserID are gone.

As well for the between model which are created automatically has the same issue.

createOrgUser(condition: ModelOrgUserConditionInputinput: CreateOrgUserInput!): OrgUser
CreateOrgUserInput: 
id: ID
userId: ID!
orgId: ID!
orguserID: ID!

And I different problem: So when I add an item in OrgUser. Provide the orgId, orguserID with the orgId and the userId with the userId. And then query the user I got null.

query MyQuery {
  getUser(id: "someID") {
    orgs {
      items {
        org {
          name
        }
      }
    }
  }
}

If I remove the hasOne relation then it works. But this is a common pattern. That a user as one org because he is the owner and user can be part of multiple orgs and org can have multiple user.

Expected behavior

For createUserInput:

id: ID
name: String
userMyOrgUserID: ID

For CreateOrgUserInput:

id: ID
userId: ID!
orgId: ID!

Reproduction steps

Create the model and push it with amplify push -y

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

ykethan commented 6 months ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

AnilMaktala commented 5 months ago

Hi @juri-diener, My apologies for the delayed response. Could you provide more details on the relationships between 'user' and 'org'? Can a 'user' be associated with multiple 'orgs'?

AnilMaktala commented 5 months ago

Hi @juri-diener, I can reproduce the issue by following the details in the description. Hence, marking this as a bug for the team to evaluate further.

image
juri-diener commented 4 months ago

Hi @juri-diener, I can reproduce the issue by following the details in the description. Hence, marking this as a bug for the team to evaluate further.

image

Hi, ok that's good any update on this?