3

Lets have this query:

query test {
  entries(section: "vacancies") {
    title
    ... on vacancies_vacancies_Entry {
      description
      organisation {
        title
        ... on organisations_organisations_Entry {
          organisationType
        }
      }
    }
  }
}

Now how would I go about only displaying vacancies from an organisation that has a specific organisationType . I've had a quick read through graphQl docs and couldn't find anything that could help.

I guess I can first query organisations, get their IDs and then pass it to relatedTo parameter to another query, but that's 2 API requests each time I want to make a query. Is it possible to somehow use one graphQL query as a parameter in another graphQl query? Are there any better solutions to this?

2
  • Would really like to know this also, as it would be a very common use-case. This is similar to a simple join in SQL, e.g. "select * from x join y on y.xid=x.id and y.type=2". Jul 9, 2020 at 3:38
  • Did you ever figure this out? I am hitting the same wall. I need to grab related Matrix blocks, but in order to get those related blocks, I need to send over an entry element or an entry id. I'd rather not have to run two queries every time. Argh.
    – Jacob Graf
    Sep 26, 2021 at 16:59

1 Answer 1

2

I know this question is 1.5+ years old but I landed here looking for something similar and think I found the answer: relatedToEntries. In the docs: https://craftcms.com/docs/3.x/graphql.html#relations

Something like this (replacing 'attributeHandle' and "valueYouWant"):

query test {
  entries(section: "vacancies", relatedToEntries({attributeHandle: "valueYouWant") {
    title
    ... on vacancies_vacancies_Entry {
      description
      organisation {
        title
        ... on organisations_organisations_Entry {
          organisationType
        }
      }
    }
  }
}

Works for me. Hope that helps get someone on the right path!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.