Trigger data and originalObject don't include linked table data

I’m calling a third party api after the update of a record that includes two table columns linking to records in other tables.

In my mutation I define these linked records in the response data which works as expected, however in the after trigger these linked records are completely excluded from the event data and originalObject.

I need to get the ID’s from these linked records to be able to make the third party api call.

Is there something I need to be doing to have these linked records included? Or is there some other way I can pass the ID’s through so they are available for the third party api call?

@squadsdev looking into that. Will answer shortly

Hey @squadsdev!

Just to clarify.

You have Record A. It is related to Record B and Record C. Both of which are stored in other tables.

You’re running a mutation using the tablenameUpdate, and have also deployed a Custom Trigger function that runs on tablename.update.

In the Trigger function, you’re seeing that it is firing but are unable to get any data from the arguments? Or you are getting data, though not the data you want?

If these assumptions are correct and you ARE getting Record A’s data in the function, know that the way to get the other information you’re looking for would be to run a GraphQL query from within the function.

I’m sure you’ve found these docs: https://docs.8base.com/8base-console/custom-functions/triggers#trigger-after. However, considering the following event object being passed to the function:

{
  // Data returned
  "data": {...},
  // Data sent
  "originalData": {...},
  // Original data record
  "originalObject": {...} // or null,
  // Request headers
  "headers": {...}
}

The context argument can be used to run a query that fetches the information you are looking for. So if this was your function, consider the following pseudo code.

/* Create a query */
const QUERY = `
query($id: ID) {
  recordATable(id: $id) {
    recordBRelation {
      id 
    }
    recordCRelation {
      id 
    }
  }
}
`;

module.exports = async (event, ctx) => {
  /* Get the objectID */
  let { id } = event.originalData;

  /* Function code*/
  let resp = await ctx.api.gqlRequest(QUERY, { id });

  // Do something
};
1 Like

Thanks @sebastian.scholl, getting data but not all of what I needed/expected is available within the trigger function. I think the additional lookup is going to be the answer in this case.

To make it a bit clearer, this example mutation would complete fine and return a member object with group and user objects that are records from the groups and users tables:

mutation($memberId: ID!) {
    memberUpdate(data: {
      status: "Active"
    }, filter: {
      id: $memberId
    }) {
      id
      role
      status
      group {
        id
      }
      user {
        id
      }
    }

But the event.data and event.originalObject objects in the after trigger function only include the id, role and status values. The group and user records are not included.

I’m guessing something to do with nested resolvers in graphql and the trigger function only returning the context for the primary/parent resolver?

Thanks for sharing the mutation!

So the response specified in the GraphQL mutation is ONLY what gets returned in the API response. The trigger function doesn’t receive the GraphQL response, it receives record being updated as an object WITHOUT any related objects.

The way to get the related objects would be to run a query!

Ah ok, thanks for clarifying that @sebastian.scholl.

Might be good to note that in the docs somewhere, it currently sounds like I should get the full response in the after trigger event data.

1 Like