Skip to content

Get Single Currency

About

The currency query retrieves a single currency by ID with support for detailed field access. This query is essential for:

  • Fetching specific currency details for price formatting
  • Retrieving currency symbol and position for display
  • Getting formatting details (decimal places, separators)
  • Validating currency existence before operations
  • Building currency detail pages
  • Configuring currency-specific price formatting

The query allows you to fetch a specific currency with all its properties.

Arguments

ArgumentTypeRequiredDescription
idID!YesThe unique identifier of the currency. Can be either numeric ID or IRI format (/api/shop/currencies/{id}).

Possible Returns

FieldTypeDescription
currencyCurrencyThe requested currency object, or null if not found.

Currency Fields

FieldTypeDescription
idString!Unique identifier in format /api/shop/currencies/{id}
_idInt!Numeric identifier for the currency
codeString!ISO 4217 currency code (e.g., "USD", "EUR", "INR")
nameString!Display name of the currency (e.g., "US Dollar", "Euro")
symbolString!Currency symbol (e.g., "$", "€", "₹")
decimalStringNumber of decimal places for the currency (e.g., "2")
groupSeparatorStringThousands group separator character (e.g., ",")
decimalSeparatorStringDecimal separator character (e.g., ".")
currencyPositionStringPosition of currency symbol relative to the amount: "left", "left_with_space", "right", "right_with_space", or null (use system default)

Common Use Cases

Get Currency Details by IRI ID

graphql
query GetCurrencyByIRI($id: ID!) {
  currency(id: $id) {
    id
    _id
    code
    name
    symbol
    currencyPosition
  }
}

Variables:

json
{
  "id": "/api/shop/currencies/1"
}

Get Currency Formatting Details

graphql
query GetCurrencyFormatting($id: ID!) {
  currency(id: $id) {
    code
    symbol
    decimal
    groupSeparator
    decimalSeparator
    currencyPosition
  }
}

Get Currency Symbol and Position

graphql
query GetCurrencyDisplay($id: ID!) {
  currency(id: $id) {
    code
    name
    symbol
    currencyPosition
  }
}

Validate Currency Existence

graphql
query ValidateCurrency($id: ID!) {
  currency(id: $id) {
    id
    code
  }
}

Error Handling

Currency Not Found

json
{
  "data": {
    "currency": null
  }
}

Missing Required ID Parameter

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

Invalid ID Format

json
{
  "errors": [
    {
      "message": "Invalid ID format. Expected IRI format like \"/api/shop/currencies/1\" or numeric ID"
    }
  ]
}

Best Practices

  1. Always Provide ID - The ID parameter is required for this query
  2. Check for Null - Handle the case when currency is not found (returns null)
  3. Use Formatting Fields - Always use decimal, groupSeparator, decimalSeparator, and currencyPosition for correct price display
  4. Cache Results - Currencies change infrequently; implement caching
  5. Validate Before Using - Verify currency exists before using in operations
  6. Use Variables - Use GraphQL variables for dynamic currency queries
  7. Request Needed Fields - Only request fields you'll actually use
  8. Display Symbol Correctly - Use currencyPosition to place symbol on the correct side

Released under the MIT License.