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


PHP Type::int方法代码示例

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


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

示例1: setup

 public function setup()
 {
     $this->allUsers = [['name' => 'Dan', 'friends' => [1, 2, 3, 4]], ['name' => 'Nick', 'friends' => [0, 2, 3, 4]], ['name' => 'Lee', 'friends' => [0, 1, 3, 4]], ['name' => 'Joe', 'friends' => [0, 1, 2, 4]], ['name' => 'Tim', 'friends' => [0, 1, 2, 3]]];
     $this->userType = new ObjectType(['name' => 'User', 'fields' => function () {
         return ['name' => ['type' => Type::string()], 'friends' => ['type' => $this->friendConnection, 'args' => Connection::connectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }], 'friendsForward' => ['type' => $this->userConnection, 'args' => Connection::forwardConnectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }], 'friendsBackward' => ['type' => $this->userConnection, 'args' => Connection::backwardConnectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }]];
     }]);
     $this->friendEdge = Connection::createEdgeType(['name' => 'Friend', 'nodeType' => $this->userType, 'resolveNode' => function ($edge) {
         return $this->allUsers[$edge['node']];
     }, 'edgeFields' => function () {
         return ['friendshipTime' => ['type' => Type::string(), 'resolve' => function () {
             return 'Yesterday';
         }]];
     }]);
     $this->friendConnection = Connection::createConnectionType(['name' => 'Friend', 'nodeType' => $this->userType, 'edgeType' => $this->friendEdge, 'connectionFields' => function () {
         return ['totalCount' => ['type' => Type::int(), 'resolve' => function () {
             return count($this->allUsers) - 1;
         }]];
     }]);
     $this->userEdge = Connection::createEdgeType(['nodeType' => $this->userType, 'resolveNode' => function ($edge) {
         return $this->allUsers[$edge['node']];
     }]);
     $this->userConnection = Connection::createConnectionType(['nodeType' => $this->userType, 'edgeType' => $this->userEdge]);
     $this->queryType = new ObjectType(['name' => 'Query', 'fields' => function () {
         return ['user' => ['type' => $this->userType, 'resolve' => function () {
             return $this->allUsers[0];
         }]];
     }]);
     $this->schema = new Schema(['query' => $this->queryType]);
 }
开发者ID:ivome,项目名称:graphql-relay-php,代码行数:35,代码来源:SeparateConnectionTest.php

示例2: getConnections

 /**
  * Generate Relay compliant edges.
  *
  * @return array
  */
 public function getConnections()
 {
     $edges = [];
     foreach ($this->connections() as $name => $edge) {
         $injectCursor = isset($edge['injectCursor']) ? $edge['injectCursor'] : null;
         $resolveCursor = isset($edge['resolveCursor']) ? $edge['resolveCursor'] : null;
         $edgeType = $this->edgeType($name, $edge['type'], $resolveCursor);
         $connectionType = $this->connectionType($name, Type::listOf($edgeType), $injectCursor);
         $edges[$name] = ['type' => $connectionType, 'description' => 'A connection to a list of items.', 'args' => ['first' => ['name' => 'first', 'type' => Type::int()], 'after' => ['name' => 'after', 'type' => Type::string()]], 'resolve' => isset($edge['resolve']) ? $edge['resolve'] : function ($collection, array $args, ResolveInfo $info) use($name) {
             $items = [];
             if (is_array($collection) && isset($collection[$name])) {
                 $items = $collection[$name];
             }
             if (isset($args['first'])) {
                 $total = count($items);
                 $first = $args['first'];
                 $after = $this->decodeCursor($args);
                 $currentPage = $first && $after ? floor(($first + $after) / $first) : 1;
                 return ['items' => array_slice($items, $after, $first), 'total' => $total, 'first' => $first, 'currentPage' => $currentPage];
             }
             return ['items' => $items, 'total' => count($items), 'first' => count($items), 'currentPage' => 1];
         }];
     }
     return $edges;
 }
开发者ID:suribit,项目名称:GraphQLRelayBundle,代码行数:30,代码来源:RelayType.php

