Attributes

Store your own custom data against Jungle objects

Attributes let you store your own custom key/value data against most Jungle objects. They're useful for carrying information from your own systems that Jungle doesn't model directly — a loyalty tier on a customer, a handling note on a product, an approval flag on an order, and so on.

An attribute is a pair of an id (the key) and a value, with an optional human-friendly name.

Setting attributes

Set one or more attributes on an object with the attributesSet mutation. It takes the target object and a list of attributes:

mutation {
  attributesSet(
    input: {
      object: { id: "1234", typename: "Product" }
      attributes: [
        { id: "brand", name: "Brand", value: "Acme" }
        { id: "warranty.months", value: "24" }
      ]
    }
  ) {
    ok
  }
}

Attribute IDs may contain letters, numbers, and the -, _, and . characters (3–64 characters). The . is handy for namespacing your own keys, for example warranty.months or my-system.ref.

Reading attributes

Objects that support attributes expose an attributes field listing the attributes set on them, each with its id, name, and value:

query {
  object(input: { id: "1234", typename: "Product" }) {
    ... on Product {
      id
      attributes {
        id
        name
        value
      }
    }
  }
}

Reading a single value

When you only need one attribute's value, use attributeValue, which returns the value as a string:

query {
  object(input: { id: "1234", typename: "Product" }) {
    ... on Product {
      id
      brand: attributeValue(input: { attributeId: "brand" })
    }
  }
}

Using a GraphQL alias (here brand:) lets you surface attributes as your own named properties in the response.

Removing an attribute

To remove an attribute, set its value to null in attributesSet. The attribute is removed rather than stored with an empty value.

Can't find what you're looking for? Contact us