HotChocolate GraphQL query for objects with null child object

Viewed 384

Is there a way I can query for all objects where a child object is null?

I am trying to do something like this:

{
GetAllAccounts (  where: { accountManager: { eq: null} })  {
    accountManagerFid,
      accountManager {
        userLastName 
      }
  }
}

That doesn't work because accountManager is an object with it's own filter so it's expecting me to filter on some field on the accountManager object once I open that nested curly bracket after "accountManager:".

I am looking for the right way to query for "All Accounts where accountManager child object does not exist at all"

1 Answers

I never found the perfect solution, but here are the notes I took that describe a work-around I used:

So far this is the closest I have figured out (I have to look at the foreign key and not for the child object itself):

{
GetAllAccounts(  where: {  accountManagerFid: {eq: null} }) {
    accountManagerFid,
      accountManager {
        userLastName 
      }
  }
}
 
Related