<p>I know this question is 1.5+ years old but I landed here looking for something similar and think I found the answer: <code>relatedToEntries</code>.
In the docs: <a href="https://craftcms.com/docs/3.x/graphql.html#relations" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/graphql.html#relations</a></p>
<p>Something like this (replacing 'attributeHandle' and &quot;valueYouWant&quot;):</p>
<pre><code>query test {
  entries(section: &quot;vacancies&quot;, relatedToEntries({attributeHandle: &quot;valueYouWant&quot;) {
    title
    ... on vacancies_vacancies_Entry {
      description
      organisation {
        title
        ... on organisations_organisations_Entry {
          organisationType
        }
      }
    }
  }
}
</code></pre>
<p>Works for me. Hope that helps get someone on the right path!</p>

CC BY-SA 4.0
2021-10-22T15:49:42.843Z
2021-10-22T15:49:42.843Z
Kirk Roberts
<p>Lets have this query:</p>

<pre><code>query test {
  entries(section: "vacancies") {
    title
    ... on vacancies_vacancies_Entry {
      description
      organisation {
        title
        ... on organisations_organisations_Entry {
          organisationType
        }
      }
    }
  }
}
</code></pre>

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

<p>I guess I can first query organisations, get their <strong>IDs</strong> and then pass it to <strong>relatedTo</strong> 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?</p>

CC BY-SA 4.0
2020-07-09T03:38:37.957Z
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".
misteraidan
CC BY-SA 4.0
2021-09-26T16:59:04.963Z
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
<relations><relatedto><graphql>
In GraphQL how to query entries where related entry has a specific value
# In GraphQL how to query entries where related entry has a specific value

(Asked by: username_0 on 2020-03-05)

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?

**Tags:** relations, relatedto, graphql

> **Comments:**
> **username_1**: 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".  
> **username_2**: 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.  

---

## 1 answers

### Answer by username_3 on 2021-10-22. Score: 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!


---

