graph query implementation