Skip to content

Get Attribute Options

About

The getAttributeOptions query retrieves attribute options (values) for a specific attribute. This query is essential for:

  • Building product filter and search interfaces
  • Displaying color swatches and size options
  • Creating configurable product selectors
  • Building faceted navigation systems
  • Multi-language product attribute support

The query supports cursor-based pagination and optional translation fetching, making it ideal for displaying product attribute values in various UI contexts.

Arguments

ArgumentTypeRequiredDescription
firstInt❌ NoNumber of options to retrieve from the start (forward pagination). Max: 100.
afterString❌ NoCursor to start after for forward pagination.
lastInt❌ NoNumber of options to retrieve from the end (backward pagination). Max: 100.
beforeString❌ NoCursor to start before for backward pagination.

Possible Returns

FieldTypeDescription
edges[AttributeOptionEdge!]!Array of attribute option edges containing options and cursors.
edges.nodeAttributeOption!The actual attribute option object with id, name, swatch, and translations.
edges.cursorString!Pagination cursor for this option. Use with after or before arguments.
pageInfoPageInfo!Pagination metadata object.
pageInfo.hasNextPageBoolean!Whether more options exist after the current page.
pageInfo.hasPreviousPageBoolean!Whether options exist before the current page.
pageInfo.startCursorStringCursor of the first option on the current page.
pageInfo.endCursorStringCursor of the last option on the current page.

AttributeOption Fields

FieldTypeDescription
idString!Unique option identifier in format /api/shop/attribute-options/{id}.
_idInt!Numeric ID of the option.
adminNameString!Admin-facing name (e.g., "Red", "Large", "Cotton").
sortOrderInt!Display order of the option (0, 1, 2, ...).
swatchValueStringSwatch value - hex color code for color attributes or text representation.
swatchValueUrlStringURL to swatch image file for image-based swatches.
translationOptionTranslationSingle translation for the default/current locale.
translations[OptionTranslation!]Collection of all translations for multi-language support.

Translation Fields

FieldTypeDescription
idString!Translation ID in format /api/attribute_option_translations/{id}.
_idInt!Numeric translation ID.
localeString!Language locale code (e.g., "en", "ar", "fr", "de").
labelString!Translated label for the option in the specified locale.

Common Use Cases

Display Color Picker in Product Page

graphql
query ColorPicker {
  attributeOptions(first: 50) {
    edges {
      node {
        adminName
        swatchValue
        translation { label }
      }
    }
  }
}

Build Size Selector with Sorting

graphql
query SizeSelector {
  attributeOptions(first: 100) {
    edges {
      node {
        adminName
        sortOrder
        translation { label }
      }
    }
  }
}

Multi-language Attribute Support

graphql
query MultiLanguageOptions {
  attributeOptions(first: 20) {
    edges {
      node {
        adminName
        translations(first: 10) {
          edges {
            node {
              locale
              label
            }
          }
        }
      }
    }
  }
}

Error Handling

Missing Attribute ID

json
{
  "errors": [
    {
      "message": "Field \"attributeOptions\" argument \"attributeId\" of type \"Int!\" is required but not provided."
    }
  ]
}

Non-existent Attribute

json
{
  "data": {
    "attributeOptions": {
      "edges": [],
      "pageInfo": {
        "hasNextPage": false,
        "endCursor": null
      }
    }
  }
}

Invalid Pagination Cursor

json
{
  "errors": [
    {
      "message": "Invalid cursor provided"
    }
  ]
}

Best Practices

  1. Use Appropriate Pagination Size - Request 10-50 options per page
  2. Cache Results - Attribute options change infrequently, cache them
  3. Request Translations When Needed - Only fetch translations if supporting multiple languages
  4. Optimize Field Selection - Request only fields your UI actually needs

Released under the MIT License.