graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Simplify adding items to the request pipeline

Open tobias-tengler opened this issue 3 years ago • 1 comments

Is your feature request related to a problem?

If I want to modify the request pipeline as a consumer and I want to hook into a specific part of the pipeline I currently have to go into the HC source and copy paste the default pipeline to make my edits - not a good DX.

The solution you'd like

An API like

.UseRequestMiddlewareBefore<TTarget, TMiddleware>()
.UseRequestMiddlewareAfter<TTarget, TMiddleware>()

would make it really easy to integrate user middleware into one of the pipelines Hot Chocolate comes with. It would also allow us to only have one default pipeline that features like caching or persisted queries extend in this way.

The challenge with this of course is that middleware is not named at the moment. I think we could use the type name as some sort of identifier and use this to be able to identify middleware in the pipeline.

I also feel like we should rename UseRequest to UseRequestMiddleware. The former is too ambiguous IMO.

The API surface of the request middleware should be something like this:

.UseDefaultRequestPipeline()
.UseXYZFeaturePipeline()
.UseRequestMiddleware<TMiddleware>() // adds to start of the pipeline
.UseRequestMiddleware(Delegate) // adds to start of the pipeline
.UseRequestMiddlewareBefore<TTarget, TMiddleware>() // adds before TTarget
.UseRequestMiddlewareBefore<TTarget>(Delegate) // adds before TTarget
.UseRequestMiddlewareAfter<TTarget, TMiddleware>() // adds after TTarget
.UseRequestMiddlewareAfter<TTarget>(Delegate) // adds after TTarget

if two middleware are registered after/before MiddlewareX or at the start, they are registered in the order they were defined in the executor builder call chain.

Product

Hot Chocolate

tobias-tengler avatar Oct 01 '22 11:10 tobias-tengler

We have implemented this for 16 and are polishing it at the moment.

michaelstaib avatar May 28 '25 12:05 michaelstaib