Add typechecking to queries