Filtering in getByType method

Hello, i am trying to use API method getByType from prismicio/client, everything works fine, except for filtering. My main goal is getting all pages with type 'blog_post' filtered by 'categories' field. It does not work (not only this filter, any filter that i have tried, even from documentation examples - I have provided a code example of such case). Also, code editor shows an error (attached below). Are filters not supported yet for this method or am I applying them incorrectly?

Thank you in advance!

Code:

      const posts = await client.getByType('blog_post', {
        pageSize: 50,
        page: Number(params.uid),
        orderings: [
          {
            field: 'my.blog_post.date',
            direction: 'desc'
          }
        ],
        filters: [
          prismic.filter.dateYear('document.last_publication_date', 2020)
        ]
      })

Hello @gerda.zykute

Welcome to the Prismic community, and thanks for reaching out to us.

I believe you need to add a document type in the filters array. It should be like this:

 filters: [
     prismic.filter.dateYear('document.last_publication_date', 2020)
     prismic.filter.at('document.type', 'blog-post')
  ]

Thanks,
Priyanka

Hello @Priyanka
I have found that it wasn't working, because i was using the wrong client and wrong version of it. So it recognises filters now. I have one more question though. I am trying to access a field which is an array like this:

      filters: [
        prismic.filter.at('document.type', 'blog_post'),
        prismic.filter.at('my.blog_post.categories', ['news'])
      ]

I get an error: Error: [function at(..)] unexpected field 'my.blog_post.categories' on line:1 col:6 in query
There certainly is such field. Also, it recognises all other fields besides this one, probably because of its type. Is there any way to handle fields that are arrays? My use case is to filter by category, e.g. get all blog posts with category 'News'

Hello @gerda.zykute

To use the at filters, pass the ID of the linked document.

For example:

const document = await client.get({
  filters: prismic.filter.at(
    'my.example_custom_type.example_content_relationship',
    'YesUgRIAACEA-UZD'
  ),
})

I hope it is clear to you.

Thanks,
Priyanka

Hello @Priyanka
the at filters work perfectly fine without ID for all fields, except for one (categories), which returns an array of objects. Also, I am trying to get all documents of a specific type (blog_post), which match the filters, so I can't really pass linked document id, as i need many documents.

Could you tell me the name of your repo? You can send me a private message.

Hi @gerda.zykute, did you ever resolve this issue?

Hey, @nick-east no, I didn't get a response after sending repo name and unfortunately, we've decided not to implement the feature that we wanted, because nothing seemed to work