当前位置: 首页>>代码示例>>PHP>>正文


PHP Type::boolean方法代码示例

本文整理汇总了PHP中GraphQL\Type\Definition\Type::boolean方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::boolean方法的具体用法?PHP Type::boolean怎么用?PHP Type::boolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphQL\Type\Definition\Type的用法示例。


在下文中一共展示了Type::boolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFieldSelection

    public function testFieldSelection()
    {
        $image = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
        $article = null;
        $author = new ObjectType(['name' => 'Author', 'fields' => function () use($image, &$article) {
            return ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['type' => $image, 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]], 'recentArticle' => ['type' => $article]];
        }]);
        $reply = new ObjectType(['name' => 'Reply', 'fields' => ['author' => ['type' => $author], 'body' => ['type' => Type::string()]]]);
        $article = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::string()], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $author], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()], 'image' => ['type' => $image], 'replies' => ['type' => Type::listOf($reply)]]]);
        $doc = '
      query Test {
        article {
            author {
                name
                pic {
                    url
                    width
                }
            }
            image {
                width
                height
            }
            replies {
                body
                author {
                    id
                    name
                    pic {
                        url
                        width
                    }
                    recentArticle {
                        id
                        title
                        body
                    }
                }
            }
        }
      }
';
        $expectedDefaultSelection = ['author' => true, 'image' => true, 'replies' => true];
        $expectedDeepSelection = ['author' => ['name' => true, 'pic' => ['url' => true, 'width' => true]], 'image' => ['width' => true, 'height' => true], 'replies' => ['body' => true, 'author' => ['id' => true, 'name' => true, 'pic' => ['url' => true, 'width' => true], 'recentArticle' => ['id' => true, 'title' => true, 'body' => true]]]];
        $hasCalled = false;
        $actualDefaultSelection = null;
        $actualDeepSelection = null;
        $blogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $article, 'resolve' => function ($value, $args, $context, ResolveInfo $info) use(&$hasCalled, &$actualDefaultSelection, &$actualDeepSelection) {
            $hasCalled = true;
            $actualDefaultSelection = $info->getFieldSelection();
            $actualDeepSelection = $info->getFieldSelection(5);
            return null;
        }]]]);
        $schema = new Schema(['query' => $blogQuery]);
        $result = GraphQL::execute($schema, $doc);
        $this->assertTrue($hasCalled);
        $this->assertEquals(['data' => ['article' => null]], $result);
        $this->assertEquals($expectedDefaultSelection, $actualDefaultSelection);
        $this->assertEquals($expectedDeepSelection, $actualDeepSelection);
    }
开发者ID:webonyx,项目名称:graphql-php,代码行数:60,代码来源:ResolveInfoTest.php

示例2: setUp

 public function setUp()
 {
     $NamedType = new InterfaceType(['name' => 'Named', 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'barks' => ['type' => Type::boolean()]], 'isTypeOf' => function ($value) {
         return $value instanceof Dog;
     }]);
     $CatType = new ObjectType(['name' => 'Cat', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]], 'isTypeOf' => function ($value) {
         return $value instanceof Cat;
     }]);
     $PetType = new UnionType(['name' => 'Pet', 'types' => [$DogType, $CatType], 'resolveType' => function ($value) use($DogType, $CatType) {
         if ($value instanceof Dog) {
             return $DogType;
         }
         if ($value instanceof Cat) {
             return $CatType;
         }
     }]);
     $PersonType = new ObjectType(['name' => 'Person', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'pets' => ['type' => Type::listOf($PetType)], 'friends' => ['type' => Type::listOf($NamedType)]], 'isTypeOf' => 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]);
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:26,代码来源:UnionInterfaceTest.php

