int() public static method

public static int ( ) : IntType
return IntType
 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]);
 }
Esempio n. 2
0
 /**
  * @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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * @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];
     }
 }
Esempio n. 5
0
    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);
    }
Esempio n. 6
0
 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]);
 }
Esempio n. 7
0
 /**
  * @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)])]]);
 }
Esempio n. 8
0
 /**
  * @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!'));
 }
 /**
  * @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));
 }
    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());
    }
Esempio n. 11
0
 /**
  * @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());
     }
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 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));
 }
Esempio n. 14
0
 /**
  * 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;
     }]];
 }
Esempio n. 15
0
 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));
 }
Esempio n. 16
0
 public function setup()
 {
     $this->simpleMutation = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Type::int()]], 'mutateAndGetPayload' => function () {
         return ['result' => 1];
     }]);
     $this->simpleMutationWithThunkFields = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutationWithThunkFields', 'inputFields' => function () {
         return ['inputData' => ['type' => Type::int()]];
     }, 'outputFields' => function () {
         return ['result' => ['type' => Type::int()]];
     }, 'mutateAndGetPayload' => function ($inputData) {
         return ['result' => $inputData['inputData']];
     }]);
     $userType = new ObjectType(['name' => 'User', 'fields' => ['name' => ['type' => Type::string()]]]);
     $this->edgeMutation = Mutation::mutationWithClientMutationId(['name' => 'EdgeMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Connection::createEdgeType(['nodeType' => $userType])]], 'mutateAndGetPayload' => function () {
         return ['result' => ['node' => ['name' => 'Robert'], 'cursor' => 'SWxvdmVHcmFwaFFM']];
     }]);
     $this->mutation = new ObjectType(['name' => 'Mutation', 'fields' => ['simpleMutation' => $this->simpleMutation, 'simpleMutationWithThunkFields' => $this->simpleMutationWithThunkFields, 'edgeMutation' => $this->edgeMutation]]);
     $this->schema = new Schema(['mutation' => $this->mutation, 'query' => $this->mutation]);
 }
Esempio n. 17
0
 public static function build()
 {
     $ValueType = new ObjectType(['name' => 'Value', 'description' => 'Value', 'fields' => ['id' => ['type' => new NonNull(Type::int()), 'description' => 'The id of the value.'], 'atri_id' => ['type' => Type::int(), 'description' => 'The attribute of the value.'], 'atri_name' => ['type' => Type::string(), 'description' => 'Attribute name'], 'atri_tag' => ['type' => Type::string(), 'description' => 'Attribute tag'], 'atri_type' => ['type' => Type::string(), 'description' => 'Attribute Type'], 'atri_language' => ['type' => Type::string(), 'description' => 'Attribute language'], 'inst_id' => ['type' => Type::int(), 'description' => 'The instance_id in which the value is contained.'], 'text_val' => ['type' => Type::string(), 'description' => 'The text_val of the value.'], 'num_val' => ['type' => Type::string(), 'description' => 'The num_val of the value.'], 'date_val' => ['type' => Type::string(), 'description' => 'The date_val of the value.'], 'img_info' => ['type' => Type::string(), 'description' => 'Image info of the value, only valid for images.'], 'is_detail' => ['type' => Type::string(), 'description' => 'Is detail? Y or N'], 'cache_time' => ['type' => Type::int(), 'description' => 'Cache Time'], 'cache_status' => ['type' => Type::string(), 'description' => 'Cache status (hit|miss)']]]);
     $RelationType = new ObjectType(['name' => 'Relation', 'description' => 'Relation Instance', 'fields' => ['id' => ['type' => new NonNull(Type::int()), 'description' => 'The id of the relation.'], 'tag' => ['type' => new NonNull(Type::string()), 'description' => 'Relation tag'], 'language' => ['type' => Type::string(), 'description' => 'Relation language'], 'direction' => ['type' => new NonNull(Type::string()), 'description' => 'Relation direction'], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'inst_id' => ['type' => Type::int(), 'description' => 'initial inst_id, the driver instance'], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format'], 'instances' => ['type' => function () use(&$InstanceType) {
         return Type::listOf($InstanceType);
     }, 'description' => 'The related children or parents of this relation.', 'args' => ['filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($relation, $args) {
         //echo "ARGS ABANS DEL GETRELATED\n";
         //print_r($relation['args']);
         //echo "PARENT ARGS ABANS DEL GETRELATED\n";
         $insts = EditoraData::getRelated($relation['direction'], $relation['id'], $relation['inst_id'], $relation['args'], null);
         //echo "Instancies despres del GetRelated\n";
         //print_r($insts);
         if ($insts && !empty($insts[0])) {
             return $insts;
         }
         return null;
     }]]]);
     $InstanceListType = new ObjectType(['name' => 'instance_list', 'description' => 'Instance List', 'fields' => ['ids' => ['type' => new NonNull(Type::string()), 'description' => 'The ids of the instances.'], 'language' => ['type' => Type::string(), 'description' => 'Class language'], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format'], 'instances' => ['type' => function () use(&$InstanceType) {
         return Type::listOf($InstanceType);
     }, 'description' => 'The instances list', 'args' => ['filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance_list, $args) {
         //echo "instance resolve\n";
         //print_r($class);
         $insts = EditoraData::getInstancesList($args, $instance_list['args']);
         //echo "attrs\n";
         //print_r($insts);
         if ($insts) {
             return $insts;
         }
         return null;
     }]]]);
     $ClassType = new ObjectType(['name' => 'class', 'description' => 'Class', 'fields' => ['class_id' => ['type' => new NonNull(Type::int()), 'description' => 'The id of the class.'], 'tag' => ['type' => new NonNull(Type::string()), 'description' => 'Class tag'], 'language' => ['type' => Type::string(), 'description' => 'Class language'], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format'], 'instances' => ['type' => function () use(&$InstanceType) {
         return Type::listOf($InstanceType);
     }, 'description' => 'The instances of this class.', 'args' => ['filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($class, $args) {
         //echo "instance resolve\n";
         //print_r($class);
         $insts = EditoraData::getInstacesOfClass($class['class_id'], $class, $args, $class['args']);
         //echo "attrs\n";
         //print_r($insts);
         if ($insts) {
             return $insts;
         }
         return null;
     }]]]);
     $SearchType = new ObjectType(['name' => 'search', 'description' => 'Search', 'fields' => ['query' => ['type' => new NonNull(Type::string()), 'description' => 'search query'], 'class_id' => ['type' => Type::int(), 'description' => 'The id of the class.'], 'tag' => ['type' => Type::string(), 'description' => 'class tag'], 'language' => ['type' => Type::string(), 'description' => 'Relation language'], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format'], 'instances' => ['type' => function () use(&$InstanceType) {
         return Type::listOf($InstanceType);
     }, 'description' => 'The instances of this class.', 'args' => ['filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($search, $args) {
         //echo "instance resolve\n";
         //print_r($search);
         $insts = EditoraData::getInstacesOfSearch($search['query'], $search, $args, $search['args']);
         //echo "attrs\n";
         //print_r($insts);
         if ($insts) {
             return $insts;
         }
         return null;
     }]]]);
     $InstanceType = new ObjectType(['name' => 'Instance', 'description' => 'Instance of any class', 'fields' => ['id' => ['type' => new NonNull(Type::int()), 'description' => 'The id of instance.'], 'class_id' => ['type' => Type::int(), 'description' => 'The class_id of instance.'], 'class_name' => ['type' => Type::string(), 'description' => 'The class_name of instance.'], 'class_tag' => ['type' => Type::string(), 'description' => 'The class_tag of instance.'], 'key_fields' => ['type' => Type::string(), 'description' => 'The internal name of the instance.'], 'nom_intern' => ['type' => Type::string(), 'description' => 'The internal name of the instance.'], 'status' => ['type' => Type::string(), 'description' => 'The status of the instance.'], 'publishing_begins' => ['type' => Type::string(), 'description' => 'The publishing start of the instance.'], 'publishing_ends' => ['type' => Type::string(), 'description' => 'The publishing start of the instance.'], 'creation_date' => ['type' => Type::string(), 'description' => 'The creation of the instance.'], 'update_date' => ['type' => Type::string(), 'description' => 'The update of the instance.'], 'update_timestamp' => ['type' => Type::int(), 'description' => 'The update of the instance in unix timestamp.'], 'nice_url' => ['type' => Type::string(), 'description' => 'The niceurl of the instance.'], 'link' => ['type' => Type::string(), 'description' => 'The link to the the instance.'], 'all_values' => ['type' => Type::listOf($ValueType), 'description' => 'The attributes of the instance.', 'args' => ['filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()]], 'resolve' => function ($instance, $args) {
         //print_r($args);
         //echo "Instance in EditoraSchema vaig a treure els values\n";
         //print_r($instance);
         if (isset($instance) && isset($instance['id']) && isset($instance['update_timestamp']) && isset($instance['args'])) {
             $attrs = EditoraData::getValues($instance['id'], $instance['update_timestamp'], $args, $instance['args']);
             //print_r($attrs);
             if ($attrs) {
                 return $attrs;
             }
         }
         return null;
     }], 'relation1' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         //echo "aqui tinc aquests args\n";
         //print_r($args);
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation2' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation3' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation4' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation5' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation6' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation7' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation8' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation9' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation10' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation11' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation12' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation13' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation14' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }], 'relation15' => ['type' => Type::listOf($RelationType), 'description' => 'The children of the instance.', 'args' => ['tag' => ['name' => 'tag', 'description' => 'tag of the relation', 'type' => new NonNull(Type::String())], 'alias' => ['name' => 'alias', 'description' => 'alias of the relation', 'type' => Type::String()], 'limit' => ['name' => 'limit', 'description' => 'number of children to get, default 1000', 'type' => Type::Int()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'filter' => ['name' => 'filter', 'description' => 'filter some fields all|detail|resume default all', 'type' => Type::String()], 'direction' => ['name' => 'direction', 'description' => 'force a direction, by default is children, use parents if you want to override', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($instance, $args) {
         if (isset($instance) && isset($instance['id']) && isset($instance['class_id']) && isset($instance['args'])) {
             $related = EditoraData::getRelations($instance['id'], $instance['class_id'], $args, $instance['args']);
             //print_r($related);
             if ($related) {
                 return $related;
             }
         }
         return null;
     }]]]);
     $queryType = new ObjectType(['name' => 'Query', 'fields' => ['instance' => ['type' => $InstanceType, 'args' => ['id' => ['name' => 'id', 'description' => 'id of the Instance', 'type' => Type::Int()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($root, $args) {
         $instance = EditoraData::getInstance($args);
         if ($instance) {
             return $instance;
         }
         return null;
         //return isset($instance[$args['id']]) ? $instance[$args['id']] : null;
     }], 'class' => ['type' => $ClassType, 'args' => ['class_id' => ['name' => 'class_id', 'description' => 'id of the Class', 'type' => Type::Int()], 'tag' => ['name' => 'tag', 'description' => 'tag of the Class', 'type' => Type::String()], 'order' => ['name' => 'order', 'description' => 'order class instances by order criteria, update_date|publishing_begins|inst_id|key_fields default publishing_begins', 'type' => Type::String()], 'order_direction' => ['name' => 'order_direction', 'description' => 'direction of the order by clause, desc|asc defaults to asc', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($root, $args) {
         $class = EditoraData::getClass($args);
         //echo "Al query type !!!$class!!!\n";
         //print_r($class);
         //												die;
         if ($class && !empty($class)) {
             return $class;
         }
         return null;
         //return isset($instance[$args['id']]) ? $instance[$args['id']] : null;
     }], 'instances_list' => ['type' => $InstanceListType, 'args' => ['ids' => ['name' => 'ids', 'description' => 'list of ids in format (1,2,3...)', 'type' => Type::String()], 'order' => ['name' => 'order', 'description' => 'order class instances by order criteria, update_date|publishing_begins|inst_id|key_fields default publishing_begins', 'type' => Type::String()], 'order_direction' => ['name' => 'order_direction', 'description' => 'direction of the order by clause, desc|asc defaults to asc', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($root, $args) {
         $instance_list = EditoraData::getInstanceList($args);
         //echo "Al query type\n";
         //print_r($instance_list);
         //die;
         if ($instance_list) {
             return $instance_list;
         }
         return null;
         //return isset($instance[$args['id']]) ? $instance[$args['id']] : null;
     }], 'search' => ['type' => $SearchType, 'args' => ['query' => ['name' => 'query', 'description' => 'Query string for search', 'type' => Type::String()], 'class_id' => ['name' => 'class_id', 'description' => 'Optional id of the Class', 'type' => Type::Int()], 'tag' => ['name' => 'tag', 'description' => 'Optional tag of the class', 'type' => Type::String()], 'lang' => ['name' => 'lang', 'description' => 'Language of the extraction', 'type' => Type::String()], 'limit' => ['type' => Type::int(), 'description' => 'limit of extraction'], 'debug' => ['name' => 'debug', 'description' => 'Sets the debug flag if true', 'type' => Type::boolean()], 'preview' => ['type' => Type::boolean(), 'description' => 'Preview true or false, default false'], 'preview_date' => ['type' => Type::string(), 'description' => 'Preview date in %Y%m%d%H%i%S format']], 'resolve' => function ($root, $args) {
         $search = EditoraData::getSearch($args);
         //echo "Al query type\n";
         //print_r($search);
         //die;
         if ($search) {
             return $search;
         }
         return null;
         //return isset($instance[$args['id']]) ? $instance[$args['id']] : null;
     }]]]);
     return new Schema(['query' => $queryType, 'mutation' => null, 'types' => null]);
 }
Esempio n. 18
0
 public function testSubstitutesArgumentWithDefaultValue()
 {
     $schema = new Schema(['query' => new ObjectType(['name' => 'Type', 'fields' => ['field' => ['type' => Type::string(), 'resolve' => function ($data, $args) {
         return $args ? json_encode($args) : '';
     }, 'args' => ['a' => ['type' => Type::boolean(), 'defaultValue' => 1], 'b' => ['type' => Type::boolean(), 'defaultValue' => null], 'c' => ['type' => Type::boolean(), 'defaultValue' => 0], 'd' => ['type' => Type::int(), 'defaultValue' => false], 'e' => ['type' => Type::int(), 'defaultValue' => '0'], 'f' => ['type' => Type::int(), 'defaultValue' => 'some-string'], 'g' => ['type' => Type::boolean()], 'h' => ['type' => new InputObjectType(['name' => 'ComplexType', 'fields' => ['a' => ['type' => Type::int()], 'b' => ['type' => Type::string()]]]), 'defaultValue' => ['a' => 1, 'b' => 'test']]]]]])]);
     $query = Parser::parse('{ field }');
     $result = Executor::execute($schema, $query);
     $expected = ['data' => ['field' => '{"a":1,"b":null,"c":0,"d":false,"e":"0","f":"some-string","h":{"a":1,"b":"test"}}']];
     $this->assertEquals($expected, $result->toArray());
 }
Esempio n. 19
0
 public function testExecutesMapCallbacksIfSet()
 {
     $fooData = [['field' => '1'], ['field' => null], null, ['field' => '4']];
     $foo = new ObjectType(['name' => 'Foo', 'fields' => ['field' => ['type' => Type::string(), 'map' => function ($listOfFoo, $args, $resolveInfo) use($fooData) {
         return Utils::map($listOfFoo, function ($fooData) use($args, $resolveInfo) {
             return json_encode(['value' => $fooData['field'] === null ? null : $fooData['field'] . 'x', 'args' => $args, 'gotResolveInfo' => $resolveInfo instanceof ResolveInfo]);
         });
     }, 'args' => ['a' => ['type' => Type::boolean()], 'b' => ['type' => Type::boolean()], 'c' => ['type' => Type::int()]]]]]);
     $bar = new ObjectType(['name' => 'Bar', 'fields' => ['foo' => ['type' => Type::listOf($foo), 'resolve' => function () use($fooData) {
         return $fooData;
     }]]]);
     $schema = new Schema($bar);
     $query = Parser::parse('{ foo { field(a: true, c: 0) } }');
     $result = Executor::execute($schema, $query);
     $expected = ['data' => ['foo' => [['field' => '{"value":"1x","args":{"a":true,"c":0},"gotResolveInfo":true}'], ['field' => '{"value":null,"args":{"a":true,"c":0},"gotResolveInfo":true}'], null, ['field' => '{"value":"4x","args":{"a":true,"c":0},"gotResolveInfo":true}']]]];
     $this->assertEquals($expected, $result->toArray());
 }
 private function getTestSchema()
 {
     $StringBox = new ObjectType(['name' => 'StringBox', 'fields' => ['scalar' => ['type' => Type::string()]]]);
     $IntBox = new ObjectType(['name' => 'IntBox', 'fields' => ['scalar' => ['type' => Type::int()]]]);
     $NonNullStringBox1 = new ObjectType(['name' => 'NonNullStringBox1', 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $NonNullStringBox2 = new ObjectType(['name' => 'NonNullStringBox2', 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $BoxUnion = new UnionType(['name' => 'BoxUnion', 'resolveType' => function () use($StringBox) {
         return $StringBox;
     }, 'types' => [$StringBox, $IntBox, $NonNullStringBox1, $NonNullStringBox2]]);
     $Connection = new ObjectType(['name' => 'Connection', 'fields' => ['edges' => ['type' => Type::listOf(new ObjectType(['name' => 'Edge', 'fields' => ['node' => ['type' => new ObjectType(['name' => 'Node', 'fields' => ['id' => ['type' => Type::id()], 'name' => ['type' => Type::string()]]])]]]))]]]);
     $schema = new Schema(new ObjectType(['name' => 'QueryRoot', 'fields' => ['boxUnion' => ['type' => $BoxUnion], 'connection' => ['type' => $Connection]]]));
     return $schema;
 }
 private function getTestSchema()
 {
     $StringBox = null;
     $IntBox = null;
     $SomeBox = null;
     $SomeBox = new InterfaceType(['name' => 'SomeBox', 'resolveType' => function () use(&$StringBox) {
         return $StringBox;
     }, 'fields' => function () use(&$SomeBox) {
         return ['deepBox' => ['type' => $SomeBox], 'unrelatedField' => ['type' => Type::string()]];
     }]);
     $StringBox = new ObjectType(['name' => 'StringBox', 'interfaces' => [$SomeBox], 'fields' => function () use(&$StringBox, &$IntBox) {
         return ['scalar' => ['type' => Type::string()], 'deepBox' => ['type' => $StringBox], 'unrelatedField' => ['type' => Type::string()], 'listStringBox' => ['type' => Type::listOf($StringBox)], 'stringBox' => ['type' => $StringBox], 'intBox' => ['type' => $IntBox]];
     }]);
     $IntBox = new ObjectType(['name' => 'IntBox', 'interfaces' => [$SomeBox], 'fields' => function () use(&$StringBox, &$IntBox) {
         return ['scalar' => ['type' => Type::int()], 'deepBox' => ['type' => $IntBox], 'unrelatedField' => ['type' => Type::string()], 'listStringBox' => ['type' => Type::listOf($StringBox)], 'stringBox' => ['type' => $StringBox], 'intBox' => ['type' => $IntBox]];
     }]);
     $NonNullStringBox1 = new InterfaceType(['name' => 'NonNullStringBox1', 'resolveType' => function () use(&$StringBox) {
         return $StringBox;
     }, 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $NonNullStringBox1Impl = new ObjectType(['name' => 'NonNullStringBox1Impl', 'interfaces' => [$SomeBox, $NonNullStringBox1], 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())], 'unrelatedField' => ['type' => Type::string()], 'deepBox' => ['type' => $SomeBox]]]);
     $NonNullStringBox2 = new InterfaceType(['name' => 'NonNullStringBox2', 'resolveType' => function () use(&$StringBox) {
         return $StringBox;
     }, 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $NonNullStringBox2Impl = new ObjectType(['name' => 'NonNullStringBox2Impl', 'interfaces' => [$SomeBox, $NonNullStringBox2], 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())], 'unrelatedField' => ['type' => Type::string()], 'deepBox' => ['type' => $SomeBox]]]);
     $Connection = new ObjectType(['name' => 'Connection', 'fields' => ['edges' => ['type' => Type::listOf(new ObjectType(['name' => 'Edge', 'fields' => ['node' => ['type' => new ObjectType(['name' => 'Node', 'fields' => ['id' => ['type' => Type::id()], 'name' => ['type' => Type::string()]]])]]]))]]]);
     $schema = new Schema(['query' => new ObjectType(['name' => 'QueryRoot', 'fields' => ['someBox' => ['type' => $SomeBox], 'connection' => ['type' => $Connection]]]), 'types' => [$IntBox, $StringBox, $NonNullStringBox1Impl, $NonNullStringBox2Impl]]);
     return $schema;
 }
Esempio n. 22
0
 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 } ] }
        ]);
      });
     */
 }
