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

Many-To-Many Connections have incorrect generated mutations for join model #3438

Closed
ghost opened this issue Feb 16, 2020 · 5 comments · Fixed by #4171
Closed

Many-To-Many Connections have incorrect generated mutations for join model #3438

ghost opened this issue Feb 16, 2020 · 5 comments · Fixed by #4171
Assignees
Labels
bug Something isn't working graphql-transformer-v1 Issue related to GraphQL Transformer v1

Comments

@ghost
Copy link

ghost commented Feb 16, 2020

Describe the bug
Take example schema from page https://aws-amplify.github.io/docs/cli-toolchain/graphql#connection
Many-To-Many Connections and run the related example mutations.

The CreateLinks mutation fails.

This prevents filling up the join model table with data, thus making many to many connections not usable.

type Post @model {
  id: ID!
  title: String!
  editors: [PostEditor] @connection(keyName: "byPost", fields: ["id"])
}

# Create a join model and disable queries as you don't need them
# and can query through Post.editors and User.posts
type PostEditor
  @model(queries: null)
  @key(name: "byPost", fields: ["postID", "editorID"])
  @key(name: "byEditor", fields: ["editorID", "postID"]) {
  id: ID!
  postID: ID!
  editorID: ID!
  post: Post! @connection(fields: ["postID"])
  editor: User! @connection(fields: ["editorID"])
}

type User @model {
  id: ID!
  username: String!
  posts: [PostEditor] @connection(keyName: "byEditor", fields: ["id"])
}

Execution of CreateLinks mutation fails:

mutation CreateData {
    p1: createPost(input: { id: "P1", title: "Post 1" }) {
        id
    }
    p2: createPost(input: { id: "P2", title: "Post 2" }) {
        id
    }
    u1: createUser(input: { id: "U1", username: "user1" }) {
        id
    }   
    u2: createUser(input: { id: "U2", username: "user2" }) {
        id
    }
}

mutation CreateLinks {
    p1u1: createPostEditor(input: { id: "P1U1", postID: "P1", editorID: "U1" }) {
        id
    }   
    p1u2: createPostEditor(input: { id: "P1U2", postID: "P1", editorID: "U2" }) {
        id
    }
    p2u1: createPostEditor(input: { id: "P2U1", postID: "P2", editorID: "U1" }) {
        id
    }
}

Error message:

Validation error of type WrongType: **argument 'input'** with value 
'ObjectValue{
objectFields=[ObjectField{name='id', value=StringValue{value='P1U1'}}, ObjectField{name='postID', value=StringValue{value='P1'}}, ObjectField{name='editorID', value=StringValue{value='U1'}}]}' **is missing required fields '[post]' @ 'createPostEditor'**

Amplify CLI Version
4.13.3

To Reproduce
Setup example schema and run example mutations

Expected behavior
Mutation CreateLinks is executed successfully.

Screenshots
none

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: v12.16.0

Additional context
The generated schema type CreatePostEditorInput contains post: PostInput! field which is probably the root cause of the issue.

input CreatePostEditorInput {
  id: ID
  postID: ID!
  editorID: ID!
  post: PostInput!
  _version: Int
}
@ammarkarachi ammarkarachi added graphql-transformer-v1 Issue related to GraphQL Transformer v1 pending-triage Issue is pending triage bug Something isn't working and removed pending-triage Issue is pending triage labels Feb 16, 2020
@SwaySway
Copy link
Contributor

Hello @silvesteradamik the bug here is that the input type is requiring the post in CreatePostEditorInput type. A potential workaround here would be to make the connected fields nullable. This would not make a requirement to add the post type in the mutation.

@ghost
Copy link
Author

ghost commented Feb 21, 2020

Making the connected fields nullable solved the problem with filling the join connection table.

However, there is now visible different issue:
I can get correct result when listing Users - I can see posts related to them.
I get empty usesrs in listing Posts - I can't see users related to posts.

When fixing the issue, please check that the relations between the Editor and Post tables work bidirectional.

@attilah
Copy link
Contributor

attilah commented May 5, 2020

This is only happening when conflict resolution is enabled, without that Transformer is behaving correctly.

@silvesteradamik Please confirm that you've enabled conflict resolution for your API.

@attilah attilah added pending-response Issue is pending response from the issue author and removed pending-response Issue is pending response from the issue author labels May 5, 2020
@amuresia
Copy link

Hi @attilah I can see the same error and I can confirm that I don't have conflict resolution enabled.
Schema:

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}

type Post @model @key(name: "byBlog", fields: ["blogID"]) {
  id: ID!
  title: String!
  blogID: ID!
  blog: Blog @connection(fields: ["blogID"])
  comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

type Comment @model @key(name: "byPost", fields: ["postID", "content"]) {
  id: ID!
  postID: ID!
  post: Post @connection(fields: ["postID"])
  content: String!
}

transform.conf.json

{
    "Version": 5,
    "ElasticsearchWarning": true
}

Error

Completed with error: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Variable \'input\' has coerced Null value for NonNull type \'ID!\'", locations: Optional([Amplify.GraphQLError.Location(line: 1, column: 21)]), path: nil, extensions: nil)]

@github-actions
Copy link

github-actions bot commented Jun 1, 2021

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working graphql-transformer-v1 Issue related to GraphQL Transformer v1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants