Skip to content

Merge OData query params at boot time instead of via middleware#2

Closed
isama92 wants to merge 1 commit intosimplesquid:mainfrom
isama92:fix/merge-odata-query-at-boot-time
Closed

Merge OData query params at boot time instead of via middleware#2
isama92 wants to merge 1 commit intosimplesquid:mainfrom
isama92:fix/merge-odata-query-at-boot-time

Conversation

@isama92
Copy link
Copy Markdown
Contributor

@isama92 isama92 commented Apr 14, 2026

Problem

The HasODataQuery trait merges OData query parameters into the PendingRequest via a request middleware registered at PipeOrder::LAST. However, Saloon's DetermineMockResponse middleware runs at normal priority (before LAST). When using Saloon::fake() with a callback that inspects $pendingRequest->query()->all() to match URLs, the OData params haven't been merged yet — so the query appears empty and mock matching fails.

Fix

Move the merge from a PipeOrder::LAST middleware to a direct $pendingRequest->query()->merge() call during boot. Boot runs during PendingRequest construction (before the middleware pipeline), so the params are available by the time DetermineMockResponse resolves the mock.

All existing functionality is preserved:

  • Connector-level #[UsesODataVersion] resolution
  • #[DefaultODataQuery] attributes
  • Constructor-time filter setup via $this->odataQuery()->filter(...)

All 120 existing tests pass.

The `HasODataQuery` trait previously merged OData query parameters into
the PendingRequest via a request middleware registered at `PipeOrder::LAST`.
However, Saloon's `DetermineMockResponse` middleware runs at normal
priority (before LAST), so when using `Saloon::fake()` with callbacks
that inspect `$pendingRequest->query()->all()` for URL matching, the
OData params haven't been merged yet and the query appears empty.

This moves the merge to happen directly during boot, which runs during
PendingRequest construction before any middleware pipeline execution.
All existing functionality (connector-level version resolution,
`#[DefaultODataQuery]` attributes, constructor-time filter setup) is
preserved since it all happens before or during boot.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mdpoulter mdpoulter closed this in 045e811 Apr 14, 2026
@mdpoulter
Copy link
Copy Markdown
Member

Thanks for flagging this @isama92! Merged the fix into main with an additional test for same-key overrides. Released in v0.1.1.

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