feat: Ability to use "where" clause inside `insert` mutation to link existing data
See original GitHub issue_Note from Hasura team: issue closed in favour of https://github.com/hasura/graphql-engine/issues/1573_
I think this is a feature request.
Given the following schema:
CREATE TABLE "Person" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid()
);
CREATE TABLE "EmailAddress" (
"personId" uuid NOT NULL REFERENCES "Person" ("id") ON DELETE CASCADE,
"emailAddress" citext PRIMARY KEY
);
CREATE TABLE "Agreement" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
"text" citext NOT NULL
);
CREATE TABLE "PersonAgreement" (
"personId" uuid NOT NULL REFERENCES "Person" ("id") ON DELETE CASCADE,
"agreementId" uuid NOT NULL REFERENCES "Agreement" ("id") ON DELETE CASCADE,
"value" boolean NOT NULL
);
A person can be uniquely found using an email address. I’d like to insert a new PersonAgreement into the database given an agreementId
, emailAddress
, and PersonAgreement value
.
Using sql, the email address could be used to get the related personId
which could be combined with the agreementId
and value
to insert a new PersonAgreement
.
At the moment, it does not appear to be possible to execute this query within a transaction using Hasura. The problem is that the only way to associate the Person with the new PersonAgreement is to insert a new Person along with the PersonAgreement. Except in this case I don’t wish to create a new Person, I wish to find an existing person or have the mutation fail.
Example of the query I’d like to perform:
mutation AddPersonAgreement(
$emailAddress: String!,
$agreementId: uuid!,
$value: Boolean!
) {
insert_PersonAgreement(
objects: {
value: $value,
agreementId: $agreementId,
person: {
where: { # <-- new API here
emailAddresses: { emailAddress: { _eq: $emailAddress } }
}
}
}
) {
affected_rows
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:9 (2 by maintainers)
Related to #3366
This could be resolved if it were possible to add nested objects via the update mutation.
Something roughly along the lines of:
This is a feature being worked on and should be released soon.
Yes, this query might translate to:
I’m not sure if this SQL is correct, but hopefully the idea is clear.