# Query by content relationship

**URL:** <https://community.prismic.io/t/query-by-content-relationship/6366>\
**Category:** Developing with Prismic\
**Tags:** graphql\
**Created:** [July 22, 2021, 6:14pm UTC](https://community.prismic.io/t/query-by-content-relationship/6366 "2021-07-22T18:14:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [July 22, 2021, 6:14pm UTC](https://community.prismic.io/t/query-by-content-relationship/6366/1 "2021-07-22T18:14:09Z")

</div>

Hey,

I tried following the example in this tutorial - [Query Data with GraphQL - Prismic](https://prismic.io/docs/technologies/query-by-a-content-relationship-or-link-field-graphql) but it doesn't work.

My query looks like this:

```auto
query {
  allPrismicAcademyPost(where: { category: "field" }) {
    edges {
      node {
        data {
          uid
        }
      }
    }
  }
}

```

I get the error "Unknown argument "where" on field"

Further more, I need to query by id. So if I go to this URL **/author/estherval** I can get the ID of the author but then how can I use this id as a variable in my next query to retrieve the related posts.

Thanks,  
Kris

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [July 23, 2021, 12:20am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/2 "2021-07-23T00:20:57Z")

</div>

Hey @kris

I updated that document to be more accurate. So, `category` is the API ID of a Content Relationship or Link field, and `"field"` should be the ID of the document you're looking for.

So your query should look like this instead:

```auto
{
  allPrismicAcademyPost(where: {your_link_field: "XYNDLREAACIAjhs1"}) {
    edges {
      node {
        data {
          uid
        }
      }
    }
  }
}

```

Then, for the URL, It'll depend on how you're building your URLs.  
To make queries to get related posts you could use [the `similar` argument](https://prismic.io/docs/technologies/query-similar-documents-graphql) or do a [`fullText` search](https://prismic.io/docs/technologies/fulltext-search-graphql), which also uses the where argument. It looks for coincidences in Rich Text, Key Text, Select, and UID fields

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [July 23, 2021, 8:02am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/4 "2021-07-23T08:02:24Z")

</div>

> [@Pau](#):
>
> ```auto
> {
> allPrismicAcademyPost(where: {your_link_field: "XYNDLREAACIAjhs1"}) {
> edges {
> node {
> data {
> uid
> }
> }
> }
> }
> }
> 
> ```

Hi @Pau , thank you for the answer but I still see the same error in the Graphql portal. See the screenshot below

 ![Screenshot 2021-07-23 at 09.01.39](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/3/37c3e1759d0a207b978edbd6fc6eb75762cf2d15.png)

I get the following error in the console:

```auto
/Users/kris/Documents/code/freelance/sharetribe/nemesis/src/templates/author.js
  77:27 error Unknown argument "where" on field "Query.allPrismicAcademyPost" graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

failed Re-building development bundle - 4.032s
success Writing page-data.json files to public directory - 0.001s - 0/38 30778.98/s
ERROR in 
/Users/kris/Documents/code/freelance/sharetribe/nemesis/src/templates/author.js
  77:27 error Unknown argument "where" on field "Query.allPrismicAcademyPost" graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

webpack compiled with 1 error

```

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [July 26, 2021, 1:51pm UTC](https://community.prismic.io/t/query-by-content-relationship/6366/5 "2021-07-26T13:51:31Z")

</div>

@Pau Apologies, just want to ping you again. This is a blocker for my client project at the moment.

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [July 26, 2021, 9:00pm UTC](https://community.prismic.io/t/query-by-content-relationship/6366/6 "2021-07-26T21:00:11Z")

</div>

Hello @kris, could you send me the URL of your repository?  
I'd like to try and reproduce this error on my end.

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [July 27, 2021, 9:05am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/7 "2021-07-27T09:05:25Z")

</div>

@Pau The repo URL is [https://sharetribe.prismic.io](https://sharetribe.prismic.io)

Thank you!

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [July 28, 2021, 12:35am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/8 "2021-07-28T00:35:26Z")

</div>

Hey Kris, I didn't realize at first that you `where` using Gatsby. In this case, it is not a where argument what you need. You'll use [the filter argument](https://prismic.io/docs/technologies/arguments-filter-sort-limit-skip-gatsby) to get all the docs that match a given Id. Take a look at this new example query

```auto
{
  allPrismicAcademyPost(filter: {data: {author: {id: {eq: "YP2kyhAAAB8AuuiO"}}}}) {
    edges {
      node {
        data {
          author {
            id
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [July 28, 2021, 8:27am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/9 "2021-07-28T08:27:23Z")

</div>

Thanks @Pau - that's the way to do it!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [July 29, 2021, 8:27am UTC](https://community.prismic.io/t/query-by-content-relationship/6366/10 "2021-07-29T08:27:30Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 3:33pm UTC](https://community.prismic.io/t/query-by-content-relationship/6366/11 "2021-12-09T15:33:46Z")

</div>


