Skip to content

Elasticsearch price range inputs are incompatible with BigIntMoneyStrategy #40

Open

Description

@amirrezabaha

Description

The Elasticsearch plugin defines its price filters using GraphQL Int:

input PriceRangeInput {
  min: Int!
  max: Int!
}

GraphQL Int is limited to signed 32-bit values, with a maximum value of 2,147,483,647.

Vendure supports BigIntMoneyStrategy for catalogs whose monetary values exceed this limit. These prices can be stored by Vendure, exposed through the Money scalar, and indexed by Elasticsearch, but they cannot be passed to priceRange or priceRangeWithTax.

PriceRangeBucket.to is also declared as Int!, so price bucket responses may have the same limitation.

Reproduction

Configure Vendure to use a whole-unit BigIntMoneyStrategy:

class WholeRialMoneyStrategy extends BigIntMoneyStrategy {
  override precision = 0;
}

const config: VendureConfig = {
  entityOptions: {
    moneyStrategy: new WholeRialMoneyStrategy(),
  },
};

Versions used:

  • @vendure/core: 3.6.3
  • @vendure-community/elasticsearch-plugin: 2.0.0
  • Elasticsearch server: 9.1.0

A product can validly have a price such as:

20,000,000,000

However, this search cannot be represented by the plugin's GraphQL schema:

query {
  search(
    input: {
      groupByProduct: true
      priceRangeWithTax: {
        min: 10000000000
        max: 20000000000
      }
    }
  ) {
    totalItems
  }
}

GraphQL rejects these values because they exceed the signed 32-bit Int range. The request therefore fails before the Elasticsearch query is executed.

Expected behavior

Elasticsearch price filters should support the same monetary range as Vendure's BigIntMoneyStrategy and Money scalar.

Suggested solution

Use Vendure's Money scalar for monetary input and bucket values:

input PriceRangeInput {
  min: Money!
  max: Money!
}

type PriceRangeBucket {
  to: Money!
  count: Int!
}

If changing PriceRangeInput would be considered a breaking schema change, an alternative would be to introduce a new money-based range input and deprecate the Int-based fields.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions