boolean() public static méthode

public static boolean ( ) : BooleanType
Résultat BooleanType
    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);
    }
 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]);
 }
 /**
  * @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];
     }
 }
Exemple #4
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;
 }
Exemple #5
0
 /**
  * @it converts boolean values to ASTs
  */
 public function testConvertsBooleanValueToASTs()
 {
     $this->assertEquals(new BooleanValue(['value' => true]), AST::astFromValue(true, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => false]), AST::astFromValue(false, Type::boolean()));
     $this->assertEquals(null, AST::astFromValue(null, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => false]), AST::astFromValue(0, Type::boolean()));
     $this->assertEquals(new BooleanValue(['value' => true]), AST::astFromValue(1, Type::boolean()));
 }
Exemple #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]);
 }
 public function testCoercesOutputBoolean()
 {
     $boolType = Type::boolean();
     $this->assertSame(true, $boolType->coerce('string'));
     $this->assertSame(false, $boolType->coerce(''));
     $this->assertSame(true, $boolType->coerce(1));
     $this->assertSame(false, $boolType->coerce(0));
     $this->assertSame(true, $boolType->coerce(true));
     $this->assertSame(false, $boolType->coerce(false));
     // TODO: how should it behaive on '0'?
 }
    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());
    }
 /**
  * Fields available on PageInfo.
  *
  * @return array
  */
 public function fields()
 {
     return ['hasNextPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating forwards, are there more items?', 'resolve' => function ($collection, $test) {
         if ($collection['total'] - $collection['first'] * $collection['currentPage'] > 0) {
             return true;
         }
         return false;
     }], 'hasPreviousPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating backwards, are there more items?', 'resolve' => function ($collection) {
         if ($collection['currentPage'] > 1) {
             return true;
         }
         return false;
     }]];
 }
Exemple #10
0
 public function setUp()
 {
     $this->objectType = new ObjectType(['name' => 'Object']);
     $this->interfaceType = new InterfaceType(['name' => 'Interface']);
     $this->unionType = new UnionType(['name' => 'Union', 'types' => [$this->objectType]]);
     $this->enumType = new EnumType(['name' => 'Enum']);
     $this->inputObjectType = new InputObjectType(['name' => 'InputObject']);
     $this->blogImage = new ObjectType(['name' => 'Image', 'fields' => ['url' => ['type' => Type::string()], 'width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]]);
     $this->blogAuthor = new ObjectType(['name' => 'Author', 'fields' => ['id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], 'pic' => ['type' => $this->blogImage, 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]]], 'recentArticle' => ['type' => function () {
         return $this->blogArticle;
     }]]]);
     $this->blogArticle = new ObjectType(['name' => 'Article', 'fields' => ['id' => ['type' => Type::string()], 'isPublished' => ['type' => Type::boolean()], 'author' => ['type' => $this->blogAuthor], 'title' => ['type' => Type::string()], 'body' => ['type' => Type::string()]]]);
     $this->blogQuery = new ObjectType(['name' => 'Query', 'fields' => ['article' => ['type' => $this->blogArticle, 'args' => ['id' => ['type' => Type::string()]]], 'feed' => ['type' => new ListOfType($this->blogArticle)]]]);
     $this->blogMutation = new ObjectType(['name' => 'Mutation', 'fields' => ['writeArticle' => ['type' => $this->blogArticle]]]);
 }
Exemple #11
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;
     }]];
 }
Exemple #12
0
 /**
  * Type fields.
  *
  * @return array
  */
 public function fields()
 {
     return ['title' => ['type' => Type::string(), 'description' => 'Title of task.'], 'description' => ['type' => Type::string(), 'description' => 'Description of task.'], 'completed' => ['type' => Type::boolean(), 'description' => 'Completed status.'], 'user' => ['type' => GraphQL::type('user'), 'description' => 'User who owns task.']];
 }
 public static function _enumValue()
 {
     if (!isset(self::$_map['__EnumValue'])) {
         self::$_map['__EnumValue'] = new ObjectType(['name' => '__EnumValue', 'fields' => ['name' => ['type' => Type::nonNull(Type::string())], 'description' => ['type' => Type::string()], 'isDeprecated' => ['type' => Type::nonNull(Type::boolean()), 'resolve' => function ($enumValue) {
             return !!$enumValue->deprecationReason;
         }], 'deprecationReason' => ['type' => Type::string()]]]);
     }
     return self::$_map['__EnumValue'];
 }
