getType() 공개 메소드

public getType ( string $name ) : Type
$name string
리턴 GraphQL\Type\Definition\Type
예제 #1
0
 public function testIncludesInterfaceSubtypesInTheTypeMap()
 {
     $someInterface = new InterfaceType(['name' => 'SomeInterface', 'fields' => []]);
     $someSubtype = new ObjectType(['name' => 'SomeSubtype', 'fields' => [], 'interfaces' => [$someInterface]]);
     $schema = new Schema($someInterface);
     $this->assertSame($someSubtype, $schema->getType('SomeSubtype'));
 }
예제 #2
0
 public function testRejectsWhenAnImplementationIsNotAPossibleType()
 {
     // rejects when an implementation is not a possible type
     $interfaceType = new InterfaceType(['name' => 'InterfaceType', 'fields' => []]);
     $subType = new ObjectType(['name' => 'SubType', 'fields' => [], 'interfaces' => []]);
     $tmp = new \ReflectionObject($subType);
     $prop = $tmp->getProperty('_interfaces');
     $prop->setAccessible(true);
     $prop->setValue($subType, [$interfaceType]);
     // Sanity check the test.
     $this->assertEquals([$interfaceType], $subType->getInterfaces());
     $this->assertSame(false, $interfaceType->isPossibleType($subType));
     // Need to make sure SubType is in the schema! We rely on
     // possibleTypes to be able to see it unless it's explicitly used.
     $schema = new Schema($interfaceType, $subType);
     // Another sanity check.
     $this->assertSame($subType, $schema->getType('SubType'));
     $validationResult = SchemaValidator::validate($schema, [SchemaValidator::typesInterfacesMustShowThemAsPossibleRule()]);
     $this->assertSame(false, $validationResult->isValid);
     $this->assertSame(1, count($validationResult->errors));
     $this->assertSame('SubType implements interface InterfaceType, but InterfaceType does ' . 'not list it as possible!', $validationResult->errors[0]->message);
     /*
     
        var validationResult = validateSchema(
          schema,
          [TypesInterfacesMustShowThemAsPossible]
        );
        expect(validationResult.isValid).to.equal(false);
        expect(validationResult.errors.length).to.equal(1);
        expect(validationResult.errors[0].message).to.equal(
          'SubType implements interface InterfaceType, but InterfaceType does ' +
          'not list it as possible!'
        );
     */
 }
예제 #3
0
 public function testIncludesInterfacesThunkSubtypesInTheTypeMap()
 {
     // includes interfaces' thunk subtypes in the type map
     $someInterface = new InterfaceType(['name' => 'SomeInterface', 'fields' => ['f' => ['type' => Type::int()]]]);
     $someSubtype = new ObjectType(['name' => 'SomeSubtype', 'fields' => ['f' => ['type' => Type::int()]], 'interfaces' => function () use($someInterface) {
         return [$someInterface];
     }, 'isTypeOf' => function () {
         return true;
     }]);
     $schema = new Schema(new ObjectType(['name' => 'Query', 'fields' => ['iface' => ['type' => $someInterface]]]));
     $this->assertSame($someSubtype, $schema->getType('SomeSubtype'));
 }
예제 #4
0
 public function testAllowsShorthandFieldDefinition()
 {
     $interface = new InterfaceType(['name' => 'SomeInterface', 'fields' => function () use(&$interface) {
         return ['value' => Type::string(), 'nested' => $interface, 'withArg' => ['type' => Type::string(), 'args' => ['arg1' => Type::int()]]];
     }]);
     $query = new ObjectType(['name' => 'Query', 'fields' => ['test' => $interface]]);
     $schema = new Schema(['query' => $query]);
     $valueField = $schema->getType('SomeInterface')->getField('value');
     $nestedField = $schema->getType('SomeInterface')->getField('nested');
     $this->assertEquals(Type::string(), $valueField->getType());
     $this->assertEquals($interface, $nestedField->getType());
     $withArg = $schema->getType('SomeInterface')->getField('withArg');
     $this->assertEquals(Type::string(), $withArg->getType());
     $this->assertEquals('arg1', $withArg->args[0]->name);
     $this->assertEquals(Type::int(), $withArg->args[0]->getType());
     $testField = $schema->getType('Query')->getField('test');
     $this->assertEquals($interface, $testField->getType());
     $this->assertEquals('test', $testField->name);
 }