add query middleware