Inheritance: extends AbstractObjectType
Example #1
0
 public function testFieldsTrait()
 {
     $idField = new Field(['name' => 'id', 'type' => new IntType()]);
     $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
     $objectType = new ObjectType(['name' => 'Post', 'fields' => [$idField], 'description' => 'Post type description']);
     $this->assertTrue($objectType->hasFields());
     $this->assertEquals(['id' => $idField], $objectType->getFields());
     $objectType->addField($nameField);
     $this->assertEquals(['id' => $idField, 'name' => $nameField], $objectType->getFields());
 }
Example #2
0
 public function testInterfaceMethods()
 {
     $interface = new TestInterfaceType();
     $this->assertEquals($interface->getNamedType(), $interface->getType());
     $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
     $nameField->getName();
     $this->assertEquals(['name' => $nameField], $interface->getFields());
     $object = new ObjectType(['name' => 'Test', 'fields' => ['name' => new StringType()], 'interfaces' => [$interface]]);
     $this->assertEquals([$interface], $object->getInterfaces());
     $this->assertTrue($interface->isValidValue($object));
     $this->assertFalse($interface->isValidValue('invalid object'));
     $this->assertEquals($interface->serialize($object), $object);
     $interfaceType = new InterfaceType(['name' => 'UserInterface', 'fields' => ['name' => new StringType()], 'resolveType' => function ($object) {
         return $object;
     }]);
     $this->assertEquals('UserInterface', $interfaceType->getName());
     $this->assertEquals($object, $interfaceType->resolveType($object));
     $this->assertTrue($interfaceType->isValidValue($object));
     $this->assertFalse($interfaceType->isValidValue('invalid object'));
 }
Example #3
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testEnumConfig()
 {
     $enumType = new EnumType(['name' => 'Status', 'values' => [['name' => 'ACTIVE', 'values' => 1]]]);
     $object = new ObjectType(['name' => 'Project', 'fields' => ['id' => new IdType(), 'status' => $enumType]]);
     ConfigValidator::getInstance()->assertValidConfig($object->getConfig());
 }