示例3: resolveType

 /**
  * @param string $name
  * @return Type
  */
 public function resolveType($name)
 {
     if (preg_match('#^(.+)\\!$#', $name, $regs)) {
         return Type::nonNull($this->resolveType($regs[1]));
     }
     if (preg_match('#^\\[(.+)\\]$#', $name, $regs)) {
         return Type::listOf($this->resolveType($regs[1]));
     }
     switch ($name) {
         case Type::INT:
             return Type::int();
         case Type::STRING:
             return Type::string();
         case Type::BOOLEAN:
             return Type::boolean();
         case Type::FLOAT:
             return Type::float();
         case Type::ID:
             return Type::id();
         default:
             if (!isset($this->types[$name])) {
                 throw new \InvalidArgumentException(sprintf('Type "%s" is not defined', $name));
             }
             return $this->types[$name];
     }
 }
开发者ID:jmcclell,项目名称:graphql-mapper,代码行数:30,代码来源:TypeResolver.php

示例4: getDefaultSchema

 /**
  * @return Schema
  */
 protected function getDefaultSchema()
 {
     $Being = new InterfaceType(['name' => 'Being', 'fields' => ['name' => ['type' => Type::string()]]]);
     $Pet = new InterfaceType(['name' => 'Pet', 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogCommand = new EnumType(['name' => 'DogCommand', 'values' => ['SIT' => ['value' => 0], 'HEEL' => ['value' => 1], 'DOWN' => ['value' => 3]]]);
     $Dog = new ObjectType(['name' => 'Dog', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'barkVolume' => ['type' => Type::int()], 'barks' => ['type' => Type::boolean()], 'doesKnowCommand' => ['type' => Type::boolean(), 'args' => ['dogCommand' => ['type' => $DogCommand]]], 'isHousetrained' => ['type' => Type::boolean(), 'args' => ['atOtherHomes' => ['type' => Type::boolean(), 'defaultValue' => true]]], 'isAtLocation' => ['type' => Type::boolean(), 'args' => ['x' => ['type' => Type::int()], 'y' => ['type' => Type::int()]]]], 'interfaces' => [$Being, $Pet]]);
     $FurColor = new EnumType(['name' => 'FurColor', 'values' => ['BROWN' => ['value' => 0], 'BLACK' => ['value' => 1], 'TAN' => ['value' => 2], 'SPOTTED' => ['value' => 3]]]);
     $Cat = new ObjectType(['name' => 'Cat', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()], 'meowVolume' => ['type' => Type::int()], 'furColor' => ['type' => $FurColor]], 'interfaces' => [$Being, $Pet]]);
     $CatOrDog = new UnionType(['name' => 'CatOrDog', 'types' => [$Dog, $Cat], 'resolveType' => function ($value) {
         // not used for validation
         return null;
     }]);
     $Intelligent = new InterfaceType(['name' => 'Intelligent', 'fields' => ['iq' => ['type' => Type::int()]]]);
     $Human = $this->humanType = new ObjectType(['name' => 'Human', 'interfaces' => [$Being, $Intelligent], 'fields' => ['name' => ['args' => ['surname' => ['type' => Type::boolean()]], 'type' => Type::string()], 'pets' => ['type' => Type::listOf($Pet)], 'relatives' => ['type' => function () {
         return Type::listOf($this->humanType);
     }]]]);
     $Alien = new ObjectType(['name' => 'Alien', 'interfaces' => [$Being, $Intelligent], 'fields' => ['iq' => ['type' => Type::int()], 'numEyes' => ['type' => Type::int()]]]);
     $DogOrHuman = new UnionType(['name' => 'DogOrHuman', 'types' => [$Dog, $Human], 'resolveType' => function () {
         // not used for validation
         return null;
     }]);
     $HumanOrAlien = new UnionType(['name' => 'HumanOrAlien', 'types' => [$Human, $Alien], 'resolveType' => function () {
         // not used for validation
         return null;
     }]);
     $ComplexInput = new InputObjectType(['name' => 'ComplexInput', 'fields' => ['requiredField' => ['type' => Type::nonNull(Type::boolean())], 'intField' => ['type' => Type::int()], 'stringField' => ['type' => Type::string()], 'booleanField' => ['type' => Type::boolean()], 'stringListField' => ['type' => Type::listOf(Type::string())]]]);
     $ComplicatedArgs = new ObjectType(['name' => 'ComplicatedArgs', 'fields' => ['intArgField' => ['type' => Type::string(), 'args' => ['intArg' => ['type' => Type::int()]]], 'nonNullIntArgField' => ['type' => Type::string(), 'args' => ['nonNullIntArg' => ['type' => Type::nonNull(Type::int())]]], 'stringArgField' => ['type' => Type::string(), 'args' => ['stringArg' => ['type' => Type::string()]]], 'booleanArgField' => ['type' => Type::string(), 'args' => ['booleanArg' => ['type' => Type::boolean()]]], 'enumArgField' => ['type' => Type::string(), 'args' => ['enumArg' => ['type' => $FurColor]]], 'floatArgField' => ['type' => Type::string(), 'args' => ['floatArg' => ['type' => Type::float()]]], 'idArgField' => ['type' => Type::string(), 'args' => ['idArg' => ['type' => Type::id()]]], 'stringListArgField' => ['type' => Type::string(), 'args' => ['stringListArg' => ['type' => Type::listOf(Type::string())]]], 'complexArgField' => ['type' => Type::string(), 'args' => ['complexArg' => ['type' => $ComplexInput]]], 'multipleReqs' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())]]], 'multipleOpts' => ['type' => Type::string(), 'args' => ['opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]], 'multipleOptAndReq' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())], 'opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]]]]);
     $queryRoot = new ObjectType(['name' => 'QueryRoot', 'fields' => ['human' => ['args' => ['id' => ['type' => Type::id()]], 'type' => $Human], 'alien' => ['type' => $Alien], 'dog' => ['type' => $Dog], 'cat' => ['type' => $Cat], 'pet' => ['type' => $Pet], 'catOrDog' => ['type' => $CatOrDog], 'dogOrHuman' => ['type' => $DogOrHuman], 'humanOrAlien' => ['type' => $HumanOrAlien], 'complicatedArgs' => ['type' => $ComplicatedArgs]]]);
     $defaultSchema = new Schema($queryRoot);
     return $defaultSchema;
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:34,代码来源:TestCase.php

