Skip to content

Get Attribute

About

The getAttribute query retrieves a single attribute by ID with support for nested options, translations, and detailed configuration metadata. This query is essential for:

  • Building product filter interfaces with attribute options
  • Displaying attribute details in admin/management interfaces
  • Creating product configuration forms
  • Fetching attribute properties and validation rules
  • Building faceted navigation systems with swatch support

The query supports nested pagination for options and translations, making it flexible for various UI requirements.

Arguments

ArgumentTypeRequiredDescription
idString!✅ YesAttribute ID in format /api/shop/attributes/{id} or numeric ID

Supported ID Formats:

graphql
# Format 1: Full URI
query { attribute(id: "/api/shop/attributes/23") { id } }

# Format 2: Numeric ID
query { attribute(id: "23") { id } }

Possible Returns

FieldTypeDescription
idString!Unique attribute identifier in IRI format /api/shop/attributes/{id}
codeString!Unique code identifier (e.g., "color", "size", "brand")
nameString!Display name of the attribute
typeString!Attribute type (text, select, date, checkbox, textarea, etc.)
sortOrderInt!Display order for sorting
isFilterableBoolean!Can be used for product filtering
isSearchableBoolean!Can be used in product search
isConfigurableBoolean!Can be configured for products
isVisibleOnFrontBoolean!Visible to frontend customers
isRequiredBoolean!Required for product assignment
defaultValueStringDefault value (nullable)
createdAtDateTime!Creation timestamp (ISO 8601)
updatedAtDateTime!Last update timestamp (ISO 8601)
optionsConnectionAttribute options with pagination support

Attribute Fields

FieldTypeDescription
idString!Unique identifier in format /api/shop/attributes/{id}
codeString!Unique code identifier for attribute
nameString!Display name of the attribute
typeString!Attribute type (text, select, date, etc.)
sortOrderInt!Display sort order
isFilterableBoolean!Usable for product filtering
isSearchableBoolean!Usable for search
isConfigurableBoolean!Can be configured for products
isVisibleOnFrontBoolean!Visible on storefront
isRequiredBoolean!Required for products
defaultValueStringDefault value if any
createdAtString!Creation date
updatedAtString!Last update date
optionsConnectionNested attribute options with pagination

Common Use Cases

Get Attribute for Filter UI

graphql
query GetAttributeFilter($id: String!) {
  attribute(id: $id) {
    id
    code
    name
    isFilterable
    options(first: 100) {
      edges {
        node {
          id
          adminName
          translation {
            label
          }
        }
      }
    }
  }
}

Get Attribute with Option Swatches

graphql
query GetColorAttribute($id: String!) {
  attribute(id: $id) {
    id
    code
    name
    type
    options(first: 50) {
      edges {
        node {
          id
          adminName
          swatchValue
          translation {
            label
          }
        }
      }
    }
  }
}

Build Product Configuration Form

graphql
query GetAttributeForForm($id: String!) {
  attribute(id: $id) {
    id
    code
    name
    type
    isRequired
    defaultValue
    options(first: 100) {
      edges {
        node {
          id
          adminName
          sortOrder
          translation {
            label
          }
        }
      }
    }
  }
}

Get Multi-language Attribute

graphql
query GetMultiLanguageAttribute($id: String!) {
  attribute(id: $id) {
    id
    code
    name
    options(first: 20) {
      edges {
        node {
          id
          adminName
          translations(first: 10) {
            edges {
              node {
                locale
                label
              }
            }
          }
        }
      }
    }
  }
}

Error Handling

Missing ID Parameter

json
{
  "errors": [
    {
      "message": "Field \"attribute\" argument \"id\" of type \"String!\" is required but not provided."
    }
  ]
}

Attribute Not Found

json
{
  "data": {
    "attribute": null
  }
}

Invalid ID Format

json
{
  "data": {
    "attribute": null
  }
}

Best Practices

  1. Use Variables - Always use GraphQL variables for dynamic IDs
  2. Request Specific Fields - Only fetch fields your UI needs
  3. Handle Pagination - Use hasNextPage and endCursor for nested options
  4. Cache Results - Attributes rarely change, implement caching
  5. Limit Option Requests - Start with reasonable limits (20-50) then load more on demand

Released under the MIT License.