Calls hook if query is not nil