示例5: testConvertsBooleanValueToASTs

 /**
  * @it converts boolean values to ASTs
  */
 public function testConvertsBooleanValueToASTs()
 {
     $this->assertEquals(new BooleanValue(['value' => true]), AST::astFromValue(true, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => false]), AST::astFromValue(false, Type::boolean()));
     $this->assertEquals(null, AST::astFromValue(null, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => false]), AST::astFromValue(0, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => true]), AST::astFromValue(1, Type::boolean()));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:11,代码来源:AstFromValueTest.php

示例6: setUp

 public function setUp()
 {
     $ColorType = new EnumType(['name' => 'Color', 'values' => ['RED' => ['value' => 0], 'GREEN' => ['value' => 1], 'BLUE' => ['value' => 2]]]);
     $simpleEnum = new EnumType(['name' => 'SimpleEnum', 'values' => ['ONE', 'TWO', 'THREE']]);
     $Complex1 = ['someRandomFunction' => function () {
     }];
     $Complex2 = new \ArrayObject(['someRandomValue' => 123]);
     $ComplexEnum = new EnumType(['name' => 'Complex', 'values' => ['ONE' => ['value' => $Complex1], 'TWO' => ['value' => $Complex2]]]);
     $QueryType = new ObjectType(['name' => 'Query', 'fields' => ['colorEnum' => ['type' => $ColorType, 'args' => ['fromEnum' => ['type' => $ColorType], 'fromInt' => ['type' => Type::int()], 'fromString' => ['type' => Type::string()]], 'resolve' => function ($value, $args) {
         if (isset($args['fromInt'])) {
             return $args['fromInt'];
         }
         if (isset($args['fromString'])) {
             return $args['fromString'];
         }
         if (isset($args['fromEnum'])) {
             return $args['fromEnum'];
         }
     }], 'simpleEnum' => ['type' => $simpleEnum, 'args' => ['fromName' => ['type' => Type::string()], 'fromValue' => ['type' => Type::string()]], 'resolve' => function ($value, $args) {
         if (isset($args['fromName'])) {
             return $args['fromName'];
         }
         if (isset($args['fromValue'])) {
             return $args['fromValue'];
         }
     }], 'colorInt' => ['type' => Type::int(), 'args' => ['fromEnum' => ['type' => $ColorType], 'fromInt' => ['type' => Type::int()]], 'resolve' => function ($value, $args) {
         if (isset($args['fromInt'])) {
             return $args['fromInt'];
         }
         if (isset($args['fromEnum'])) {
             return $args['fromEnum'];
         }
     }], 'complexEnum' => ['type' => $ComplexEnum, 'args' => ['fromEnum' => ['type' => $ComplexEnum, 'defaultValue' => $Complex1], 'provideGoodValue' => ['type' => Type::boolean()], 'provideBadValue' => ['type' => Type::boolean()]], 'resolve' => function ($value, $args) use($Complex1, $Complex2) {
         if (!empty($args['provideGoodValue'])) {
             // Note: this is one of the references of the internal values which
             // ComplexEnum allows.
             return $Complex2;
         }
         if (!empty($args['provideBadValue'])) {
             // Note: similar shape, but not the same *reference*
             // as Complex2 above. Enum internal values require === equality.
             return new \ArrayObject(['someRandomValue' => 123]);
         }
         return $args['fromEnum'];
     }]]]);
     $MutationType = new ObjectType(['name' => 'Mutation', 'fields' => ['favoriteEnum' => ['type' => $ColorType, 'args' => ['color' => ['type' => $ColorType]], 'resolve' => function ($value, $args) {
         return isset($args['color']) ? $args['color'] : null;
     }]]]);
     $SubscriptionType = new ObjectType(['name' => 'Subscription', 'fields' => ['subscribeToEnum' => ['type' => $ColorType, 'args' => ['color' => ['type' => $ColorType]], 'resolve' => function ($value, $args) {
         return isset($args['color']) ? $args['color'] : null;
     }]]]);
     $this->Complex1 = $Complex1;
     $this->Complex2 = $Complex2;
     $this->ComplexEnum = $ComplexEnum;
     $this->schema = new Schema(['query' => $QueryType, 'mutation' => $MutationType, 'subscription' => $SubscriptionType]);
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:56,代码来源:EnumTypeTest.php

示例7: testCoercesOutputBoolean

 public function testCoercesOutputBoolean()
 {
     $boolType = Type::boolean();
     $this->assertSame(true, $boolType->coerce('string'));
     $this->assertSame(false, $boolType->coerce(''));
     $this->assertSame(true, $boolType->coerce(1));
     $this->assertSame(false, $boolType->coerce(0));
     $this->assertSame(true, $boolType->coerce(true));
     $this->assertSame(false, $boolType->coerce(false));
     // TODO: how should it behaive on '0'?
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:11,代码来源:ScalarCoercionTest.php

示例8: testExecutesUsingASchema

    public function testExecutesUsingASchema()
    {
        $BlogArticle = null;
        $BlogImage = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
        $BlogAuthor = new ObjectType(['name' => 'Author', 'fields' => ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]], 'type' => $BlogImage, 'resolve' => function ($obj, $args) {
            return $obj['pic']($args['width'], $args['height']);
        }], 'recentArticle' => ['type' => function () use(&$BlogArticle) {
            return $BlogArticle;
        }]]]);
        $BlogArticle = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::nonNull(Type::string())], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $BlogAuthor], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()], 'keywords' => ['type' => Type::listOf(Type::string())]]]);
        $BlogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $BlogArticle, 'args' => ['id' => ['type' => Type::id()]], 'resolve' => function ($_, $args) {
            return $this->article($args['id']);
        }], 'feed' => ['type' => Type::listOf($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]]]]]];
        $this->assertEquals($expected, Executor::execute($BlogSchema, Parser::parse($request))->toArray());
    }
