Query by reverse relationship?

Hey folks! I was wondering if it’s possible to query by reverse relationship, and if so, what the syntax is for that? In my example, I have a “Project” type, which has a relationship to many “Organization” entities. I’d like to pass my query the value of a custom field on the “Organization” data type, and return all Projects that are related to that Organization… In Strapi I would do something like so:

query Projects($orgId: String!) {
    privateProjects: portfolioProjects(
      filters: {
        Private: { eq: true }
        organizations: { ClerkID: { eq: $orgId } }
      }
    ) {
      data {
        id
     }
  }

Hello @stevenlangbroek,

Welcome to the builder.io forum post.

In Builder.io, you can indeed query by reverse relationship using GraphQL. Assuming you have set up the relationships between “Project” and “Organization” entities, and you want to retrieve all projects related to a specific organization based on a custom field value, you would construct your GraphQL query similarly to your example in Strapi.

Here’s how you might structure your query in Builder.io:

query Projects($orgId: String!) {
  projects(
    limit: 100
    options: {
      query: {
        'content.organization': { $eq: $orgId }
      }
    }
  ) {
    results {
      id
      # Other fields you want to retrieve
    }
  }
}

Make sure to adjust field names (content.organization ) and IDs ($orgId ) based on your actual schema and data structure in Builder.io.

Thanks,