本文整理汇总了PHP中GraphQL\Type\Definition\Type::listOf方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::listOf方法的具体用法?PHP Type::listOf怎么用?PHP Type::listOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphQL\Type\Definition\Type
的用法示例。
在下文中一共展示了Type::listOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDefaultSchema
/**
* @return Schema
*/
protected function getDefaultSchema()
{
$Being = new InterfaceType(['name' => 'Being', 'fields' => ['name' => ['type' => Type::string()]]]);
$Pet = new InterfaceType(['name' => 'Pet', 'fields' => ['name' => ['type' => Type::string()]]]);
$DogCommand = new EnumType(['name' => 'DogCommand', 'values' => ['SIT' => ['value' => 0], 'HEEL' => ['value' => 1], 'DOWN' => ['value' => 3]]]);
$Dog = new ObjectType(['name' => 'Dog', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'barkVolume' => ['type' => Type::int()], 'barks' => ['type' => Type::boolean()], 'doesKnowCommand' => ['type' => Type::boolean(), 'args' => ['dogCommand' => ['type' => $DogCommand]]], 'isHousetrained' => ['type' => Type::boolean(), 'args' => ['atOtherHomes' => ['type' => Type::boolean(), 'defaultValue' => true]]], 'isAtLocation' => ['type' => Type::boolean(), 'args' => ['x' => ['type' => Type::int()], 'y' => ['type' => Type::int()]]]], 'interfaces' => [$Being, $Pet]]);
$FurColor = new EnumType(['name' => 'FurColor', 'values' => ['BROWN' => ['value' => 0], 'BLACK' => ['value' => 1], 'TAN' => ['value' => 2], 'SPOTTED' => ['value' => 3]]]);
$Cat = new ObjectType(['name' => 'Cat', 'fields' => ['name' => ['type' => Type::string()], 'nickname' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()], 'meowVolume' => ['type' => Type::int()], 'furColor' => ['type' => $FurColor]], 'interfaces' => [$Being, $Pet]]);
$CatOrDog = new UnionType(['name' => 'CatOrDog', 'types' => [$Dog, $Cat], 'resolveType' => function ($value) {
// not used for validation
return null;
}]);
$Intelligent = new InterfaceType(['name' => 'Intelligent', 'fields' => ['iq' => ['type' => Type::int()]]]);
$Human = $this->humanType = new ObjectType(['name' => 'Human', 'interfaces' => [$Being, $Intelligent], 'fields' => ['name' => ['args' => ['surname' => ['type' => Type::boolean()]], 'type' => Type::string()], 'pets' => ['type' => Type::listOf($Pet)], 'relatives' => ['type' => function () {
return Type::listOf($this->humanType);
}]]]);
$Alien = new ObjectType(['name' => 'Alien', 'interfaces' => [$Being, $Intelligent], 'fields' => ['iq' => ['type' => Type::int()], 'numEyes' => ['type' => Type::int()]]]);
$DogOrHuman = new UnionType(['name' => 'DogOrHuman', 'types' => [$Dog, $Human], 'resolveType' => function () {
// not used for validation
return null;
}]);
$HumanOrAlien = new UnionType(['name' => 'HumanOrAlien', 'types' => [$Human, $Alien], 'resolveType' => function () {
// not used for validation
return null;
}]);
$ComplexInput = new InputObjectType(['name' => 'ComplexInput', 'fields' => ['requiredField' => ['type' => Type::nonNull(Type::boolean())], 'intField' => ['type' => Type::int()], 'stringField' => ['type' => Type::string()], 'booleanField' => ['type' => Type::boolean()], 'stringListField' => ['type' => Type::listOf(Type::string())]]]);
$ComplicatedArgs = new ObjectType(['name' => 'ComplicatedArgs', 'fields' => ['intArgField' => ['type' => Type::string(), 'args' => ['intArg' => ['type' => Type::int()]]], 'nonNullIntArgField' => ['type' => Type::string(), 'args' => ['nonNullIntArg' => ['type' => Type::nonNull(Type::int())]]], 'stringArgField' => ['type' => Type::string(), 'args' => ['stringArg' => ['type' => Type::string()]]], 'booleanArgField' => ['type' => Type::string(), 'args' => ['booleanArg' => ['type' => Type::boolean()]]], 'enumArgField' => ['type' => Type::string(), 'args' => ['enumArg' => ['type' => $FurColor]]], 'floatArgField' => ['type' => Type::string(), 'args' => ['floatArg' => ['type' => Type::float()]]], 'idArgField' => ['type' => Type::string(), 'args' => ['idArg' => ['type' => Type::id()]]], 'stringListArgField' => ['type' => Type::string(), 'args' => ['stringListArg' => ['type' => Type::listOf(Type::string())]]], 'complexArgField' => ['type' => Type::string(), 'args' => ['complexArg' => ['type' => $ComplexInput]]], 'multipleReqs' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())]]], 'multipleOpts' => ['type' => Type::string(), 'args' => ['opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]], 'multipleOptAndReq' => ['type' => Type::string(), 'args' => ['req1' => ['type' => Type::nonNull(Type::int())], 'req2' => ['type' => Type::nonNull(Type::int())], 'opt1' => ['type' => Type::int(), 'defaultValue' => 0], 'opt2' => ['type' => Type::int(), 'defaultValue' => 0]]]]]);
$queryRoot = new ObjectType(['name' => 'QueryRoot', 'fields' => ['human' => ['args' => ['id' => ['type' => Type::id()]], 'type' => $Human], 'alien' => ['type' => $Alien], 'dog' => ['type' => $Dog], 'cat' => ['type' => $Cat], 'pet' => ['type' => $Pet], 'catOrDog' => ['type' => $CatOrDog], 'dogOrHuman' => ['type' => $DogOrHuman], 'humanOrAlien' => ['type' => $HumanOrAlien], 'complicatedArgs' => ['type' => $ComplicatedArgs]]]);
$defaultSchema = new Schema($queryRoot);
return $defaultSchema;
}
示例2: setUp
public function setUp()
{
$NamedType = new InterfaceType(['name' => 'Named', 'fields' => ['name' => ['type' => Type::string()]]]);
$DogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'barks' => ['type' => Type::boolean()]], 'isTypeOf' => function ($value) {
return $value instanceof Dog;
}]);
$CatType = new ObjectType(['name' => 'Cat', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]], 'isTypeOf' => function ($value) {
return $value instanceof Cat;
}]);
$PetType = new UnionType(['name' => 'Pet', 'types' => [$DogType, $CatType], 'resolveType' => function ($value) use($DogType, $CatType) {
if ($value instanceof Dog) {
return $DogType;
}
if ($value instanceof Cat) {
return $CatType;
}
}]);
$PersonType = new ObjectType(['name' => 'Person', 'interfaces' => [$NamedType], 'fields' => ['name' => ['type' => Type::string()], 'pets' => ['type' => Type::listOf($PetType)], 'friends' => ['type' => Type::listOf($NamedType)]], 'isTypeOf' => function ($value) {
return $value instanceof Person;
}]);
$this->schema = new Schema($PersonType);
$this->garfield = new Cat('Garfield', false);
$this->odie = new Dog('Odie', true);
$this->liz = new Person('Liz');
$this->john = new Person('John', [$this->garfield, $this->odie], [$this->liz, $this->odie]);
}
示例3: resolveType
/**
* @param string $name
* @return Type
*/
public function resolveType($name)
{
if (preg_match('#^(.+)\\!$#', $name, $regs)) {
return Type::nonNull($this->resolveType($regs[1]));
}
if (preg_match('#^\\[(.+)\\]$#', $name, $regs)) {
return Type::listOf($this->resolveType($regs[1]));
}
switch ($name) {
case Type::INT:
return Type::int();
case Type::STRING:
return Type::string();
case Type::BOOLEAN:
return Type::boolean();
case Type::FLOAT:
return Type::float();
case Type::ID:
return Type::id();
default:
if (!isset($this->types[$name])) {
throw new \InvalidArgumentException(sprintf('Type "%s" is not defined', $name));
}
return $this->types[$name];
}
}
示例4: testFieldSelection
public function testFieldSelection()
{
$image = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
$article = null;
$author = new ObjectType(['name' => 'Author', 'fields' => function () use($image, &$article) {
return ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['type' => $image, 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]], 'recentArticle' => ['type' => $article]];
}]);
$reply = new ObjectType(['name' => 'Reply', 'fields' => ['author' => ['type' => $author], 'body' => ['type' => Type::string()]]]);
$article = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::string()], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $author], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()], 'image' => ['type' => $image], 'replies' => ['type' => Type::listOf($reply)]]]);
$doc = '
query Test {
article {
author {
name
pic {
url
width
}
}
image {
width
height
}
replies {
body
author {
id
name
pic {
url
width
}
recentArticle {
id
title
body
}
}
}
}
}
';
$expectedDefaultSelection = ['author' => true, 'image' => true, 'replies' => true];
$expectedDeepSelection = ['author' => ['name' => true, 'pic' => ['url' => true, 'width' => true]], 'image' => ['width' => true, 'height' => true], 'replies' => ['body' => true, 'author' => ['id' => true, 'name' => true, 'pic' => ['url' => true, 'width' => true], 'recentArticle' => ['id' => true, 'title' => true, 'body' => true]]]];
$hasCalled = false;
$actualDefaultSelection = null;
$actualDeepSelection = null;
$blogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $article, 'resolve' => function ($value, $args, $context, ResolveInfo $info) use(&$hasCalled, &$actualDefaultSelection, &$actualDeepSelection) {
$hasCalled = true;
$actualDefaultSelection = $info->getFieldSelection();
$actualDeepSelection = $info->getFieldSelection(5);
return null;
}]]]);
$schema = new Schema(['query' => $blogQuery]);
$result = GraphQL::execute($schema, $doc);
$this->assertTrue($hasCalled);
$this->assertEquals(['data' => ['article' => null]], $result);
$this->assertEquals($expectedDefaultSelection, $actualDefaultSelection);
$this->assertEquals($expectedDeepSelection, $actualDeepSelection);
}
示例5: baseFields
/**
* Fields that exist on every connection.
*
* @return array
*/
protected function baseFields()
{
return ['pageInfo' => ['type' => Type::nonNull($this->pageInfoType), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
return $collection;
}], 'edges' => ['type' => Type::listOf($this->edgeType), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
return $this->injectCursor($collection);
}]];
}
示例6: baseFields
/**
* Fields that exist on every connection.
*
* @return array
*/
protected function baseFields()
{
$type = $this->type ?: $this->type();
return ['pageInfo' => ['type' => Type::nonNull(GraphQL::type('pageInfo')), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
return $collection;
}], 'edges' => ['type' => Type::listOf($this->buildEdgeType($this->name, $type)), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
return $this->injectCursor($collection);
}]];
}
示例7: testHandlesNonNullListOfNonNulls
/**
* @describe [T!]!
*/
public function testHandlesNonNullListOfNonNulls()
{
$type = Type::nonNull(Type::listOf(Type::nonNull(Type::int())));
// Contains values
$this->check($type, [1, 2], ['data' => ['nest' => ['test' => [1, 2]]]]);
// Contains null
$this->check($type, [1, null, 2], ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
// Returns null
$this->check($type, null, ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
}
示例8: withModifiers
private function withModifiers($types)
{
return array_merge(Utils::map($types, function ($type) {
return Type::listOf($type);
}), Utils::map($types, function ($type) {
return Type::nonNull($type);
}), Utils::map($types, function ($type) {
return Type::nonNull(Type::listOf($type));
}));
}
示例9: pluralIdentifyingRootField
/**
* Returns configuration for Plural identifying root field
*
* type PluralIdentifyingRootFieldConfig = {
* argName: string,
* inputType: GraphQLInputType,
* outputType: GraphQLOutputType,
* resolveSingleInput: (input: any, info: GraphQLResolveInfo) => ?any,
* description?: ?string,
* };
*
* @param array $config
* @return array
*/
public static function pluralIdentifyingRootField(array $config)
{
$inputArgs = [];
$argName = self::getArrayValue($config, 'argName');
$inputArgs[$argName] = ['type' => Type::nonNull(Type::listOf(Type::nonNull(self::getArrayValue($config, 'inputType'))))];
return ['description' => isset($config['description']) ? $config['description'] : null, 'type' => Type::listOf(self::getArrayValue($config, 'outputType')), 'args' => $inputArgs, 'resolve' => function ($obj, $args, $context, ResolveInfo $info) use($argName, $config) {
$inputs = $args[$argName];
return array_map(function ($input) use($config, $context, $info) {
return call_user_func(self::getArrayValue($config, 'resolveSingleInput'), $input, $context, $info);
}, $inputs);
}];
}
示例10: testExecutesUsingASchema
public function testExecutesUsingASchema()
{
$BlogArticle = null;
$BlogImage = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
$BlogAuthor = new ObjectType(['name' => 'Author', 'fields' => ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]], 'type' => $BlogImage, 'resolve' => function ($obj, $args) {
return $obj['pic']($args['width'], $args['height']);
}], 'recentArticle' => ['type' => function () use(&$BlogArticle) {
return $BlogArticle;
}]]]);
$BlogArticle = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::nonNull(Type::string())], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $BlogAuthor], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()], 'keywords' => ['type' => Type::listOf(Type::string())]]]);
$BlogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $BlogArticle, 'args' => ['id' => ['type' => Type::id()]], 'resolve' => function ($_, $args) {
return $this->article($args['id']);
}], 'feed' => ['type' => Type::listOf($BlogArticle), 'resolve' => function () {
return [$this->article(1), $this->article(2), $this->article(3), $this->article(4), $this->article(5), $this->article(6), $this->article(7), $this->article(8), $this->article(9), $this->article(10)];
}]]]);
$BlogSchema = new Schema($BlogQuery);
$request = '
{
feed {
id,
title
},
article(id: "1") {
...articleFields,
author {
id,
name,
pic(width: 640, height: 480) {
url,
width,
height
},
recentArticle {
...articleFields,
keywords
}
}
}
}
fragment articleFields on Article {
id,
isPublished,
title,
body,
hidden,
notdefined
}
';
$expected = ['data' => ['feed' => [['id' => '1', 'title' => 'My Article 1'], ['id' => '2', 'title' => 'My Article 2'], ['id' => '3', 'title' => 'My Article 3'], ['id' => '4', 'title' => 'My Article 4'], ['id' => '5', 'title' => 'My Article 5'], ['id' => '6', 'title' => 'My Article 6'], ['id' => '7', 'title' => 'My Article 7'], ['id' => '8', 'title' => 'My Article 8'], ['id' => '9', 'title' => 'My Article 9'], ['id' => '10', 'title' => 'My Article 10']], 'article' => ['id' => '1', 'isPublished' => true, 'title' => 'My Article 1', 'body' => 'This is a post', 'author' => ['id' => '123', 'name' => 'John Smith', 'pic' => ['url' => 'cdn://123', 'width' => 640, 'height' => 480], 'recentArticle' => ['id' => '1', 'isPublished' => true, 'title' => 'My Article 1', 'body' => 'This is a post', 'keywords' => ['foo', 'bar', '1', 'true', null]]]]]];
$this->assertEquals($expected, Executor::execute($BlogSchema, Parser::parse($request))->toArray());
}
示例11: buildHumanType
public static function buildHumanType()
{
if (null !== self::$humanType) {
return self::$humanType;
}
self::$humanType = new ObjectType(['name' => 'Human', 'fields' => function () {
return ['firstName' => ['type' => Type::nonNull(Type::string())], 'dogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(self::buildDogType()))), 'complexity' => function ($childrenComplexity, $args) {
$complexity = isset($args['name']) ? 1 : 10;
return $childrenComplexity + $complexity;
}, 'args' => ['name' => ['type' => Type::string()]]]];
}]);
return self::$humanType;
}
示例12: createConnectionType
/**
* Returns a GraphQLObjectType for a connection with the given name,
* and whose nodes are of the specified type.
*
* @return ObjectType
*/
public static function createConnectionType(array $config)
{
if (!array_key_exists('nodeType', $config)) {
throw new \InvalidArgumentException('Connection config needs to have at least a node definition');
}
$nodeType = $config['nodeType'];
$name = array_key_exists('name', $config) ? $config['name'] : $nodeType->name;
$connectionFields = array_key_exists('connectionFields', $config) ? $config['connectionFields'] : [];
$edgeType = array_key_exists('edgeType', $config) ? $config['edgeType'] : null;
$connectionType = new ObjectType(['name' => $name . 'Connection', 'description' => 'A connection to a list of items.', 'fields' => function () use($edgeType, $connectionFields, $config) {
return array_merge(['pageInfo' => ['type' => Type::nonNull(self::pageInfoType()), 'description' => 'Information to aid in pagination.'], 'edges' => ['type' => Type::listOf($edgeType ?: self::createEdgeType($config)), 'description' => 'Information to aid in pagination']], self::resolveMaybeThunk($connectionFields));
}]);
return $connectionType;
}
示例13: testIntrospectsOnInputObject
/**
* @it introspects on input object
*/
function testIntrospectsOnInputObject()
{
$TestInputObject = new InputObjectType(['name' => 'TestInputObject', 'fields' => ['a' => ['type' => Type::string(), 'defaultValue' => 'foo'], 'b' => ['type' => Type::listOf(Type::string())]]]);
$TestType = new ObjectType(['name' => 'TestType', 'fields' => ['field' => ['type' => Type::string(), 'args' => ['complex' => ['type' => $TestInputObject]], 'resolve' => function ($_, $args) {
return json_encode($args['complex']);
}]]]);
$schema = new Schema(['query' => $TestType]);
$request = '
{
__schema {
types {
kind
name
inputFields {
name
type { ...TypeRef }
defaultValue
}
}
}
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
';
$expectedFragment = ['kind' => 'INPUT_OBJECT', 'name' => 'TestInputObject', 'inputFields' => [['name' => 'a', 'type' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null], 'defaultValue' => '"foo"'], ['name' => 'b', 'type' => ['kind' => 'LIST', 'name' => null, 'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null]], 'defaultValue' => null]]];
$result = GraphQL::execute($schema, $request);
$result = $result['data']['__schema']['types'];
// $this->assertEquals($expectedFragment, $result[1]);
$this->assertContains($expectedFragment, $result);
}
示例14: testSerializesToEmptyObjectVsEmptyArray
/**
* @see https://github.com/webonyx/graphql-php/issues/59
*/
public function testSerializesToEmptyObjectVsEmptyArray()
{
$iface = null;
$a = new ObjectType(['name' => 'A', 'fields' => ['id' => Type::id()], 'interfaces' => function () use(&$iface) {
return [$iface];
}]);
$b = new ObjectType(['name' => 'B', 'fields' => ['id' => Type::id()], 'interfaces' => function () use(&$iface) {
return [$iface];
}]);
$iface = new InterfaceType(['name' => 'Iface', 'fields' => ['id' => Type::id()], 'resolveType' => function ($v) use($a, $b) {
return $v['type'] === 'A' ? $a : $b;
}]);
$schema = new Schema(['query' => new ObjectType(['name' => 'Query', 'fields' => ['ab' => Type::listOf($iface)]]), 'types' => [$a, $b]]);
$data = ['ab' => [['id' => 1, 'type' => 'A'], ['id' => 2, 'type' => 'A'], ['id' => 3, 'type' => 'B'], ['id' => 4, 'type' => 'B']]];
$query = Parser::parse('
{
ab {
... on A{
id
}
}
}
');
$result = Executor::execute($schema, $query, $data, null);
$this->assertEquals(['data' => ['ab' => [['id' => '1'], ['id' => '2'], new \stdClass(), new \stdClass()]]], $result->toArray());
}
示例15: build
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;
}