开发者ID:andytruong,项目名称:graphql-php,代码行数:52,代码来源:ExecutorSchemaTest.php

示例9: fields

 /**
  * Fields available on PageInfo.
  *
  * @return array
  */
 public function fields()
 {
     return ['hasNextPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating forwards, are there more items?', 'resolve' => function ($collection, $test) {
         if ($collection['total'] - $collection['first'] * $collection['currentPage'] > 0) {
             return true;
         }
         return false;
     }], 'hasPreviousPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating backwards, are there more items?', 'resolve' => function ($collection) {
         if ($collection['currentPage'] > 1) {
             return true;
         }
         return false;
     }]];
 }
开发者ID:suribit,项目名称:GraphQLRelayBundle,代码行数:19,代码来源:PageInfoType.php

示例10: setUp

 public function setUp()
 {
     $this->objectType = new ObjectType(['name' => 'Object']);
     $this->interfaceType = new InterfaceType(['name' => 'Interface']);
     $this->unionType = new UnionType(['name' => 'Union', 'types' => [$this->objectType]]);
     $this->enumType = new EnumType(['name' => 'Enum']);
     $this->inputObjectType = new InputObjectType(['name' => 'InputObject']);
     $this->blogImage = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
     $this->blogAuthor = new ObjectType(['name' => 'Author', 'fields' => ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['type' => $this->blogImage, 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]], 'recentArticle' => ['type' => function () {
         return $this->blogArticle;
     }]]]);
     $this->blogArticle = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::string()], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $this->blogAuthor], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()]]]);
     $this->blogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $this->blogArticle, 'args' => ['id' => ['type' => Type::string()]]], 'feed' => ['type' => new ListOfType($this->blogArticle)]]]);
     $this->blogMutation = new ObjectType(['name' => 'Mutation', 'fields' => ['writeArticle' => ['type' => $this->blogArticle]]]);
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:15,代码来源:DefinitionTest.php

