I'm having trouble building a hasura graphql query that inserts a row into a table that has multiple foreign key relationships.
I have three tables, "Users", "Groups", and "UserGroups". The "UserGroups" table has foreign key relationships on columns groupId, and userId. I used Hasura's UI to track the relationships that it had suggested based on the two foreign keys.
I can create new UserGroups by connecting to the database directly but when I try to create a new UserGroup through a graphql query I get a foreign key violation response.
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_user_group.args.objects",
"code": "constraint-violation"
},
"message": "Foreign key violation. insert or update on table \"user_group\" violates foreign key constraint \"user_group_userId_fkey\""
}
]
}
Here is the mutation I'm trying to use:
mutation insert_user_group {
insert_user_group(objects: [{
userId: 1,
groupId: 1,
}]) {
affected_rows
}
}
I was only able to find documentation regarding querying tables with one-to-many relationships but nothing showing how to construct an insert mutation.