Esempio n. 23
0
 private function schema()
 {
     $dataType = new ObjectType(['name' => 'DataType', 'fields' => ['list' => ['type' => Type::listOf(Type::int())], 'listOfNonNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullList' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'listContainsNull' => ['type' => Type::listOf(Type::int())], 'listOfNonNullContainsNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullListContainsNull' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNullContainsNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'listReturnsNull' => ['type' => Type::listOf(Type::int())], 'listOfNonNullReturnsNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullListReturnsNull' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNullReturnsNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'nest' => ['type' => function () use(&$dataType) {
         return $dataType;
     }]]]);
     $schema = new Schema($dataType);
     return $schema;
 }
Esempio n. 24
0
 static function build()
 {
     $typeEnum = new EnumType(["name" => "Type", "description" => "The type of entity", "values" => ["user" => ["value" => "user"], "group" => ["value" => "group"], "object" => ["value" => "object"]]]);
     $statusEnum = new EnumType(["name" => "Status", "description" => "The status of the entity", "values" => ["ok" => ["value" => "ok"], "access_denied" => ["value" => "access_denied"], "not_found" => ["value" => "not_found"]]]);
     $voteDirectionEnum = new EnumType(["name" => "VoteType", "description" => "The type of vote", "values" => ["up" => ["value" => "up"], "down" => ["value" => "down"]]]);
     $entityInterface = new InterfaceType(["name" => "Entity", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)]], "resolveType" => function ($object) use(&$userType, &$objectType, &$groupType) {
         switch ($object["type"]) {
             case "user":
                 return $userType;
             case "object":
                 return $objectType;
             case "group":
                 return $groupType;
         }
     }]);
     $accessIdType = new ObjectType(["name" => "AccessId", "fields" => ["id" => ["type" => Type::nonNull(Type::int())], "description" => ["type" => Type::nonNull(Type::string())]]]);
     $userType = new ObjectType(["name" => "User", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "url" => ["type" => Type::string()]]]);
     $groupType = new ObjectType(["name" => "Group", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "canEdit" => ["type" => Type::boolean()], "isClosed" => ["type" => Type::boolean()], "canJoin" => ["type" => Type::boolean()], "defaultAccessId" => ["type" => Type::int()]]]);
     $objectType = new ObjectType(["name" => "Object", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "title" => ["type" => Type::string()], "subtype" => ["type" => Type::string()], "description" => ["type" => Type::string()], "url" => ["type" => Type::string()], "tags" => ["type" => Type::listOf(Type::string())], "timeCreated" => ["type" => Type::string()], "timeUpdated" => ["type" => Type::string()], "canEdit" => ["type" => Type::boolean()], "canComment" => ["type" => Type::boolean()], "accessId" => ["type" => Type::int()], "isBookmarked" => ["type" => Type::boolean(), "resolve" => function ($object) {
         return Resolver::isBookmarked($object);
     }], "votes" => ["type" => Type::int(), "resolve" => function ($object) {
         return Resolver::countVotes($object);
     }], "owner" => ["type" => $userType, "resolve" => function ($object) {
         return Resolver::getUser($object["ownerGuid"]);
     }], "comments" => ["type" => function () use(&$objectType) {
         return Type::listOf($objectType);
     }, "resolve" => function ($object) {
         return Resolver::getComments($object);
     }]]]);
     $searchListType = new ObjectType(["name" => "Search", "fields" => ["total" => ["type" => Type::nonNull(Type::int())], "results" => ["type" => Type::listOf($entityInterface)]]]);
     $entityListType = new ObjectType(["name" => "EntityList", "fields" => ["total" => ["type" => Type::nonNull(Type::int())], "canWrite" => ["type" => Type::nonNull(Type::boolean())], "entities" => ["type" => Type::listOf($entityInterface)]]]);
     $viewerType = new ObjectType(["name" => "Viewer", "description" => "The current site viewer", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "loggedIn" => ["type" => Type::nonNull(Type::boolean())], "username" => ["type" => Type::string()], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "url" => ["type" => Type::string()], "bookmarks" => ["type" => $entityListType, "args" => ["offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()]], "resolve" => "Pleio\\Resolver::getBookmarks"]]]);
     $menuItemType = new ObjectType(["name" => "MenuItem", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::nonNull(Type::string())], "link" => ["type" => Type::nonNull(Type::string())], "js" => ["type" => Type::nonNull(Type::boolean())]]]);
     $siteType = new ObjectType(["name" => "Site", "description" => "The current site", "fields" => ["id" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::nonNull(Type::string())], "menu" => ["type" => Type::listOf($menuItemType)], "accessIds" => ["type" => Type::listOf($accessIdType)], "defaultAccessId" => ["type" => Type::nonNull(Type::int())]]]);
     $queryType = new ObjectType(["name" => "Query", "fields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"], "entity" => ["type" => $entityInterface, "args" => ["guid" => ["type" => Type::nonNull(Type::string())]], "resolve" => "Pleio\\Resolver::getEntity"], "search" => ["type" => $searchListType, "args" => ["q" => ["type" => Type::nonNull(Type::string())], "offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()]], "resolve" => "Pleio\\Resolver::search"], "entities" => ["type" => $entityListType, "args" => ["offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()], "type" => ["type" => $typeEnum], "subtype" => ["type" => Type::string()], "containerGuid" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "resolve" => "Pleio\\Resolver::getEntities"], "site" => ["type" => $siteType, "resolve" => "Pleio\\Resolver::getSite"]]]);
     $loginMutation = Relay::mutationWithClientMutationId(["name" => "login", "inputFields" => ["username" => ["type" => Type::nonNull(Type::string())], "password" => ["type" => Type::nonNull(Type::string())], "rememberMe" => ["type" => Type::boolean()]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::login"]);
     $logoutMutation = Relay::mutationWithClientMutationId(["name" => "logout", "inputFields" => [], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::logout"]);
     $registerMutation = Relay::mutationWithClientMutationId(["name" => "register", "inputFields" => ["name" => ["type" => Type::nonNull(Type::string())], "email" => ["type" => Type::nonNull(Type::string())], "password" => ["type" => Type::nonNull(Type::string())], "newsletter" => ["type" => Type::boolean()], "terms" => ["type" => Type::boolean()]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::register"]);
     $forgotPasswordMutation = Relay::mutationWithClientMutationId(["name" => "forgotPassword", "inputFields" => ["username" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["status" => ["type" => Type::nonNull($statusEnum), "resolve" => function ($return) {
         return $return["status"];
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::forgotPassword"]);
     $forgotPasswordConfirmMutation = Relay::mutationWithClientMutationId(["name" => "forgotPasswordConfirm", "inputFields" => ["userGuid" => ["type" => Type::nonNull(Type::string())], "code" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["status" => ["type" => Type::nonNull($statusEnum), "resolve" => function ($return) {
         return $return["status"];
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::forgotPasswordConfirm"]);
     $subscribeNewsletterMutation = Relay::mutationWithClientMutationId(["name" => "subscribeNewsletter", "inputFields" => ["email" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::subscribeNewsletter"]);
     $addEntityMutation = Relay::mutationWithClientMutationId(["name" => "addEntity", "inputFields" => ["type" => ["type" => Type::nonNull($typeEnum)], "subtype" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::string()], "description" => ["type" => Type::nonNull(Type::string())], "containerGuid" => ["type" => Type::int()], "accessId" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::addEntity"]);
     $editEntityMutation = Relay::mutationWithClientMutationId(["name" => "editEntity", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::string()], "description" => ["type" => Type::nonNull(Type::string())], "accessId" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::editEntity"]);
     $deleteEntityMutation = Relay::mutationWithClientMutationId(["name" => "deleteEntity", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::deleteEntity"]);
     $bookmarkMutation = Relay::mutationWithClientMutationId(["name" => "bookmark", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string()), "description" => "The guid of the entity to bookmark."], "isAdding" => ["type" => Type::nonNull(Type::boolean()), "description" => "True when adding, false when removing."]], "outputFields" => ["object" => ["type" => Type::nonNull($objectType), "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::bookmark"]);
     $voteMutation = Relay::mutationWithClientMutationId(["name" => "vote", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string()), "description" => "The guid of the entity to bookmark."], "direction" => ["type" => Type::nonNull($voteDirectionEnum)]], "outputFields" => ["object" => ["type" => Type::nonNull($objectType), "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::vote"]);
     $mutationType = new ObjectType(["name" => "Mutation", "fields" => ["login" => $loginMutation, "logout" => $logoutMutation, "register" => $registerMutation, "forgotPassword" => $forgotPasswordMutation, "forgotPasswordConfirm" => $forgotPasswordConfirmMutation, "addEntity" => $addEntityMutation, "editEntity" => $editEntityMutation, "deleteEntity" => $deleteEntityMutation, "subscribeNewsletter" => $subscribeNewsletterMutation, "bookmark" => $bookmarkMutation, "vote" => $voteMutation]]);
     $schema = new Schema($queryType, $mutationType);
     return $schema;
 }
Esempio n. 25
0
 /**
  * Add option args to multivalued request fields.
  *
  * @param array $args
  */
 protected function addOptionArgs(&$args)
 {
     $args['start'] = ['type' => Type::int()];
     $args['limit'] = ['type' => Type::int()];
     $args['orderBy'] = ['type' => Type::string()];
     $args['orderByDirection'] = ['type' => Type::string()];
 }
Esempio n. 26
0
 public function testProhibitsPuttingNonObjectTypesInUnions()
 {
     $int = Type::int();
     $badUnionTypes = [$int, new NonNull($int), new ListOfType($int), $this->interfaceType, $this->unionType, $this->enumType, $this->inputObjectType];
     Config::enableValidation();
     foreach ($badUnionTypes as $type) {
         try {
             new UnionType(['name' => 'BadUnion', 'types' => [$type]]);
             $this->fail('Expected exception not thrown');
         } catch (\Exception $e) {
             $this->assertSame('Expecting callable or instance of GraphQL\\Type\\Definition\\ObjectType at "types:0", but got "' . get_class($type) . '"', $e->getMessage());
         }
     }
     Config::disableValidation();
 }
 /**
  * Get the default arguments for a connection.
  *
  * @return array
  */
 public static function connectionArgs()
 {
     return ['after' => ['type' => Type::string()], 'first' => ['type' => Type::int()], 'before' => ['type' => Type::string()], 'last' => ['type' => Type::int()]];
 }
Esempio n. 28
0
 /**
  * Returns node definitions
  *
  * @return array
  */
 protected function getNodeDefinitions()
 {
     if (!self::$nodeDefinition) {
         self::$nodeDefinition = Node::nodeDefinitions(function ($id, $context, ResolveInfo $info) {
             $userData = $this->getUserData();
             if (array_key_exists($id, $userData)) {
                 return $userData[$id];
             } else {
                 $photoData = $this->getPhotoData();
                 if (array_key_exists($id, $photoData)) {
                     return $photoData[$id];
                 }
             }
         }, function ($obj) {
             if (array_key_exists($obj['id'], $this->getUserData())) {
                 return self::$userType;
             } else {
                 return self::$photoType;
             }
         });
         self::$userType = new ObjectType(['name' => 'User', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'name' => ['type' => Type::string()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
         self::$photoType = new ObjectType(['name' => 'Photo', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'width' => ['type' => Type::int()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
     }
     return self::$nodeDefinition;
 }
Esempio n. 29
0
 /**
  * @return \GraphQL\Type\Definition\IntType
  */
 public static function int()
 {
     return Type::int();
 }
Esempio n. 30
-2
 /**
  * Resolve field type by column info.
  *
  * @param  string $name
  * @param  string $colType
  * @return \GraphQL\Type\Definition\Type
  */
 protected function resolveTypeByColumn($name, $colType)
 {
     $type = Type::string();
     $type->name = $this->getName() . '_String';
     if ($name === $this->model->getKeyName()) {
         $type = Type::id();
         $type->name = $this->getName() . '_ID';
     } elseif ($colType === 'integer') {
         $type = Type::int();
         $type->name = $this->getName() . '_Int';
     } elseif ($colType === 'float' || $colType === 'decimal') {
         $type = Type::float();
         $type->name = $this->getName() . '_Float';
     } elseif ($colType === 'boolean') {
         $type = Type::boolean();
         $type->name = $this->getName() . '_Boolean';
     }
     return $type;
 }