Query by content relationship

Hey,

I tried following the example in this tutorial - Query Data with GraphQL - Prismic but it doesn't work.

My query looks like this:

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

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:

{
  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 or do a fullText search, which also uses the where argument. It looks for coincidences in Rich Text, Key Text, Select, and UID fields

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

I get the following error in the console:

/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

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

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

@Pau The repo URL is https://sharetribe.prismic.io

Thank you!

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 to get all the docs that match a given Id. Take a look at this new example query

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

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

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