<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: GraphQL variables not working with arrays in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1130705#M42588</link>
    <description>&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Apr 2025 08:52:52 GMT</pubDate>
    <dc:creator>JEdwards71</dc:creator>
    <dc:date>2025-04-02T08:52:52Z</dc:date>
    <item>
      <title>GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1027626#M40293</link>
      <description>&lt;P&gt;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..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried everything, but for some reason HUBL doesn't translate the array into the filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The array is a variable defined in HUBL on top of my .graphql file.&lt;BR /&gt;&lt;BR /&gt;Any help would be appreciated. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;# $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
      }
    }
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 14:21:39 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1027626#M40293</guid>
      <dc:creator>RDuthie</dc:creator>
      <dc:date>2024-08-15T14:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1027707#M40297</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/401875"&gt;@RDuthie&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;If you're having trouble passing an array of slugs into a GraphQL query in HubL, here's a simple approach.&lt;BR /&gt;&lt;BR /&gt;1.&amp;nbsp;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.&lt;BR /&gt;&lt;BR /&gt;2.&amp;nbsp;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.&lt;BR /&gt;&lt;BR /&gt;{% set slug_list = ['value-1', 'value-2'] %}&lt;BR /&gt;{% set slug_string = slug_list|join(',') %}&lt;BR /&gt;&lt;BR /&gt;3.&amp;nbsp;Use the string in your GraphQL query instead of the array.&lt;BR /&gt;&lt;BR /&gt;query GetPosts {&lt;BR /&gt;posts(slugs: "{{ slug_string }}") {&lt;BR /&gt;title&lt;BR /&gt;slug&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;4. Make sure to test this setup to confirm that GraphQL correctly interprets the slug list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need more help,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://calendly.com/khushboo-pokhriyal/30min?month=2024-08" target="_blank" rel="noopener nofollow noreferrer"&gt;let's talk!&lt;BR /&gt;&lt;BR /&gt;&lt;/A&gt;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;Khushboo Pokhriyal&lt;/P&gt;&lt;P&gt;Growth &amp;amp; Operations&lt;/P&gt;&lt;P&gt;GroRapid Labs&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.linkedin.com/in/khushboopokhriyal" target="_blank" rel="noopener nofollow noreferrer"&gt;LinkedIn |&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;&lt;A href="tel:9315044754" target="_blank" rel="noopener nofollow noreferrer"&gt;9315044754 |&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;&lt;A href="mailto:khushboo.pokhriyal@grorapid.com" target="_blank" rel="noopener nofollow noreferrer"&gt;Email |&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;&lt;A href="https://www.grorapidlabs.com/" target="_blank" rel="noopener nofollow noreferrer"&gt;Website&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 Aug 2024 15:56:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1027707#M40297</guid>
      <dc:creator>KhushbooP11</dc:creator>
      <dc:date>2024-08-15T15:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1028102#M40309</link>
      <description>&lt;P&gt;Thanks for replying.&lt;BR /&gt;&lt;BR /&gt;This doesn't seem to work at all. I think there's an issue with HUBL interpreting arrays as variables in .graphql files.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RDuthie_0-1723811644993.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/124941i855BA05C6F8804B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RDuthie_0-1723811644993.png" alt="RDuthie_0-1723811644993.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 12:34:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1028102#M40309</guid>
      <dc:creator>RDuthie</dc:creator>
      <dc:date>2024-08-16T12:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1106487#M41996</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/401875"&gt;@RDuthie&lt;/a&gt;&amp;nbsp;I have the same problem. Did you find a solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 09:04:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1106487#M41996</guid>
      <dc:creator>phlp</dc:creator>
      <dc:date>2025-02-10T09:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1106578#M41998</link>
      <description>&lt;P&gt;Here is my current solution.&lt;/P&gt;
&lt;P&gt;It's ugly and stupid, but it works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;# label: "Blog Post Tag Filter"
# $blog_id: "{{ blog.id }}"


# $tag0: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[0] || [] }}
# $tag1: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[1] || [] }}
# $tag2: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[2] || [] }}
# $tag3: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[3] || [] }}
# $tag4: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[4] || [] }}
# $tag5: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[5] || [] }}
# $tag6: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[6] || [] }}
# $tag7: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[7] || [] }}
# $tag8: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[8] || [] }}
# $tag9: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))[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
    }
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If 10 Filters by tag aren't enough, just add more. They are all optional&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 11:39:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1106578#M41998</guid>
      <dc:creator>phlp</dc:creator>
      <dc:date>2025-02-10T11:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1107263#M42020</link>
      <description>&lt;P&gt;And today I found a better solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;#$filter_tag: {{ (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;'))|length &amp;gt; 0 ? { "state__eq": "PUBLISHED", "content_group_id__eq": blog.id, "post_tag_slug__in": (request.query|split('&amp;amp;')|select('containing', 'tag' )|join('&amp;amp;')|replace('tag=', '')|split('&amp;amp;')) }|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
		}
	}
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 11:50:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1107263#M42020</guid>
      <dc:creator>phlp</dc:creator>
      <dc:date>2025-02-11T11:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1108406#M42151</link>
      <description>&lt;P&gt;Thank you I'll give this a go and see how well it works.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 07:23:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1108406#M42151</guid>
      <dc:creator>RDuthie</dc:creator>
      <dc:date>2025-02-13T07:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL variables not working with arrays</title>
      <link>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1130705#M42588</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 08:52:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/GraphQL-variables-not-working-with-arrays/m-p/1130705#M42588</guid>
      <dc:creator>JEdwards71</dc:creator>
      <dc:date>2025-04-02T08:52:52Z</dc:date>
    </item>
  </channel>
</rss>

