# Mustache template with node-red-contrib-graphql

**URL:** https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726
**Category:** General
**Created:** [9 November 2023 03:13 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726 "2023-11-09T03:13:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![quarfie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quarfie/32/39697_2.png) [@quarfie](https://discourse.nodered.org/u/quarfie)
#### Post date: [9 November 2023 03:13 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726/1 "2023-11-09T03:13:44Z")

</div>

I used a change node to set msg.payload.inventory\_item\_id to 42112828440781

Next I use the graphql node (from node-red-contrib-graphql) to run the following GraphQL query:

```auto
{
  inventoryItem(id: "gid://shopify/InventoryItem/{{inventory_item_id}}") {
    variant {
      sku
      title
      product {
        id
        title
      }
    }
  }
}

```

I set the node to use moustache templating. However, the {{inventory\_item\_id}} is being replaced with nothing. This results in the following error: "Invalid global id 'gid://shopify/InventoryItem/'"

The docs for node-red-contrib-graphql state:

> If you select mustache, your template will be processed by Mustache with the message's payload as an argument. I.e.  
> `submitted_template = mustache("template in text area", msg.payload)`

Am I missing something?

---

<div class="post-metadata">

### Author: ![quarfie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quarfie/32/39697_2.png) [@quarfie](https://discourse.nodered.org/u/quarfie)
#### Post date: [9 November 2023 03:26 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726/2 "2023-11-09T03:26:07Z")

</div>

Aha! I had to reference it as `{{payload.inventory_item_id}}`

Did I misunderstand the docs or are they wrong?

> [@](#):
>
> If you select mustache, your template will be processed by Mustache with the message's payload as an argument. I.e.  
> `submitted_template = mustache("template in text area", msg.payload)`

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [9 November 2023 03:27 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726/3 "2023-11-09T03:27:23Z")

</div>

I have not used that particular contrib node, but if I recall correctly, the context of the core `template` node is the full `msg` object, not just the playload...

Have you tried this?

```
"gid://shopify/InventoryItem/{{payload.inventory_item_id}}" 

```

If that does work, then I guess the documentation just needs to be updated.  
If not, then I have no idea ;\*)

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [9 November 2023 03:28 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726/4 "2023-11-09T03:28:29Z")

</div>

> [@quarfie](#):
>
> Aha! I had to reference it as `{{payload.inventory_item_id}}`

Jinx! nice catch

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [8 January 2024 03:29 UTC](https://discourse.nodered.org/t/mustache-template-with-node-red-contrib-graphql/82726/5 "2024-01-08T03:29:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