Exemple #14
0
 public function fields()
 {
     return ['title' => ['type' => Type::string(), 'description' => 'Title of task.'], 'description' => ['type' => Type::string(), 'description' => 'Description of task.'], 'completed' => ['type' => Type::boolean(), 'description' => 'Completed status.']];
 }
 function testResolveTypeOnInterfaceYieldsUsefulError()
 {
     $DogType = null;
     $CatType = null;
     $HumanType = null;
     $PetType = new InterfaceType(['name' => 'Pet', 'resolveType' => function ($obj) use(&$DogType, &$CatType, &$HumanType) {
         if ($obj instanceof Dog) {
             return $DogType;
         }
         if ($obj instanceof Cat) {
             return $CatType;
         }
         if ($obj instanceof Human) {
             return $HumanType;
         }
         return null;
     }, 'fields' => ['name' => ['type' => Type::string()]]]);
     $HumanType = new ObjectType(['name' => 'Human', 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()]]]);
     $CatType = new ObjectType(['name' => 'Cat', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]]]);
     $schema = new Schema(new ObjectType(['name' => 'Query', 'fields' => ['pets' => ['type' => Type::listOf($PetType), 'resolve' => function () {
         return [new Dog('Odie', true), new Cat('Garfield', false), new Human('Jon')];
     }]]]));
     $query = '{
       pets {
         name
         ... on Dog {
           woofs
         }
         ... on Cat {
           meows
         }
       }
     }';
     $expected = ['data' => ['pets' => [['name' => 'Odie', 'woofs' => true], ['name' => 'Garfield', 'meows' => false], null]], 'errors' => [['message' => 'Runtime Object type "Human" is not a possible type for "Pet".']]];
     $this->assertEquals($expected, Executor::execute($schema, Parser::parse($query))->toArray());
 }
Exemple #16
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 } ] }
        ]);
      });
     */
 }
 /**
  * @it asserts variables are provided as items in lists
  */
 public function testAssertsVariablesAreProvidedAsItemsInLists()
 {
     $listOfBool = Type::listOf(Type::boolean());
     $listOfNonNullBool = Type::listOf(Type::nonNull(Type::boolean()));
     $this->runTestCaseWithVars([], $listOfBool, '[ $foo ]', [null]);
     $this->runTestCaseWithVars([], $listOfNonNullBool, '[ $foo ]', Utils::undefined());
     $this->runTestCaseWithVars(['foo' => true], $listOfNonNullBool, '[ $foo ]', [true]);
     // Note: variables are expected to have already been coerced, so we
     // do not expect the singleton wrapping behavior for variables.
     $this->runTestCaseWithVars(['foo' => true], $listOfNonNullBool, '$foo', true);
     $this->runTestCaseWithVars(['foo' => [true]], $listOfNonNullBool, '$foo', [true]);
 }
Exemple #18
0
 public static function _enumValue()
 {
     if (!isset(self::$map['__EnumValue'])) {
         self::$map['__EnumValue'] = new ObjectType(['name' => '__EnumValue', 'description' => 'One possible value for a given Enum. Enum values are unique values, not ' . 'a placeholder for a string or numeric value. However an Enum value is ' . 'returned in a JSON response as a string.', 'fields' => ['name' => ['type' => Type::nonNull(Type::string())], 'description' => ['type' => Type::string()], 'isDeprecated' => ['type' => Type::nonNull(Type::boolean()), 'resolve' => function ($enumValue) {
             return !!$enumValue->deprecationReason;
         }], 'deprecationReason' => ['type' => Type::string()]]]);
     }
     return self::$map['__EnumValue'];
 }
Exemple #19
0
 /**
  * Initialize Alambic types using GraphQL scalar types.
  */
 protected function initAlambicBaseTypes()
 {
     $this->alambicTypes = ['String' => Type::string(), 'Int' => Type::int(), 'Float' => Type::float(), 'Boolean' => Type::boolean(), 'ID' => Type::id()];
     $this->inputAlambicTypes = ['String' => Type::string(), 'Int' => Type::int(), 'Float' => Type::float(), 'Boolean' => Type::boolean(), 'ID' => Type::id()];
 }
