コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getType()
 {
     if (!isset($this->type)) {
         $this->type = new NonNullModifier(Type::booleanType());
     }
     return $this->type;
 }
コード例 #2
0
 protected function setUp()
 {
     $namedType = new InterfaceType('Named', ['name' => ['type' => Type::stringType()]]);
     $dogType = new ObjectType('Dog', ['name' => ['type' => Type::stringType()], 'barks' => ['type' => Type::booleanType()]], [$namedType], function ($value) {
         return $value instanceof Dog;
     });
     $catType = new ObjectType('Cat', ['name' => ['type' => Type::stringType()], 'meows' => ['type' => Type::booleanType()]], [$namedType], function ($value) {
         return $value instanceof Cat;
     });
     $petType = new UnionType('Pet', [$dogType, $catType], function ($value) use($dogType, $catType) {
         if ($value instanceof Dog) {
             return $dogType;
         }
         if ($value instanceof Cat) {
             return $catType;
         }
         return NULL;
     });
     $personType = new ObjectType('Person', ['name' => ['type' => Type::stringType()], 'pets' => ['type' => new ListModifier($petType)], 'friends' => ['type' => new ListModifier($namedType)]], [$namedType], function ($value) {
         return $value instanceof Person;
     });
     $this->schema = new Schema($personType);
     $this->garfield = new Cat('Garfield', FALSE);
     $this->odie = new Dog('Odie', TRUE);
     $this->liz = new Person('Liz');
     $this->john = new Person('John', [$this->garfield, $this->odie], [$this->liz, $this->odie]);
 }
コード例 #3
0
ファイル: DefinitionTest.php プロジェクト: fubhy/graphql-php
 public function setUp()
 {
     $this->blogImage = new ObjectType('Image', ['url' => ['type' => Type::stringType()], 'width' => ['type' => Type::intType()], 'height' => ['type' => Type::intType()]]);
     $this->blogAuthor = new ObjectType('Author', ['id' => ['type' => Type::stringType()], 'name' => ['type' => Type::stringType()], 'pic' => ['args' => ['width' => ['type' => Type::intType()], 'height' => ['type' => Type::intType()]], 'type' => $this->blogImage], 'recentArticle' => ['type' => function () {
         return $this->blogArticle;
     }]]);
     $this->blogArticle = new ObjectType('Article', ['id' => ['type' => Type::stringType()], 'isPublished' => ['type' => Type::booleanType()], 'author' => ['type' => $this->blogAuthor], 'title' => ['type' => Type::stringType()], 'body' => ['type' => Type::stringType()]]);
     $this->blogQuery = new ObjectType('Query', ['article' => ['args' => ['id' => ['type' => Type::stringType()]], 'type' => $this->blogArticle], 'feed' => ['type' => new ListModifier($this->blogArticle)]]);
     $this->blogMutation = new ObjectType('Mutation', ['writeArticle' => ['type' => $this->blogArticle]]);
 }
