Skip to content

ING-139 feat(payments): Filter payments by currency#5517

Merged
mariohd merged 2 commits into
mainfrom
currency-payments-resolver
May 19, 2026
Merged

ING-139 feat(payments): Filter payments by currency#5517
mariohd merged 2 commits into
mainfrom
currency-payments-resolver

Conversation

@mariohd
Copy link
Copy Markdown
Contributor

@mariohd mariohd commented May 15, 2026

The payments listing in the front-end needs to be filterable by currency, but the GraphQL payments query and the underlying PaymentsQuery had no such filter. This PR adds it at both layers.

The change is mechanical: a currency argument on Resolvers::PaymentsResolver, a currency entry in PaymentsQuery::Filters, and a filter_by_currency helper that scopes the query to where(amount_currency: filters.currency). The resolver's resolve method defaults currency: to nil so existing callers that don't pass it continue to work unchanged. The generated schema.graphql and schema.json are regenerated to reflect the new argument.

Before and after

Before After
Filter payments by currency through GraphQL No payments(currency: "USD") { ... }
PaymentsQuery::Filters shape [:invoice_id, :external_customer_id] [:invoice_id, :external_customer_id, :currency]
Existing filters (invoice, external customer, search) Worked Unchanged

Test plan

  • bundle exec rspec spec/queries/payments_query_spec.rb
  • bundle exec rspec spec/graphql/resolvers/payments_resolver_spec.rb
  • Manual via GraphiQL: payments(currency: "USD") { collection { id } } returns only payments whose amount_currency = "USD".

Migration

None. The new argument is optional and not gated — existing callers see no change.

Follow-up worth opening

app/contracts/queries/payments_query_filters_contract.rb lists invoice_id and external_customer_id but not currency. Adding optional(:currency).maybe(:string) would reject malformed currency strings at the validation layer instead of silently returning empty results. Skipped here to keep the PR focused.

@mariohd mariohd changed the title feat(payments): Filter payments by currency ING-139 feat(payments): Filter payments by currency May 18, 2026
Comment thread app/graphql/resolvers/payments_resolver.rb Outdated
mariohd added 2 commits May 19, 2026 08:42
The payments GraphQL query exposed filters by invoice, external
customer, and search term, but not by currency. The frontend payments
listing needs to narrow results by currency, so the resolver and the
underlying query both need the new filter.

Add a `currency` argument to `Resolvers::PaymentsResolver` and a
matching `:currency` filter to `PaymentsQuery`. When set, the filter
scopes the query to `where(amount_currency: filters.currency)`; when
absent, it is a no-op and existing behavior is preserved. The
generated `schema.graphql` and `schema.json` are regenerated to expose
the new argument.

Cover the new filter at both layers: a `PaymentsQuery` context
creating a USD payment alongside the existing EUR set and asserting
only the USD row comes back (plus a complementary "no matches"
context for a currency with no payments), and a `PaymentsResolver`
context exercising the GraphQL query with `currency: "USD"`.
## Context

The `payments` GraphQL query exposes a `currency` filter that landed
on this branch as a free-form `String`. Currencies in Lago come from
the fixed list in `Currencies::ACCEPTED_CURRENCIES`, and the rest of
the schema already surfaces them through `Types::CurrencyEnum`.
Leaving the filter as a string let callers pass any value, deferring
validation to the database lookup and producing an empty collection
instead of a clear GraphQL error.

## Description

Switch the `currency` argument on `Resolvers::PaymentsResolver` from
`String` to `Types::CurrencyEnum`, regenerate `schema.graphql` and
`schema.json` to reflect the new contract, and update the resolver
spec so the query variable declaration matches the new type. The
resolver internals stay the same: `PaymentsQuery` still receives a
currency code string from GraphQL, and existing valid queries
(`"USD"`, `"EUR"`, …) continue to work. The only user-visible change
is that unknown currencies are now rejected by the GraphQL layer
before the resolver runs.
@mariohd mariohd force-pushed the currency-payments-resolver branch from 1d7cfb2 to 29b2893 Compare May 19, 2026 11:42
@mariohd mariohd merged commit d4991ec into main May 19, 2026
13 checks passed
@mariohd mariohd deleted the currency-payments-resolver branch May 19, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants