# GraphQL variables not working with arrays

**URL:** <https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557>\
**Category:** CMS Development\
**Created:** [August 15, 2024, 2:18pm UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557 "2024-08-15T14:18:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RDuthie](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@RDuthie](https://community.hubspot.com/u/RDuthie)\
**Post date:** [August 15, 2024, 2:18pm UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/1 "2024-08-15T14:18:51Z")

</div>

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:

```lia-code-sample
# $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
 }
 }
 }
}

```

---

<div class="post-metadata">

**Author:** ![KhushbooP11](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/khushboop11/32/8252_2.png) [@KhushbooP11](https://community.hubspot.com/u/KhushbooP11)\
**Post date:** [August 15, 2024, 3:56pm UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/2 "2024-08-15T15:56:46Z")

</div>

Hi @RDuthie ,  
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.  
query GetPosts {  
posts(slugs: “{{ slug\_string }}”) {  
title  
slug  
}  
}  
4. Make sure to test this setup to confirm that GraphQL correctly interprets the slug list.

If you need more help, [let’s talk!  
 ](https://calendly.com/khushboo-pokhriyal/30min?month=2024-08)

Khushboo Pokhriyal

Growth & Operations

GroRapid Labs

[LinkedIn |](https://www.linkedin.com/in/khushboopokhriyal)9315044754 | [Email |](mailto:khushboo.pokhriyal@grorapid.com)[Website](https://www.grorapidlabs.com/)

---

<div class="post-metadata">

**Author:** ![RDuthie](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@RDuthie](https://community.hubspot.com/u/RDuthie)\
**Post date:** [August 16, 2024, 12:32pm UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/3 "2024-08-16T12:32:29Z")

</div>

Thanks for replying.  
This doesn’t seem to work at all. I think there’s an issue with HUBL interpreting arrays as variables in .graphql files.  
This of course works perfectly fine if I directly pass an array to the filter, but doesn’t work if its passed from a parameter in the graphQL query.

 ![RDuthie_0-1723811644993.png](https://d2qpr2jzcazej7.cloudfront.net/original/1X/9c7486fa87c4fc07c270f3918ff91436c2a2dd84.png)

---

<div class="post-metadata">

**Author:** ![phlp](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/phlp/32/23809_2.png) [@phlp](https://community.hubspot.com/u/phlp)\
**Post date:** [February 10, 2025, 9:04am UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/4 "2025-02-10T09:04:37Z")

</div>

@RDuthie I have the same problem. Did you find a solution?

I tried every combination, all the escaping-filters, … I found no way to get the array of tags as a variable in my query. I’m completly lost

---

<div class="post-metadata">

**Author:** ![phlp](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/phlp/32/23809_2.png) [@phlp](https://community.hubspot.com/u/phlp)\
**Post date:** [February 10, 2025, 11:38am UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/5 "2025-02-10T11:38:39Z")

</div>

Here is my current solution.

It’s ugly and stupid, but it works

```lia-code-sample
# label: "Blog Post Tag Filter"
# $blog_id: "{{ blog.id }}"

# $tag0: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[0] || [] }}
# $tag1: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[1] || [] }}
# $tag2: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[2] || [] }}
# $tag3: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[3] || [] }}
# $tag4: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[4] || [] }}
# $tag5: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[5] || [] }}
# $tag6: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[6] || [] }}
# $tag7: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[7] || [] }}
# $tag8: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[8] || [] }}
# $tag9: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))[9] || [] }}

query getPostByTagFilter($blog_id: String!, $tag0: String, $tag1: String, $tag2: String, $tag3: String, $tag4: String, $tag5: String, $tag6: String, $tag7: String, $tag8: String, $tag9: String) {
 BLOG {
 blogPosts: post_collection(
 filter: {
 content_group_id__eq: $blog_id,
 state__eq: "PUBLISHED",
 post_tag_slug__in: [$tag0, $tag1, $tag2, $tag3, $tag4, $tag5, $tag6, $tag7, $tag8, $tag9]
 },
 orderBy: publish_date__desc
 ) {
 items {
 tag_ids
 blog_tags {
 name
 id
 }
 name
 post_summary
 url
 featured_image
 featured_image_alt_text,
 publish_date
 state
 widgets
 }
 offset
 limit
 total
 }
 }
}

```

If 10 Filters by tag aren’t enough, just add more. They are all optional

---

<div class="post-metadata">

**Author:** ![phlp](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/phlp/32/23809_2.png) [@phlp](https://community.hubspot.com/u/phlp)\
**Post date:** [February 11, 2025, 11:49am UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/6 "2025-02-11T11:49:32Z")

</div>

And today I found a better solution:

```lia-code-sample
#$filter_tag: {{ (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&'))|length > 0 ? { "state __eq": "PUBLISHED", "content_group_id__ eq": blog.id, "post_tag_slug__in": (request.query|split('&')|select('containing', 'tag' )|join('&')|replace('tag=', '')|split('&')) }|tojson : { "state__eq": "PUBLISHED", "content_group_id__eq": blog.id }|tojson }}

query getPostByFirstFilter($offset: Int!, $filter_tag: blog_post_filter) {
	BLOG {
		blogPostsByTag: post_collection(
			filter: $filter_tag,
			limit: 6,
			offset: $offset,
			orderBy: publish_date__desc
		) {
		items {
			blog_tags {
				name
			}
			name
			post_summary
			url
			featured_image
			featured_image_alt_text,
			publish_date
			state
			widgets
		}
		offset
		limit
		total
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![RDuthie](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@RDuthie](https://community.hubspot.com/u/RDuthie)\
**Post date:** [February 13, 2025, 7:23am UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/7 "2025-02-13T07:23:01Z")

</div>

Thank you I’ll give this a go and see how well it works.

---

<div class="post-metadata">

**Author:** ![JEdwards71](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@JEdwards71](https://community.hubspot.com/u/JEdwards71)\
**Post date:** [April 2, 2025, 8:52am UTC](https://community.hubspot.com/t/graphql-variables-not-working-with-arrays/114557/8 "2025-04-02T08:52:52Z")

</div>

It’s pretty strict about how variables are structured, and in some cases, array inputs just don’t behave as expected—especially when passed in as variables rather than inline. One thing that helps is double-checking the expected input type in the schema and making sure the array is exactly in that format, both in shape and in how it’s passed. Sometimes wrapping or unwrapping it slightly can make the difference.
