Skip to content

Add response middlewares to the network queryers - #47

Open
cideM wants to merge 1 commit into
nautilus:masterfrom
amboss-mededu:feat/response-middlewares
Open

cideM wants to merge 1 commit into
nautilus:masterfrom
amboss-mededu:feat/response-middlewares

Conversation

@cideM

@cideM cideM commented Sep 17, 2026

Copy link
Copy Markdown

Problem

NetworkMiddleware lets callers see every outgoing request, there's no equivalent for inspecting the response. We ran into this when we were trying to implement support for extensions in our GraphQL gateway (which is based on nautilus/gateway).

More specifically, SingleRequestQueryer.Query and MultiOpQueryer.Query parse the response and then decode only data into the receiver, so everything else is dropped, including extensions.

Solution

Add a ResponseMiddleware, similar to NetworkMiddleware:

type ResponseMiddleware func(ctx context.Context, response map[string]interface{}) error

type QueryerWithResponseMiddlewares interface {
    WithResponseMiddlewares(wares []ResponseMiddleware) Queryer
}

Both network queryers implement it through WithResponseMiddlewares, mirroring WithMiddlewares. The middlewares run after the response is parsed and before data is decoded. Returning an error aborts the query with that error, like a NetworkMiddleware does on the request side.

In MultiOpQueryer the middlewares run once per bundled query, with that query's own context and its own entry of the batched response.

With no middlewares configured the queryers behave exactly as before.

Tests

queryerResponseMiddleware_test.go covers the single request queryer (JSON and multipart responses, error propagation) and the multi-op queryer (each bundled query sees its own entry and context).

Add ResponseMiddleware similar to NetworkMiddleware so callers can see
the response. SingleRequestQueryer and MultiOpQueryer parse the response
and then decode only "data" into the receiver, dropping everything else.

ResponseMiddleware sees the parsed response and the query's context,
before "data" is decoded. The entry point is WithResponseMiddlewares,
similar to WithMiddlewares.

In MultiOpQueryer the middlewares run once per bundled query, with that
query's own context and its own entry of the batched response.
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