Hi. I'm having an issue when trying to pass an array of slugs into an GraphQL query. For context I've got a array of blog post slugs I want GraphQL to filter by. Array would look something like ['value-1', 'value-2'] etc..
I tried everything, but for some reason HUBL doesn't translate the array into the filter.
The array is a variable defined in HUBL on top of my .graphql file.
Any help would be appreciated. Thanks
Example of code:
# $post_tag_slug: ['seo-paid-media'] //This array would ideally be split from an string received from query params.
query resourceCenterPosts($post_tag_slug: [String]) {
BLOG {
post_collection(limit: 9, filter: {post_tag_slug__in: $post_tag_slug}) {
items {
id
name
}
}
}
}
If you're having trouble passing an array of slugs into a GraphQL query in HubL, here's a simple approach.
1. When you define an array of slugs in HubL and pass it to your GraphQL query, it might not be correctly translated into the format GraphQL expects.
2. Before passing the array to GraphQL, convert it into a string that GraphQL can parse. You can use HubL to join the array into a comma-separated string.
{% set slug_list = ['value-1', 'value-2'] %} {% set slug_string = slug_list|join(',') %}
3. Use the string in your GraphQL query instead of the array.