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

Using GraphQL API, creating an item having M2O relationship does not allow providing the foreign key instead requires that a new related object be created #13689

Closed
ravi-2912 opened this issue Jun 2, 2022 · 1 comment

Comments

@ravi-2912
Copy link

ravi-2912 commented Jun 2, 2022

Describe the Bug

Consider case of Many-to-One (M2O) having 2 tables Post and Comment.

Post has fields

  • id as int
  • content as text

Comment has fields

  • id as int
  • message as text
  • post which is as foreign key to table Post (M2O relation)

In GraphQL, a comment can only be created if a new post is also created. The schema definition of post in create_comment_input schema is of type create_post_input which means a post must be create if a new comment has to be made.

This is not a desired behaviour as and as I cannot create a new comment without creating a post. I wish to create a comment and be able to assign a post by providing its id. Could you please look. Ideally, it would be nice to have both.

To Reproduce

Steps are described above. Create Post and Comment table with M2O relations.

Creat a post first.
Then try creating a comment.
GraphQL with throw GRAPHQL_VALIDATION_EXCEPTION and will require that a new post must be created if creating a new comment.

Errors Shown

This error below is for my personal project and not for Post/Comment scenario.

My Query

mutation CREATE_INSTURMENTS {
  create_instrument_item(
    data: {
      name: "Wheat"
      ticker: "WHT"
      broker: 1
      status: "draft"
    }
  ) {
    id
  }
}
{
  "error": {
    "errors": [
      {
        "message": "GraphQL validation error.",
        "extensions": {
          "code": "GRAPHQL_VALIDATION_EXCEPTION",
          "graphqlErrors": [
            {
              "message": "Expected value of type \"create_broker_input\", found 1.",
              "locations": [
                {
                  "line": 2,
                  "column": 77
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

What version of Directus are you using?

9.11.1

What version of Node.js are you using?

16.15.0

What database are you using?

Postgres 14

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@rijkvanzanten
Copy link
Member

Duplicate of #7237

@rijkvanzanten rijkvanzanten marked this as a duplicate of #7237 Jun 2, 2022
@rijkvanzanten rijkvanzanten closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants