I’m trying to run code based on when new connections are created on a table (essentially when one record links to another). But neither the event.originalObject nor the event.data objects contain any reference to linked tables.
You can see the two objects listed below. The trigger was an update to an Account field that isn’t listed, so both objects are identical. Not only is the linked field that I updated missing, but all linked fields are missing.
At this time you cant use triggers on relations, in future we have a plan to change that, but now you have only one option:
Instead of trigger create task or resolver (depend on your logic) and run them manually when you connecting relations, here is a simple example for server-side code
export const POST_CREATE_MANY_MUTATION = gql`
mutation MetricValueCreateMany($data: [PostCreateManyInput]!) {
postCreateMany(data: $data) {
id
}
}
`;
// Here is list of connected relations
const auhtorIds = [
'ckoe61c0c02er09la4wd4556q',
'ckoe64jfb011y07mhaz7m0o49',
];
await ctx.api.gqlRequest(
POST_CREATE_MANY_MUTATION,
{
data: [{
title: "Example",
author: {
connect: {
id: { in: auhtorIds }
}
}
}, {
title: "Example 2",
author: {
connect: {
id: { in: auhtorIds }
}
}
}]
}
);
// Only allowed in server context (deployed custom functions)
await ctx.invokeFunction(
'onConnectAuthorTask', // it can be task or even trigger
{ data: { auhtorIds } },
{ waitForResponse: false }, // if you don't need to wait for the trigger
);
if you make a request from the frontend (like react app) use your gql client instead of ctx.api.gqlRequest, and invokeFunction will be replaced with gql mutation.
Let me know if you have any questions about this example.