コード例 #4
0
    public function testExecutesUsingASchema()
    {
        $blogArticle = NULL;
        $blogImage = new ObjectType('Image', ['url' => ['type' => Type::stringType()], 'width' => ['type' => Type::intType()], 'height' => ['type' => Type::intType()]]);
        $blogAuthor = new ObjectType('Author', ['id' => ['type' => Type::stringType()], 'name' => ['type' => Type::stringType()], 'pic' => ['args' => ['width' => ['type' => Type::intType()], 'height' => ['type' => Type::intType()]], 'type' => $blogImage, 'resolve' => function ($obj, $args) {
            return $obj['pic']($args['width'], $args['height']);
        }], 'recentArticle' => ['type' => function () use(&$blogArticle) {
            return $blogArticle;
        }]]);
        $blogArticle = new ObjectType('Article', ['id' => ['type' => new NonNullModifier(Type::stringType())], 'isPublished' => ['type' => Type::booleanType()], 'author' => ['type' => $blogAuthor], 'title' => ['type' => Type::stringType()], 'body' => ['type' => Type::stringType()], 'keywords' => ['type' => new ListModifier(Type::stringType())]]);
        $blogQuery = new ObjectType('Query', ['article' => ['type' => $blogArticle, 'args' => ['id' => ['type' => Type::idType()]], 'resolve' => function ($_, $args) {
            return $this->article($args['id']);
        }], 'feed' => ['type' => new ListModifier($blogArticle), 'resolve' => function () {
            return [$this->article(1), $this->article(2), $this->article(3), $this->article(4), $this->article(5), $this->article(6), $this->article(7), $this->article(8), $this->article(9), $this->article(10)];
        }]]);
        $blogSchema = new Schema($blogQuery);
        $request = '
            {
                feed {
                    id,
                    title
                },
                article(id: "1") {
                    ...articleFields,
                    author {
                        id,
                        name,
                        pic(width: 640, height: 480) {
                            url,
                            width,
                            height
                        },
                        recentArticle {
                            ...articleFields,
                            keywords
                        }
                    }
                }
            }

            fragment articleFields on Article {
                id,
                isPublished,
                title,
                body,
                hidden,
                notdefined
            }
        ';
        $expected = ['data' => ['feed' => [['id' => '1', 'title' => 'My Article 1'], ['id' => '2', 'title' => 'My Article 2'], ['id' => '3', 'title' => 'My Article 3'], ['id' => '4', 'title' => 'My Article 4'], ['id' => '5', 'title' => 'My Article 5'], ['id' => '6', 'title' => 'My Article 6'], ['id' => '7', 'title' => 'My Article 7'], ['id' => '8', 'title' => 'My Article 8'], ['id' => '9', 'title' => 'My Article 9'], ['id' => '10', 'title' => 'My Article 10']], 'article' => ['id' => '1', 'isPublished' => TRUE, 'title' => 'My Article 1', 'body' => 'This is a post', 'author' => ['id' => '123', 'name' => 'John Smith', 'pic' => ['url' => 'cdn://123', 'width' => 640, 'height' => 480], 'recentArticle' => ['id' => '1', 'isPublished' => TRUE, 'title' => 'My Article 1', 'body' => 'This is a post', 'keywords' => ['foo', 'bar', '1', 'true', NULL]]]]]];
        $parser = new Parser();
        $this->assertEquals($expected, Executor::execute($blogSchema, NULL, $parser->parse(new Source($request)), '', []));
    }
コード例 #5
0
ファイル: CoercionTest.php プロジェクト: fubhy/graphql-php
 /**
  * @dataProvider coercesOutputBooleanProvider
  *
  * @param mixed $input
  * @param float|null $expected
  */
 public function testCoercesOutputBoolean($input, $expected)
 {
     $this->assertSame($expected, Type::booleanType()->coerce($input));
 }
コード例 #6
0
ファイル: Schema.php プロジェクト: fubhy/graphql-php
 /**
  * Re-populate static properties when de-serializing.
  */
 public function __wakeup()
 {
     Type::intType();
     Type::booleanType();
     Type::floatType();
     Type::idType();
     Type::stringType();
 }
コード例 #7
0
ファイル: Introspection.php プロジェクト: fubhy/graphql-php
 /**
  * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
  */
 public static function enumValue()
 {
     if (!isset(static::$enumValue)) {
         static::$enumValue = new ObjectType('__EnumValue', ['name' => ['type' => new NonNullModifier(Type::stringType()), 'resolve' => [__CLASS__, 'resolveEnumValueName']], 'description' => ['type' => Type::stringType(), 'resolve' => [__CLASS__, 'resolveEnumValueDescription']], 'isDeprecated' => ['type' => new NonNullModifier(Type::booleanType()), 'resolve' => [__CLASS__, 'resolveEnumValueIsDeprecated']], 'deprecationReason' => ['type' => Type::stringType(), 'resolve' => [__CLASS__, 'resolveEnumValueDeprecationReason']]]);
     }
     return static::$enumValue;
 }