Example #1
0
 private function assertAllVariablesUsed(Request $request)
 {
     foreach ($request->getQueryVariables() as $queryVariable) {
         if (!$queryVariable->isUsed()) {
             throw new InvalidRequestException(sprintf('Variable "%s" not used', $queryVariable->getName()), $queryVariable->getLocation());
         }
     }
 }
Example #2
0
 public function testSetVariableParseJson()
 {
     $variables = '{"foo": "bar"}';
     $expectedVariableArray = ['foo' => 'bar'];
     $request = new Request([], $variables);
     $this->assertEquals($expectedVariableArray, $request->getVariables());
     $request = new Request();
     $request->setVariables($variables);
     $this->assertEquals($expectedVariableArray, $request->getVariables());
 }
Example #3
0
 private function getVariableReferenceArgumentValue(VariableReference $variableReference, AbstractType $argumentType, Request $request)
 {
     $variable = $variableReference->getVariable();
     if ($argumentType->getKind() == TypeMap::KIND_LIST) {
         if ($variable->getTypeName() != $argumentType->getNamedType()->getName() || !$variable->isArray()) {
             throw new ResolveException(sprintf('Invalid variable "%s" type, allowed type is "%s"', $variable->getName(), $argumentType->getName()), $variable->getLocation());
         }
     } else {
         if ($variable->getTypeName() != $argumentType->getName()) {
             throw new ResolveException(sprintf('Invalid variable "%s" type, allowed type is "%s"', $variable->getName(), $argumentType->getName()), $variable->getLocation());
         }
     }
     $requestValue = $request->getVariable($variable->getName());
     if (!$request->hasVariable($variable->getName()) || null === $requestValue && $variable->isNullable()) {
         throw new ResolveException(sprintf('Variable "%s" does not exist in request', $variable->getName()), $variable->getLocation());
     }
     return $requestValue;
 }