示例3: 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

示例4: 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

示例5: 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

示例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: testHandlesNonNullListOfNonNulls

 /**
  * @describe [T!]!
  */
 public function testHandlesNonNullListOfNonNulls()
 {
     $type = Type::nonNull(Type::listOf(Type::nonNull(Type::int())));
     // Contains values
     $this->check($type, [1, 2], ['data' => ['nest' => ['test' => [1, 2]]]]);
     // Contains null
     $this->check($type, [1, null, 2], ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
     // Returns null
     $this->check($type, null, ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:13,代码来源:ListsTest.php

示例8: testUsesProvidedResolveFunction

 /**
  * @it uses provided resolve function
  */
 public function testUsesProvidedResolveFunction()
 {
     $schema = $this->buildSchema(['type' => Type::string(), 'args' => ['aStr' => ['type' => Type::string()], 'aInt' => ['type' => Type::int()]], 'resolve' => function ($source, $args) {
         return json_encode([$source, $args]);
     }]);
     $this->assertEquals(['data' => ['test' => '[null,[]]']], GraphQL::execute($schema, '{ test }'));
     $this->assertEquals(['data' => ['test' => '["Source!",[]]']], GraphQL::execute($schema, '{ test }', 'Source!'));
     $this->assertEquals(['data' => ['test' => '["Source!",{"aStr":"String!"}]']], GraphQL::execute($schema, '{ test(aStr: "String!") }', 'Source!'));
     $this->assertEquals(['data' => ['test' => '["Source!",{"aStr":"String!","aInt":-123}]']], GraphQL::execute($schema, '{ test(aInt: -123, aStr: "String!") }', 'Source!'));
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:13,代码来源:ResolveTest.php

示例9: testSerializesOutputInt

 /**
  * @it serializes output int
  */
 public function testSerializesOutputInt()
 {
     $intType = Type::int();
     $this->assertSame(1, $intType->serialize(1));
     $this->assertSame(123, $intType->serialize('123'));
     $this->assertSame(0, $intType->serialize(0));
     $this->assertSame(-1, $intType->serialize(-1));
     $this->assertSame(0, $intType->serialize(0.1));
     $this->assertSame(1, $intType->serialize(1.1));
     $this->assertSame(-1, $intType->serialize(-1.1));
     $this->assertSame(100000, $intType->serialize(100000.0));
     // Maybe a safe PHP int, but bigger than 2^32, so not
     // representable as a GraphQL Int
     try {
         $intType->serialize(9876504321);
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: 9876504321', $e->getMessage());
     }
     try {
         $intType->serialize(-9876504321);
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: -9876504321', $e->getMessage());
     }
     try {
         $intType->serialize(1.0E+100);
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: 1.0E+100', $e->getMessage());
     }
     try {
         $intType->serialize(-1.0E+100);
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: -1.0E+100', $e->getMessage());
     }
     $this->assertSame(-1, $intType->serialize('-1.1'));
     try {
         $intType->serialize('one');
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: one', $e->getMessage());
     }
     try {
         $intType->serialize('');
         $this->fail('Expected exception was not thrown');
     } catch (InvariantViolation $e) {
         $this->assertEquals('Int cannot represent non 32-bit signed integer value: (empty string)', $e->getMessage());
     }
     $this->assertSame(0, $intType->serialize(false));
     $this->assertSame(1, $intType->serialize(true));
 }
开发者ID:webonyx,项目名称:graphql-php,代码行数:56,代码来源:ScalarSerializationTest.php

示例10: 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

示例11: testConvertsIntValuesToASTs

 /**
  * @it converts Int values to Int ASTs
  */
 public function testConvertsIntValuesToASTs()
 {
     $this->assertEquals(new IntValue(['value' => '123']), AST::astFromValue(123.0, Type::int()));
     $this->assertEquals(new IntValue(['value' => '123']), AST::astFromValue(123.5, Type::int()));
     $this->assertEquals(new IntValue(['value' => '10000']), AST::astFromValue(10000.0, Type::int()));
     try {
         AST::astFromValue(1.0E+40, Type::int());
         // Note: js version will produce 1e+40, both values are valid GraphQL floats
         $this->fail('Expected exception is not thrown');
     } catch (\Exception $e) {
         $this->assertSame('Int cannot represent non 32-bit signed integer value: 1.0E+40', $e->getMessage());
     }
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:16,代码来源:AstFromValueTest.php

示例12: schema

 private function schema()
 {
     $numberHolderType = new ObjectType(['fields' => ['theNumber' => ['type' => Type::int()]], 'name' => 'NumberHolder']);
     $schema = new Schema(['query' => new ObjectType(['fields' => ['numberHolder' => ['type' => $numberHolderType]], 'name' => 'Query']), 'mutation' => new ObjectType(['fields' => ['immediatelyChangeTheNumber' => ['type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], 'resolve' => function (Root $obj, $args) {
         return $obj->immediatelyChangeTheNumber($args['newNumber']);
     }], 'promiseToChangeTheNumber' => ['type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], 'resolve' => function (Root $obj, $args) {
         return $obj->promiseToChangeTheNumber($args['newNumber']);
     }], 'failToChangeTheNumber' => ['type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], 'resolve' => function (Root $obj, $args) {
         return $obj->failToChangeTheNumber($args['newNumber']);
     }], 'promiseAndFailToChangeTheNumber' => ['type' => $numberHolderType, 'args' => ['newNumber' => ['type' => Type::int()]], 'resolve' => function (Root $obj, $args) {
         return $obj->promiseAndFailToChangeTheNumber($args['newNumber']);
     }]], 'name' => 'Mutation'])]);
     return $schema;
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:14,代码来源:MutationsTest.php

示例13: testCoercesOutputInt

 public function testCoercesOutputInt()
 {
     $intType = Type::int();
     $this->assertSame(1, $intType->coerce(1));
     $this->assertSame(0, $intType->coerce(0));
     $this->assertSame(0, $intType->coerce(0.1));
     $this->assertSame(1, $intType->coerce(1.1));
     $this->assertSame(-1, $intType->coerce(-1.1));
     $this->assertSame(100000, $intType->coerce(100000.0));
     $this->assertSame(null, $intType->coerce(1.0E+100));
     $this->assertSame(null, $intType->coerce(-1.0E+100));
     $this->assertSame(-1, $intType->coerce('-1.1'));
     $this->assertSame(null, $intType->coerce('one'));
     $this->assertSame(0, $intType->coerce(false));
 }
开发者ID:rtuin,项目名称:graphql-php,代码行数:15,代码来源:ScalarCoercionTest.php

示例14: 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

示例15: getConfig

 function getConfig($config)
 {
     return array_replace_recursive(['description' => 'An image from the ACF plugin', 'fields' => ['caption' => ['description' => 'Image caption'], 'title' => ['description' => 'Image title'], 'url' => ['description' => 'Image path', 'args' => ['size' => ['description' => 'size of the image', 'type' => Type::string()]], 'resolve' => function ($field, $args) {
         $args += ['size' => 'medium'];
         $size = $args['size'];
         if ($size == 'full') {
             return $field['url'];
         }
         return $field['sizes'][$size];
     }], 'width' => ['type' => Type::int(), 'description' => 'Image width', 'args' => ['size' => ['description' => 'size of the image', 'type' => Type::string()]], 'resolve' => function ($field) {
         $args += ['size' => 'medium'];
         $size = $args['size'];
         return $field['sizes'][$size . '-width'];
     }], 'height' => ['type' => Type::int(), 'description' => 'Image width', 'args' => ['size' => ['description' => 'size of the image', 'type' => Type::string()]], 'resolve' => function ($post) {
         $args += ['size' => 'medium'];
         $size = $args['size'];
         return $field['sizes'][$size . '-height'];
     }]]], parent::getConfig($config));
 }
开发者ID:dobbit,项目名称:graphql-wp,代码行数:19,代码来源:ACFImage.php


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