Skip to content

fix: Correct GraphQL mutation format for Transactions.Delete()#17

Merged
eshaffer321 merged 3 commits intomainfrom
fix/transaction-delete-bad-request
Oct 26, 2025
Merged

fix: Correct GraphQL mutation format for Transactions.Delete()#17
eshaffer321 merged 3 commits intomainfrom
fix/transaction-delete-bad-request

Conversation

@eshaffer321
Copy link
Copy Markdown
Owner

Summary

Fixes the Transactions.Delete() method which was returning BAD_REQUEST errors due to incorrect GraphQL mutation format. The mutation now matches the Python client and Monarch API expectations.

Root Cause

The Go client was using:

mutation DeleteTransaction($id: UUID!) {
  deleteTransaction(id: $id) { ... }
}

With variables: {"id": "txn-123"}

But the Monarch API expects (matching Python client):

mutation Common_DeleteTransactionMutation($input: DeleteTransactionMutationInput!) {
  deleteTransaction(input: $input) { ... }
}

With variables: {"input": {"transactionId": "txn-123"}}

Changes

  • ✅ Fixed GraphQL mutation in internal/graphql/queries/transactions/delete.graphql
  • ✅ Updated pkg/monarch/transactions.go to use input wrapper format
  • ✅ Added comprehensive test coverage (TestTransactionService_Delete, TestTransactionService_Delete_Error)
  • ✅ Created examples/transaction_deletion.go with:
    • Delete method usage and error handling
    • hideFromReports workaround for bank-imported transactions
    • Real-world example: Walmart multi-delivery consolidation
  • ✅ Updated CHANGELOG.md with fix details
  • ✅ Updated go.mod/go.sum dependencies

Test Results

All tests pass ✅ (54 tests, 1 skipped):

PASS
ok      github.com/eshaffer321/monarchmoney-go/pkg/monarch    0.207s

Breaking Changes

None - this is a bug fix that makes the existing API work as intended.

Additional Notes

The error handling already captures both Code and Message from the API response, so detailed error messages will now be visible when deletion fails (e.g., for bank-imported transactions that cannot be deleted).

For transactions that cannot be deleted, users can use the HideFromReports field as an alternative (documented in the new example file).

Related Issues

Resolves issue where bank-imported transactions couldn't be deleted in Walmart multi-delivery consolidation tool.

The Delete method was using an incorrect GraphQL mutation format that
caused BAD_REQUEST errors when attempting to delete transactions.

Changes:
- Updated delete.graphql mutation to use DeleteTransactionMutationInput
  with input wrapper (matching Python client and Monarch API format)
- Changed variables from {"id": "..."} to {"input": {"transactionId": "..."}}
- Added comprehensive test coverage for Delete method (success & error cases)
- Added examples/transaction_deletion.go with workarounds and real-world
  use cases (including Walmart multi-delivery consolidation)
- Updated CHANGELOG.md with fix details and hideFromReports alternative

Before: deleteTransaction(id: $id) with {"id": "txn-123"}
After: deleteTransaction(input: $input) with {"input": {"transactionId": "txn-123"}}

Tests: All 54 tests pass
Fixes: BAD_REQUEST error when deleting transactions
- Move examples/transaction_deletion.go to examples/transaction_deletion/main.go to avoid main() conflicts
- Fix NewClient() usage to match correct API (returns client and error)
- Resolves lint and test failures in CI
Line 35 was redeclaring err instead of reusing the existing variable from line 14
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.55%. Comparing base (2e51ad7) to head (6bec196).
⚠️ Report is 1 commits behind head on main.

❌ Your project status has failed because the head coverage (44.55%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
+ Coverage   43.18%   44.55%   +1.36%     
==========================================
  Files          15       15              
  Lines        2239     1663     -576     
==========================================
- Hits          967      741     -226     
+ Misses       1198      846     -352     
- Partials       74       76       +2     
Flag Coverage Δ
unittests 44.55% <100.00%> (+1.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/monarch/transactions.go 72.31% <100.00%> (+4.23%) ⬆️

... and 14 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e51ad7...6bec196. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eshaffer321 eshaffer321 merged commit b269e9a into main Oct 26, 2025
12 of 13 checks passed
@eshaffer321 eshaffer321 deleted the fix/transaction-delete-bad-request branch October 26, 2025 03:07
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.

1 participant