support for client side polymorphic queries and fix to toType bug