You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
Describe the Bug
Consider case of Many-to-One (M2O) having 2 tables Post and Comment.
Post has fields
id
asint
content
astext
Comment has fields
id
asint
message
astext
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
increate_comment_input
schema is of typecreate_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
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
The text was updated successfully, but these errors were encountered: