Skip to content

Logging payload via custom_request_replace #3027

Answered by robjtede
lewsmith asked this question in Q&A
Discussion options

You must be logged in to vote

There's no way to read the payload when you only have a &ServiceRequest, as is the case here. That's because, at the middleware level, all payloads are streams that are yet to be read.

If you want to do this, I'd suggest logging the query within your GraphQL handler, since middleware is designed more to apply to a large range of endpoints.

Alternatively, a middleware around the specific GraphQL handler that does this separately. Using from_fn from actix-web-lab make this a breeze because you can use extractors, though you need to "re-insert" the body which is a little hacky.

Roughly (untested):

async fn log_gql_query<B>(
    query: String,
    mut req: ServiceRequest,
    next: Next<B>,
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lewsmith
Comment options

Answer selected by robjtede
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants