<p>Perhaps something like this?</p>
<p>I don't know the structure of your data but this would be my best 'educated guess'.</p>
<p>I renamed the different ID's to make it a little more clear in the response.</p>
<pre><code>query MyQuery {
  categories(relatedToEntries: {section: &quot;entryType&quot;}) {
    categoryId: id
    title
    entries(relatedToCategories: categoryId) {
      entryId: id,
      title
    }
  }
}
</code></pre>

CC BY-SA 4.0
2022-04-26T13:41:28.460Z
This does not seem to work. If i put a similar entries query below categories with an hard-code ID i get results, but it does not produce results or errors when located inside the categories query.
Jørgen
CC BY-SA 4.0
2022-04-27T08:59:22.803Z
That would suggest that `categoryId` is not actually passed into the nested entries() query. I'm... not sure why tbh.
InanisAtheos
CC BY-SA 4.0
2022-04-27T09:09:30.973Z
Does not work with an hard-coded ID inside the categories query either.. it looks like GQL is basically ignoring the entire entries() query when inside categories()
Jørgen
CC BY-SA 4.0
2022-04-28T07:00:38.257Z
I'm starting to wonder how your GraphQL is set up. I think you need to start there and look it over. Following the the docs over at https://craftcms.com/docs/3.x/graphql.html, my solution looks correct.
InanisAtheos
CC BY-SA 4.0
2022-04-26T11:18:25.313Z
2022-04-26T11:18:25.313Z
InanisAtheos
<p>Is it possible to get categories with related entries with one graphQL query?</p>
<p>I have the following query:</p>
<pre><code>query MyQuery {
  categories(relatedToEntries: {section: &quot;entryType&quot;}) {
    id
    title
  }
}
</code></pre>
<p>Giving me this result:</p>
<pre><code>{
  &quot;data&quot;: {
    &quot;categories&quot;: [
      {
        &quot;id&quot;: &quot;253&quot;,
        &quot;title&quot;: &quot;Category One&quot;
      },
      {
        &quot;id&quot;: &quot;257&quot;,
        &quot;title&quot;: &quot;Category Two&quot;
      }
    ]
  }
}
</code></pre>
<p>I would like something like the following:</p>
<pre><code>{
  &quot;data&quot;: {
    &quot;categories&quot;: [
      {
        &quot;id&quot;: &quot;253&quot;,
        &quot;title&quot;: &quot;Category One&quot;,
        &quot;entries&quot;: [
           {
              &quot;id&quot;: 1,
              &quot;title&quot;: &quot;Title&quot;
         }
      },
      {
        &quot;id&quot;: &quot;257&quot;,
        &quot;title&quot;: &quot;Category Two&quot;,
        &quot;entries&quot;: [
           {
              &quot;id&quot;: 1,
              &quot;title&quot;: &quot;Title&quot;
         }
    ]
  }


}

 
</code></pre>

<categories><graphql>
GraphQL - Categories with entries
# GraphQL - Categories with entries

(Asked by: username_0 on 2022-04-22)

Is it possible to get categories with related entries with one graphQL query?
I have the following query:
query MyQuery {
  categories(relatedToEntries: {section: "entryType"}) {
    id
    title
  }
}

Giving me this result:
{
  "data": {
    "categories": [
      {
        "id": "253",
        "title": "Category One"
      },
      {
        "id": "257",
        "title": "Category Two"
      }
    ]
  }
}

I would like something like the following:
{
  "data": {
    "categories": [
      {
        "id": "253",
        "title": "Category One",
        "entries": [
           {
              "id": 1,
              "title": "Title"
         }
      },
      {
        "id": "257",
        "title": "Category Two",
        "entries": [
           {
              "id": 1,
              "title": "Title"
         }
    ]
  }


}

**Tags:** categories, graphql

---

## 1 answers

### Answer by username_1 on 2022-04-26. Score: -1

Perhaps something like this?
I don't know the structure of your data but this would be my best 'educated guess'.
I renamed the different ID's to make it a little more clear in the response.
query MyQuery {
  categories(relatedToEntries: {section: "entryType"}) {
    categoryId: id
    title
    entries(relatedToCategories: categoryId) {
      entryId: id,
      title
    }
  }
}

> **Comments:**
> **username_0**: This does not seem to work. If i put a similar entries query below categories with an hard-code ID i get results, but it does not produce results or errors when located inside the categories query.  
> **username_1**: That would suggest that `categoryId` is not actually passed into the nested entries() query. I'm... not sure why tbh.  
> **username_0**: Does not work with an hard-coded ID inside the categories query either.. it looks like GQL is basically ignoring the entire entries() query when inside categories()  
> **username_1**: I'm starting to wonder how your GraphQL is set up. I think you need to start there and look it over. Following the the docs over at https://craftcms.com/docs/3.x/graphql.html, my solution looks correct.  

---

