How to use filter_query in this library?
daliborristic883 opened this issue · 9 comments
About this issue
This is how to use on web app.
const fetchedStories = await Storyblok.get(`cdn/stories/`, {
starts_with: slug,
filter_query: {
title: {
like: `*${query}*`,
},
},
});
but this library doesn't provides to use Map<Key: Any> for filter_query
.
Please help me to fetch stories with filter_query
as above js codes.
Thank you.
Details
- [ ] Used library version: 1.2.1
Checklist
- Searched for similar issues
- Checked out the sample application
- Read the README
- Checked out the CHANGELOG
- Read the FAQ
- Checked out the MIGRATION GUIDE
The library exposes the filter query here:
So you can pass in the filter query as string which is then sent to the API.
Maybe you can explain a bit more on the need for the API, so we can look into exposing additional helpers to construct the filter qery?
@mikepenz
When I call api directly, I can get stories.
https://api.storyblok.com/v1/cdn/stories?token=******&filter_query%5Btitle%5D%5Blike%5D=*test*&resolve_relations=collection.category&starts_with=videos/&version=published
how can I pass filter_query
as string?
filter_query%5Btitle%5D%5Blike%5D=test
Github link what you shared doesn't make sense for me.
How can I pass this filter as string?
filter_query: {
title: {
like: `*test*`,
},
}
@daliborristic883 I understand now. thank you.
Your filterquery is sent as filter_query[title][like]=*test*
via the query parameters.
I'll look into adjusting the API to support such query parameters, which is currently not handled as needed.
Ok thanks.
Before I release an update with the change. Can you please have a look at the PR and see if it also matches your needs:
#71 ?
@mikepenz
Sorry I can't make sure how to use filter_query
.
can you please show me how to use it?
Thank you.
So with the new API (after it's released) you can pass the different arrays like:
storyblok.fetchStories(filterQuery = mapOf("[title][like]" to "*test*"))
Do you have more complicated filter setups which would be worth trying prior?
Releasing it as 1.3.0-rc01 so you can more easily try it out, and we can iterate on it depending on the needs