0

Since prismic has no concept of required fields, we might end up with null instead of data.

I am looking for a way to pull prismic data in gatsby app, 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
     }
    }
   }
  }
 }
}
`

how to use filter, include or similar approach to filter out filtering out articles with no quote. Option 2 - ignore all quotes with length < 100 chars

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Lev Savranskiy
  • 422
  • 2
  • 7
  • 19

1 Answers1

0

This question has answers on prismic community forum

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

I'm using allPrismicBlogpost and have a similar query and problem. I think something like this would work for you (changed sort to first_publication_date).

export const query = graphql`
query AnnouncementCardQuery {
 allPrismicAnnouncement(filter: {data: {quote: {text: {ne: null}}}}, sort: { order: DESC, fields: first_publication_date}) {
  edges {
   node {
   uid
    id
     data {
      quote {
        text
       }
      subtitle1 {
     text
     }
    }
   }
  }
 }
}
`
Geoff Williams
  • 1,320
  • 10
  • 15