Exemple #20
0
 function getWPQuerySchema()
 {
     return ['name' => 'WPQuery', 'description' => 'deals with the intricacies of a post request on a WordPress blog', 'fields' => ['posts' => ['type' => new ListOfType($this->getPostInterface()), 'args' => ['posts_per_page' => ['description' => 'number of post to show per page', 'type' => Type::int()], 'paged' => ['description' => 'number of page.', 'type' => Type::int()], 'post_type' => ['description' => "Retrieves posts by Post Types, default value is 'post'.", 'type' => new ListOfType(Type::string())], 'name' => ['description' => "Retrieves post by name", 'type' => Type::string()], 'order' => ['description' => "Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'DESC'. An array can be used for multiple order/orderby sets.", 'type' => Type::string()], 'orderby' => ['description' => "Sort retrieved posts by parameter. Defaults to 'date (post_date)'. One or more options can be passed.", 'type' => Type::string()], 's' => ['description' => "Show posts based on a keyword search.", 'type' => Type::string()], 'cat' => ['description' => "Show in this category id", 'type' => Type::int()], 'category_name' => ['description' => "Show in this category slug", 'type' => Type::string()], 'tag' => ['description' => "Show in this tag slug", 'type' => Type::string()], 'tag_id' => ['description' => "Show in this tag id", 'type' => Type::int()]], 'resolve' => function ($root, $args) {
         return $args ? get_posts($args) : $root->posts;
     }], 'menu' => ['type' => new ListOfType(new MenuItem(['name' => 'MenuItem'])), 'args' => ['name' => ['type' => Type::nonNull(Type::string()), 'description' => "Menu 'id','name' or 'slug'"]], 'resolve' => function ($root, $args) {
         return wp_get_nav_menu_items($args['name']);
     }], 'home_page' => ['type' => $this->getPostInterface(), 'resolve' => function () {
         return get_post(get_option('page_on_front'));
     }], 'terms' => ['type' => new ListOfType($this->getTerm()), 'description' => 'Retrieve the terms in a given taxonomy or list of taxonomies. ', 'args' => ['taxonomies' => ['description' => 'Array of Taxonomy names. Overides taxonomy argument', 'type' => new ListOfType(Type::string())], 'taxonomy' => ['description' => 'The taxonomy for which to retrieve terms. Defaults to category', 'type' => Type::string()], 'orderby' => ['description' => "Field(s) to order terms by. Accepts term fields ('name', 'slug', 'term_group', 'term_id', 'id', 'description'), 'count' for term taxonomy count, 'include' to match the 'order' of the include param, or 'none' to skip ORDER BY. Defaults to 'name'", 'type' => Type::string()], 'order' => ['description' => "Whether to order terms in ascending or descending order. Accepts 'ASC' (ascending) or 'DESC' (descending). Default 'ASC", 'type' => Type::string()], 'hide_empty' => ['description' => "Whether to order terms in ascending or descending order. Accepts 'ASC' (ascending) or 'DESC' (descending). Default 'ASC'", 'type' => Type::string()], 'include' => ['description' => "Array of term ids to include. Default empty array", 'type' => new ListOfType(Type::int())], 'exclude' => ['description' => "Array of term ids to exclude. Default empty array", 'type' => new ListOfType(Type::int())], 'exclude_tree' => ['description' => "Term ids to exclude along with all of their descendant terms. If include is non-empty, exclude_tree is ignored", 'type' => new ListOfType(Type::int())], 'number' => ['description' => "Maximum number of terms to return. Default 0 (all)", 'type' => Type::int()], 'offset' => ['description' => "The number by which to offset the terms query.", 'type' => Type::int()], 'name' => ['description' => "Array of names to return terms for", 'type' => new ListOfType(Type::string())], 'slug' => ['description' => "Array of slugs to return terms for", 'type' => new ListOfType(Type::string())], 'hierarchical' => ['description' => "Whether to include terms that have non-empty descendants (even if hide_empty is set to true). Default true", 'type' => new ListOfType(Type::boolean())], 'search' => ['description' => "Search criteria to match terms. Will be SQL-formatted with wildcards before and after.", 'type' => Type::string()], 'name__like' => ['description' => "Retrieve terms with criteria by which a term is LIKE name__like", 'type' => Type::string()], 'description__like' => ['description' => "Retrieve terms where the description is LIKE description__like", 'type' => Type::string()], 'pad_counts' => ['description' => "Whether to pad the quantity of a term's children in the quantity of each term's \"count\" object variable. Default false", 'type' => Type::boolean()], 'get' => ['description' => "Whether to return terms regardless of ancestry or whether the terms are empty. Accepts 'all' or empty (disabled).", 'type' => Type::boolean()], 'child_of' => ['description' => "Term ID to retrieve child terms of. If multiple taxonomies are passed, child_of is ignored. Default 0", 'type' => Type::int()], 'parent' => ['description' => "Parent term ID to retrieve direct-child terms of.", 'type' => Type::int()], 'childless' => ['description' => "True to limit results to terms that have no children. This parameter has no effect on non-hierarchical taxonomies. Default false.", 'type' => Type::boolean()]], 'resolve' => function ($root, $args) {
         $taxonomies = isset($args['taxonomies']) ? $args['taxonomies'] : isset($args['taxonomy']) ? $args['taxonomy'] : 'category';
         return get_terms($taxonomies, $args);
     }]]];
 }
