GraphQL\Type\Definition\UnionType::getTypes PHP Method

getTypes() public method

public getTypes ( ) : ObjectType[]
return ObjectType[]
    public function getTypes()
    {
        if (null === $this->types) {
            if ($this->config['types'] instanceof \Closure) {
                $types = call_user_func($this->config['types']);
            } else {
                $types = $this->config['types'];
            }
            Utils::invariant(is_array($types), 'Option "types" of union "%s" is expected to return array of types (or closure returning array of types)', $this->name);
            $this->types = [];
            foreach ($types as $type) {
                $this->types[] = Type::resolve($type);
            }
        }
        return $this->types;
    }

Usage Example

コード例 #1
0
 /**
  * @it allows a thunk for Union\'s types
  */
 public function testAllowsThunkForUnionTypes()
 {
     $union = new UnionType(['name' => 'ThunkUnion', 'types' => function () {
         return [$this->objectType];
     }]);
     $types = $union->getTypes();
     $this->assertEquals(1, count($types));
     $this->assertSame($this->objectType, $types[0]);
 }