Filtering out unfilled fields with gatsby/graphql/gatsby-source-prismic

Hi there,

Looking for an ideal way to validate "required" fields outside of prismic, and a way to pull prismic data into the gatsby app with graphql, filtering out unwanted entities.

the SQL idea

SELECT *
FROM allPrismicAnnouncement
WHERE quote IS NOT NULL;

actual gql i use

export const query = graphql`
query AnnouncementCardQuery {
 allPrismicAnnouncement(sort: {order: DESC, fields: data___date}) {
  edges {
   node {
   uid
    id
     data {
      quote {
        text
       }
      subtitle1 {
     text
     }
    }
   }
  }
 }
}
`

Is there a way to use filter , include or similar approach to filter out articles with no quote? Or, sort of a separate question, but a way to ignore all quotes with length < 100 chars?

Thanks!

Hey Zach!

Yes, you can use the ne operator; to filter the response with Prismic fields.

There are many options to sort, filter, and limit the response to your Gatsby queries.

In this example, I'm retrieving all documents in which the display_title field is not equal to "news"

query MyQuery {
  allPrismicPage(filter: {data: {display_title: {text: {ne: "news"}}}}) {
    edges {
      node {
        data {
          display_title {
            text
          }
        }
      }
    }
  }
}

1 Like

This issue has been closed due to inactivity. Flag to reopen.