mikepenz/storyblok-mp-SDK

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

The library exposes the filter query here:

https://github.com/mikepenz/storyblok-mp-SDK/blob/develop/storyblok-mp-sdk/src/commonMain/kotlin/com/mikepenz/storyblok/sdk/Storyblok.kt#L181

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?

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