Exemple #21
0
 /**
  * Boolean field.
  *
  * @param  array|string $config
  * @return array
  */
 public function boolean($config = [])
 {
     $description = is_string($config) ? $config : '';
     $config = is_array($config) ? $config : [];
     return array_merge(['type' => Type::boolean(), 'description' => $description], $config);
 }
Exemple #22
0
 /**
  * @it resolveType allows resolving with type name
  */
 public function testResolveTypeAllowsResolvingWithTypeName()
 {
     $PetType = new InterfaceType(['name' => 'Pet', 'resolveType' => function ($obj) {
         if ($obj instanceof Dog) {
             return 'Dog';
         }
         if ($obj instanceof Cat) {
             return 'Cat';
         }
         return null;
     }, 'fields' => ['name' => ['type' => Type::string()]]]);
     $DogType = new ObjectType(['name' => 'Dog', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()]]]);
     $CatType = new ObjectType(['name' => 'Cat', 'interfaces' => [$PetType], 'fields' => ['name' => ['type' => Type::string()], 'meows' => ['type' => Type::boolean()]]]);
     $schema = new Schema(['query' => new ObjectType(['name' => 'Query', 'fields' => ['pets' => ['type' => Type::listOf($PetType), 'resolve' => function () {
         return [new Dog('Odie', true), new Cat('Garfield', false)];
     }]]]), 'types' => [$CatType, $DogType]]);
     $query = '{
       pets {
         name
         ... on Dog {
           woofs
         }
         ... on Cat {
           meows
         }
       }
     }';
     $result = GraphQL::execute($schema, $query);
     $this->assertEquals(['data' => ['pets' => [['name' => 'Odie', 'woofs' => true], ['name' => 'Garfield', 'meows' => false]]]], $result);
 }
 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());
 }
 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]);
 }
 /**
  * @it does not converts NonNull values to NullValue
  */
 public function testDoesNotConvertsNonNullValuestoNullValue()
 {
     $this->assertSame(null, AST::astFromValue(null, Type::nonNull(Type::boolean())));
 }
Exemple #26
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());
 }
Exemple #27
0
 public static function boolean()
 {
     return Type::boolean();
 }
 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;
 }
 /**
  * The common page info type used by all connections.
  *
  * @return ObjectType
  */
 public static function pageInfoType()
 {
     if (self::$pageInfoType === null) {
         self::$pageInfoType = new ObjectType(['name' => 'PageInfo', 'description' => 'Information about pagination in a connection.', 'fields' => ['hasNextPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating forwards, are there more items?'], 'hasPreviousPage' => ['type' => Type::nonNull(Type::boolean()), 'description' => 'When paginating backwards, are there more items?'], 'startCursor' => ['type' => Type::string(), 'description' => 'When paginating backwards, the cursor to continue.'], 'endCursor' => ['type' => Type::string(), 'description' => 'When paginating forwards, the cursor to continue.']]]);
     }
     return self::$pageInfoType;
 }
 /**
  * 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;
 }