示例11: fields

 /**
  * Fields available on PageInfo.
  *
  * @return array
  */
 public function fields()
 {
     return ['hasNextPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating forwards, are there more items?', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->hasMorePages();
         }
         return false;
     }], 'hasPreviousPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating backwards, are there more items?', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->currentPage() > 1;
         }
         return false;
     }], 'startCursor' => ['type' => Type::string(), 'description' => 'When paginating backwards, the cursor to continue.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $this->encodeGlobalId('arrayconnection', $collection->firstItem() * $collection->currentPage());
         }
         return null;
     }], 'endCursor' => ['type' => Type::string(), 'description' => 'When paginating forwards, the cursor to continue.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $this->encodeGlobalId('arrayconnection', $collection->lastItem() * $collection->currentPage());
         }
         return null;
     }], 'total' => ['type' => Type::int(), 'description' => 'Total number of node in connection.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->total();
         }
         return null;
     }], 'count' => ['type' => Type::int(), 'description' => 'Count of nodes in current request.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->count();
         }
         return null;
     }], 'currentPage' => ['type' => Type::int(), 'description' => 'Current page of request.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->currentPage();
         }
         return null;
     }], 'lastPage' => ['type' => Type::int(), 'description' => 'Last page in connection.', 'resolve' => function ($collection) {
         if ($collection instanceof LengthAwarePaginator) {
             return $collection->lastPage();
         }
         return null;
     }]];
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:49,代码来源:PageInfoType.php

