DEV Community

Discussion on: Gridsome Pagination

Collapse
 
hizbe profile image
Muhammad Hizbullah • Edited

#ask

if I'll to filter data in taxonomy pages, example :
I'll get a list of post where tag is A, then I'll filter it with published: true.

query ($page: Int) {
  category {
    title
    belongsTo(perPage: 10, page: $page) @paginate {
      pageInfo {
        totalPages
        currentPage
      }
      edges {
        node {
          ... on Post {
            id
            title
            path
          }
        }
      }
    }
  }
}

when I filter it use this

query Tag ($id: ID!, $page: Int) {
  tag (id: $id) {
    title
    belongsTo (perPage: 2, page: $page, sortBy: "date", filter: { published: {eq: true} }) @paginate {
        totalCount
        pageInfo {
            totalPages
            currentPage            
        }
        edges {
            node {
                ...on Post {
                    title
                    path
                    date (format: "D MMMM YYYY")
                    timeToRead
                    description
                    content
                }
            }
        }
    }
  }
}

I get Error in terminal Field "published" is not defined by type BelongsToFilterInput
how can I filter and solve it?

Collapse
 
eclecticcoding profile image
Chuck

So, I added the published feature to my blog site. You will need to add the following to the gridsome.server.js file. It will add the filter, but will ignore the published field in your development server:

module.exports = function(api) {
  api.loadSource(store => {
    if (process.env.NODE_ENV === 'production') {
      const posts = store.getContentType('Post')

      posts.data().forEach(node => {
        if (node.published !== true) {
          posts.removeNode(node.id)
        }
      })
    }
  })
}
Collapse
 
hizbe profile image
Muhammad Hizbullah

oke solved, thank's.

Thread Thread
 
eclecticcoding profile image
Chuck

Great I am glad this helped.