youshido-php / GraphQL

Pure PHP realization of GraphQL protocol
MIT License
710 stars 107 forks source link

counting queries in payload #207

Closed usefksa closed 6 years ago

usefksa commented 6 years ago

Is there any way to count how many query exist inside payload (root query)?

like here

{
  user(username: "root") {
    id
    username
  }
  user(username: "root2") {
    id
    username
  }
  user(username: "root3") {
    id
    username
  }
}

The total here should be 3. I want to know how may query exists to prevent malicious queries (example, repeating the above query for thousands times.

usefksa commented 6 years ago

I fixed it here is the code for that


 $parser  = new Parser();
        $request = new Request($parser->parse($payload), $variables);
        $countQueriesAndMutations=count($request->getQueries()) + count($request->getMutations());