sangria v0.4.3 Release Notes
Release Date: 2015-10-16 // over 8 years ago-
QueryReducer
is introduced. It allows you to analyze a query and take an action before it's executed. It provides very similar functionality to complexity analysis (introduced in previous release), but in much more generic form. That's because complexity analysis is now rewritten as aQueryReducer
. In order to migrate, you need to replacemeasureComplexity
function withQueryReducer.measureComplexity
. Here is an example: ```scala val complReducer = QueryReducer.measureComplexity[MyCtx] { (c, ctx) => complexity = c ctx }
Executor.execute(schema, query, userContext = new MyCtx, queryReducers = complReducer :: Nil)
Since rejection of complex queries is such a common use-case, there is now a helper function to create a reducer for it: ```scala val rejectComplexQuery = QueryReducer.rejectComplexQueries[MyCtx](14, (c, ctx) => new IllegalArgumentException(s"Too complex query: max allowed complexity is 14.0, but got $c"))
Middleware
got a type parameter forCtx
. This is a minor breaking change. If you don't use theuserContext
inside of theMiddleware
, then you can just parametrize it withAny
.- Complexity function on field should also be given the
Ctx
(#87)