hasVariable() public method

public hasVariable ( $name )
示例#1
0
 public function testMethods()
 {
     $fragment1 = new Fragment('fragmentName1', 'test', [], new Location(1, 1));
     $fragment2 = new Fragment('fragmentName2', 'test', [], new Location(1, 1));
     $queriesData = ['query1', 'query2'];
     $mutationsData = ['mutation1', 'mutation2'];
     $fragmentsData = [$fragment1];
     $variables = ['page' => 2];
     $request = new Request(['queries' => $queriesData, 'mutations' => $mutationsData, 'fragments' => $fragmentsData]);
     $request->setVariables($variables);
     $this->assertEquals($queriesData, $request->getQueries());
     $this->assertEquals($mutationsData, $request->getMutations());
     $this->assertEquals($fragmentsData, $request->getFragments());
     $this->assertEquals($variables, $request->getVariables());
     $this->assertTrue($request->hasFragments());
     $this->assertTrue($request->hasMutations());
     $this->assertTrue($request->hasQueries());
     $this->assertTrue($request->hasVariable('page'));
     $this->assertEquals(2, $request->getVariable('page'));
     $request->addFragment($fragment2);
     $this->assertEquals($fragment2, $request->getFragment('fragmentName2'));
     $this->assertNull($request->getFragment('unknown fragment'));
 }
示例#2
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;
 }