Retrieve Articles having specific category

Hi,
I am new to Prismic and am in the process of developing a GraphQL query. However, I am facing confusion regarding how to retrieve articles that belong to a specific category type.

Here is the query

<<~GRAPHQL
      {
        allArticles(
          where: {
            online_only: true,
            category: { category: "#{category}" }
          },
          tags: "#{tag}",
          sortBy: meta_firstPublicationDate_DESC
        ) {
          edges {
            node {
              _meta {
                uid
                type
                tags
                firstPublicationDate
              }
              title
              short_title
              description
              featured_image
              category {
                ... on Category {
                  category
                }
              }
              authors {
                ... on ArticleAuthors {
                  author {
                    ... on Author {
                      _meta {
                        uid
                      }
                      name
                    }
                  }
                }
              }
            }
          }
        }
      }
    GRAPHQL

and here is the error I am facing

{
    :data => nil,
    :errors => [
        [0] {
              :message => "Expected type 'String', found '{category: \"Policy\"}'. String value expected (line 5, column 17):\n      category: { category: \"Policy\" }\n                ^",
            :locations => [
                [0] {
                      :line => 5,
                    :column => 17
                }
            ]
        }
    ]
}

Any help will be appreciated. Thanks!

Hi @haideralifsd786 ,

Welcome to the community!

For this you'll need the filter method:

1 Like

Great, it works :+1:
Thanks!

1 Like