示例12: fields

 public function fields()
 {
     return ['title' => ['type' => Type::string(), 'description' => 'Title of task.'], 'description' => ['type' => Type::string(), 'description' => 'Description of task.'], 'completed' => ['type' => Type::boolean(), 'description' => 'Completed status.']];
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:4,代码来源:CursorTest.php

示例13: _enumValue

 public static function _enumValue()
 {
     if (!isset(self::$_map['__EnumValue'])) {
         self::$_map['__EnumValue'] = new ObjectType(['name' => '__EnumValue', 'fields' => ['name' => ['type' => Type::nonNull(Type::string())], 'description' => ['type' => Type::string()], 'isDeprecated' => ['type' => Type::nonNull(Type::boolean()), 'resolve' => function ($enumValue) {
             return !!$enumValue->deprecationReason;
         }], 'deprecationReason' => ['type' => Type::string()]]]);
     }
     return self::$_map['__EnumValue'];
 }
开发者ID:mrsinguyen,项目名称:graphql-php,代码行数:9,代码来源:Introspection.php

示例14: testDoesNotIncludeArgumentsThatWereNotSet

 public function testDoesNotIncludeArgumentsThatWereNotSet()
 {
     $schema = new Schema(new ObjectType(['name' => 'Type', 'fields' => ['field' => ['type' => Type::string(), 'resolve' => function ($data, $args) {
         return $args ? json_encode($args) : '';
     }, 'args' => ['a' => ['type' => Type::boolean()], 'b' => ['type' => Type::boolean()], 'c' => ['type' => Type::boolean()], 'd' => ['type' => Type::int()], 'e' => ['type' => Type::int()]]]]]));
     $query = Parser::parse('{ field(a: true, c: false, e: 0) }');
     $result = Executor::execute($schema, $query);
     $expected = ['data' => ['field' => '{"a":true,"c":false,"e":0}']];
     $this->assertEquals($expected, $result->toArray());
     /*
        var query = parse('{ field(a: true, c: false, e: 0) }');
        var result = await execute(schema, query);
     
        expect(result).to.deep.equal({
          data: {
            field: '{"a":true,"c":false,"e":0}'
          }
        });
      });
     
      it('fails when an isTypeOf check is not met', async () => {
        class Special {
          constructor(value) {
            this.value = value;
          }
        }
     
        class NotSpecial {
          constructor(value) {
            this.value = value;
          }
        }
     
        var SpecialType = new GraphQLObjectType({
          name: 'SpecialType',
          isTypeOf(obj) {
            return obj instanceof Special;
          },
          fields: {
            value: { type: GraphQLString }
          }
        });
     
        var schema = new GraphQLSchema({
          query: new GraphQLObjectType({
            name: 'Query',
            fields: {
              specials: {
                type: new GraphQLList(SpecialType),
                resolve: rootValue => rootValue.specials
              }
            }
          })
        });
     
        var query = parse('{ specials { value } }');
        var value = {
          specials: [ new Special('foo'), new NotSpecial('bar') ]
        };
        var result = await execute(schema, query, value);
     
        expect(result.data).to.deep.equal({
          specials: [
            { value: 'foo' },
            null
          ]
        });
        expect(result.errors).to.have.lengthOf(1);
        expect(result.errors).to.containSubset([
          { message:
              'Expected value of type "SpecialType" but got: [object Object].',
            locations: [ { line: 1, column: 3 } ] }
        ]);
      });
     */
 }
开发者ID:joaqtor,项目名称:graphql-php,代码行数:76,代码来源:ExecutorTest.php

示例15: InterfaceType

 function testResolveTypeOnInterfaceYieldsUsefulError()
 {
     $DogType = null;
     $CatType = null;
     $HumanType = null;
     $PetType = new InterfaceType(['name' => 'Pet', 'resolveType' => function ($obj) use(&$DogType, &$CatType, &$HumanType) {
         if ($obj instanceof Dog) {
             return $DogType;
         }
         if ($obj instanceof Cat) {
             return $CatType;
         }
         if ($obj instanceof Human) {
             return $HumanType;
         }
         return null;
     }, 'fields' => ['name' => ['type' => Type::string()]]]);
     $HumanType = new ObjectType(['name' => 'Human', 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()]]]);
     $CatType = new ObjectType(['name' => 'Cat', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]]]);
     $schema = new Schema(new ObjectType(['name' => 'Query', 'fields' => ['pets' => ['type' => Type::listOf($PetType), 'resolve' => function () {
         return [new Dog('Odie', true), new Cat('Garfield', false), new Human('Jon')];
     }]]]));
     $query = '{
       pets {
         name
         ... on Dog {
           woofs
         }
         ... on Cat {
           meows
         }
       }
     }';
     $expected = ['data' => ['pets' => [['name' => 'Odie', 'woofs' => true], ['name' => 'Garfield', 'meows' => false], null]], 'errors' => [['message' => 'Runtime Object type "Human" is not a possible type for "Pet".']]];
     $this->assertEquals($expected, Executor::execute($schema, Parser::parse($query))->toArray());
 }
开发者ID:andytruong,项目名称:graphql-php,代码行数:37,代码来源:AbstractTest.php


注:本文中的GraphQL\Type\Definition\Type::boolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。