nonNull() публичный статический Метод

public static nonNull ( $wrappedType ) : NonNull
$wrappedType
Результат NonNull
Пример #1
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;
 }
Пример #2
0
 /**
  * @param string $name
  * @return Type
  */
 public function resolveType($name)
 {
     if (preg_match('#^(.+)\\!$#', $name, $regs)) {
         return Type::nonNull($this->resolveType($regs[1]));
     }
     if (preg_match('#^\\[(.+)\\]$#', $name, $regs)) {
         return Type::listOf($this->resolveType($regs[1]));
     }
     switch ($name) {
         case Type::INT:
             return Type::int();
         case Type::STRING:
             return Type::string();
         case Type::BOOLEAN:
             return Type::boolean();
         case Type::FLOAT:
             return Type::float();
         case Type::ID:
             return Type::id();
         default:
             if (!isset($this->types[$name])) {
                 throw new \InvalidArgumentException(sprintf('Type "%s" is not defined', $name));
             }
             return $this->types[$name];
     }
 }
Пример #3
0
 public function setUp()
 {
     $this->syncError = new Error('sync');
     $this->nonNullSyncError = new Error('nonNullSync');
     $this->throwingData = ['sync' => function () {
         throw $this->syncError;
     }, 'nonNullSync' => function () {
         throw $this->nonNullSyncError;
     }, 'nest' => function () {
         return $this->throwingData;
     }, 'nonNullNest' => function () {
         return $this->throwingData;
     }];
     $this->nullingData = ['sync' => function () {
         return null;
     }, 'nonNullSync' => function () {
         return null;
     }, 'nest' => function () {
         return $this->nullingData;
     }, 'nonNullNest' => function () {
         return $this->nullingData;
     }];
     $dataType = new ObjectType(['name' => 'DataType', 'fields' => ['sync' => ['type' => Type::string()], 'nonNullSync' => ['type' => Type::nonNull(Type::string())], 'nest' => ['type' => function () use(&$dataType) {
         return $dataType;
     }], 'nonNullNest' => ['type' => function () use(&$dataType) {
         return Type::nonNull($dataType);
     }]]]);
     $this->schema = new Schema($dataType);
 }
Пример #4
0
 /**
  * Fields that exist on every connection.
  *
  * @return array
  */
 protected function baseFields()
 {
     return ['pageInfo' => ['type' => Type::nonNull($this->pageInfoType), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
         return $collection;
     }], 'edges' => ['type' => Type::listOf($this->edgeType), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
         return $this->injectCursor($collection);
     }]];
 }
Пример #5
0
 public static function buildDogType()
 {
     if (null !== self::$dogType) {
         return self::$dogType;
     }
     self::$dogType = new ObjectType(['name' => 'Dog', 'fields' => ['name' => ['type' => Type::nonNull(Type::string())], 'master' => ['type' => self::buildHumanType()]]]);
     return self::$dogType;
 }
 /**
  * Fields that exist on every connection.
  *
  * @return array
  */
 protected function baseFields()
 {
     $type = $this->type ?: $this->type();
     return ['pageInfo' => ['type' => Type::nonNull(GraphQL::type('pageInfo')), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
         return $collection;
     }], 'edges' => ['type' => Type::listOf($this->buildEdgeType($this->name, $type)), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection) {
         return $this->injectCursor($collection);
     }]];
 }
Пример #7
0
 private function withModifiers($types)
 {
     return array_merge(Utils::map($types, function ($type) {
         return Type::listOf($type);
     }), Utils::map($types, function ($type) {
         return Type::nonNull($type);
     }), Utils::map($types, function ($type) {
         return Type::nonNull(Type::listOf($type));
     }));
 }
Пример #8
0
 /**
  * @describe [T!]!
  */
 public function testHandlesNonNullListOfNonNulls()
 {
     $type = Type::nonNull(Type::listOf(Type::nonNull(Type::int())));
     // Contains values
     $this->check($type, [1, 2], ['data' => ['nest' => ['test' => [1, 2]]]]);
     // Contains null
     $this->check($type, [1, null, 2], ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
     // Returns null
     $this->check($type, null, ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable field DataType.test.', [new SourceLocation(1, 10)])]]);
 }
Пример #9
0
 /**
  * Returns configuration for Plural identifying root field
  *
  * type PluralIdentifyingRootFieldConfig = {
  *       argName: string,
  *       inputType: GraphQLInputType,
  *       outputType: GraphQLOutputType,
  *       resolveSingleInput: (input: any, info: GraphQLResolveInfo) => ?any,
  *       description?: ?string,
  * };
  *
  * @param array $config
  * @return array
  */
 public static function pluralIdentifyingRootField(array $config)
 {
     $inputArgs = [];
     $argName = self::getArrayValue($config, 'argName');
     $inputArgs[$argName] = ['type' => Type::nonNull(Type::listOf(Type::nonNull(self::getArrayValue($config, 'inputType'))))];
     return ['description' => isset($config['description']) ? $config['description'] : null, 'type' => Type::listOf(self::getArrayValue($config, 'outputType')), 'args' => $inputArgs, 'resolve' => function ($obj, $args, $context, ResolveInfo $info) use($argName, $config) {
         $inputs = $args[$argName];
         return array_map(function ($input) use($config, $context, $info) {
             return call_user_func(self::getArrayValue($config, 'resolveSingleInput'), $input, $context, $info);
         }, $inputs);
     }];
 }
Пример #10
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());
    }
Пример #11
0
 /**
  * Fields that exist on every connection.
  *
  * @return array
  */
 public function fields()
 {
     return ['node' => ['type' => $this->type, 'description' => 'The item at the end of the edge.', 'resolve' => function ($edge) {
         return $edge;
     }], 'cursor' => ['type' => Type::nonNull(Type::string()), 'description' => 'A cursor for use in pagination.', 'resolve' => function ($edge) {
         if (is_array($edge) && isset($edge['relayCursor'])) {
             return $edge['relayCursor'];
         } elseif (is_array($edge->attributes)) {
             return $edge->attributes['relayCursor'];
         }
         return $edge->relayCursor;
     }]];
 }
Пример #12
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, $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;
     }]];
 }
Пример #13
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;
     }]];
 }
Пример #14
0
 /**
  * Returns a GraphQLFieldConfig for the mutation described by the
  * provided MutationConfig.
  *
  * A description of a mutation consumable by mutationWithClientMutationId
  * to create a GraphQLFieldConfig for that mutation.
  *
  * The inputFields and outputFields should not include `clientMutationId`,
  * as this will be provided automatically.
  *
  * An input object will be created containing the input fields, and an
  * object will be created containing the output fields.
  *
  * mutateAndGetPayload will receieve an Object with a key for each
  * input field, and it should return an Object with a key for each
  * output field. It may return synchronously, or return a Promise.
  *
  * type MutationConfig = {
  *   name: string,
  *   inputFields: InputObjectConfigFieldMap,
  *   outputFields: GraphQLFieldConfigMap,
  *   mutateAndGetPayload: mutationFn,
  * }
  */
 public static function mutationWithClientMutationId(array $config)
 {
     $name = self::getArrayValue($config, 'name');
     $inputFields = self::getArrayValue($config, 'inputFields');
     $outputFields = self::getArrayValue($config, 'outputFields');
     $mutateAndGetPayload = self::getArrayValue($config, 'mutateAndGetPayload');
     $augmentedInputFields = function () use($inputFields) {
         $inputFieldsResolved = self::resolveMaybeThunk($inputFields);
         return array_merge($inputFieldsResolved !== null ? $inputFieldsResolved : [], ['clientMutationId' => ['type' => Type::nonNull(Type::string())]]);
     };
     $augmentedOutputFields = function () use($outputFields) {
         $outputFieldsResolved = self::resolveMaybeThunk($outputFields);
         return array_merge($outputFieldsResolved !== null ? $outputFieldsResolved : [], ['clientMutationId' => ['type' => Type::nonNull(Type::string())]]);
     };
     $outputType = new ObjectType(['name' => $name . 'Payload', 'fields' => $augmentedOutputFields]);
     $inputType = new InputObjectType(['name' => $name . 'Input', 'fields' => $augmentedInputFields]);
     return ['type' => $outputType, 'args' => ['input' => ['type' => Type::nonNull($inputType)]], 'resolve' => function ($query, $args, $context, ResolveInfo $info) use($mutateAndGetPayload) {
         $payload = call_user_func($mutateAndGetPayload, $args['input'], $context, $info);
         $payload['clientMutationId'] = $args['input']['clientMutationId'];
         return $payload;
     }];
 }
Пример #15
0
 public function setUp()
 {
     $this->syncError = new \Exception('sync');
     $this->nonNullSyncError = new \Exception('nonNullSync');
     $this->promiseError = new \Exception('promise');
     $this->nonNullPromiseError = new \Exception('nonNullPromise');
     $this->throwingData = ['sync' => function () {
         throw $this->syncError;
     }, 'nonNullSync' => function () {
         throw $this->nonNullSyncError;
     }, 'promise' => function () {
         return new Promise(function () {
             throw $this->promiseError;
         });
     }, 'nonNullPromise' => function () {
         return new Promise(function () {
             throw $this->nonNullPromiseError;
         });
     }, 'nest' => function () {
         return $this->throwingData;
     }, 'nonNullNest' => function () {
         return $this->throwingData;
     }, 'promiseNest' => function () {
         return new Promise(function (callable $resolve) {
             $resolve($this->throwingData);
         });
     }, 'nonNullPromiseNest' => function () {
         return new Promise(function (callable $resolve) {
             $resolve($this->throwingData);
         });
     }];
     $this->nullingData = ['sync' => function () {
         return null;
     }, 'nonNullSync' => function () {
         return null;
     }, 'promise' => function () {
         return new Promise(function (callable $resolve) {
             return $resolve(null);
         });
     }, 'nonNullPromise' => function () {
         return new Promise(function (callable $resolve) {
             return $resolve(null);
         });
     }, 'nest' => function () {
         return $this->nullingData;
     }, 'nonNullNest' => function () {
         return $this->nullingData;
     }, 'promiseNest' => function () {
         return new Promise(function (callable $resolve) {
             $resolve($this->nullingData);
         });
     }, 'nonNullPromiseNest' => function () {
         return new Promise(function (callable $resolve) {
             $resolve($this->nullingData);
         });
     }];
     $dataType = new ObjectType(['name' => 'DataType', 'fields' => function () use(&$dataType) {
         return ['sync' => ['type' => Type::string()], 'nonNullSync' => ['type' => Type::nonNull(Type::string())], 'promise' => Type::string(), 'nonNullPromise' => Type::nonNull(Type::string()), 'nest' => $dataType, 'nonNullNest' => Type::nonNull($dataType), 'promiseNest' => $dataType, 'nonNullPromiseNest' => Type::nonNull($dataType)];
     }]);
     $this->schema = new Schema(['query' => $dataType]);
 }
Пример #16
0
 /**
  * Create ConnectionType.
  *
  * @param  string $name
  * @param  mixed $type
  * @param Closure $injectCursor
  * @return ObjectType
  */
 protected function connectionType($name, $type, Closure $injectCursor = null)
 {
     if (!$type instanceof ListOfType) {
         $type = Type::listOf($type);
     }
     return new ObjectType(['name' => ucfirst($name) . 'Connection', 'fields' => ['edges' => ['type' => $type, 'resolve' => function ($collection, array $args, ResolveInfo $info) use($injectCursor) {
         if ($injectCursor) {
             return $injectCursor($collection, $args, $info);
         }
         return $this->injectCursor($collection);
     }], 'pageInfo' => ['type' => Type::nonNull($this->pageInfoType()), 'description' => 'Information to aid in pagination.', 'resolve' => function ($collection, array $args, ResolveInfo $info) {
         return $collection;
     }]]]);
 }
Пример #17
0
 /**
  * Returns node definitions
  *
  * @return array
  */
 protected function getNodeDefinitions()
 {
     if (!self::$nodeDefinition) {
         self::$nodeDefinition = Node::nodeDefinitions(function ($id, $context, ResolveInfo $info) {
             $userData = $this->getUserData();
             if (array_key_exists($id, $userData)) {
                 return $userData[$id];
             } else {
                 $photoData = $this->getPhotoData();
                 if (array_key_exists($id, $photoData)) {
                     return $photoData[$id];
                 }
             }
         }, function ($obj) {
             if (array_key_exists($obj['id'], $this->getUserData())) {
                 return self::$userType;
             } else {
                 return self::$photoType;
             }
         });
         self::$userType = new ObjectType(['name' => 'User', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'name' => ['type' => Type::string()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
         self::$photoType = new ObjectType(['name' => 'Photo', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'width' => ['type' => Type::int()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
     }
     return self::$nodeDefinition;
 }
Пример #18
0
 static function build()
 {
     $typeEnum = new EnumType(["name" => "Type", "description" => "The type of entity", "values" => ["user" => ["value" => "user"], "group" => ["value" => "group"], "object" => ["value" => "object"]]]);
     $statusEnum = new EnumType(["name" => "Status", "description" => "The status of the entity", "values" => ["ok" => ["value" => "ok"], "access_denied" => ["value" => "access_denied"], "not_found" => ["value" => "not_found"]]]);
     $voteDirectionEnum = new EnumType(["name" => "VoteType", "description" => "The type of vote", "values" => ["up" => ["value" => "up"], "down" => ["value" => "down"]]]);
     $entityInterface = new InterfaceType(["name" => "Entity", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)]], "resolveType" => function ($object) use(&$userType, &$objectType, &$groupType) {
         switch ($object["type"]) {
             case "user":
                 return $userType;
             case "object":
                 return $objectType;
             case "group":
                 return $groupType;
         }
     }]);
     $accessIdType = new ObjectType(["name" => "AccessId", "fields" => ["id" => ["type" => Type::nonNull(Type::int())], "description" => ["type" => Type::nonNull(Type::string())]]]);
     $userType = new ObjectType(["name" => "User", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "url" => ["type" => Type::string()]]]);
     $groupType = new ObjectType(["name" => "Group", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "canEdit" => ["type" => Type::boolean()], "isClosed" => ["type" => Type::boolean()], "canJoin" => ["type" => Type::boolean()], "defaultAccessId" => ["type" => Type::int()]]]);
     $objectType = new ObjectType(["name" => "Object", "interfaces" => [$entityInterface], "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "status" => ["type" => Type::nonNull($statusEnum)], "title" => ["type" => Type::string()], "subtype" => ["type" => Type::string()], "description" => ["type" => Type::string()], "url" => ["type" => Type::string()], "tags" => ["type" => Type::listOf(Type::string())], "timeCreated" => ["type" => Type::string()], "timeUpdated" => ["type" => Type::string()], "canEdit" => ["type" => Type::boolean()], "canComment" => ["type" => Type::boolean()], "accessId" => ["type" => Type::int()], "isBookmarked" => ["type" => Type::boolean(), "resolve" => function ($object) {
         return Resolver::isBookmarked($object);
     }], "votes" => ["type" => Type::int(), "resolve" => function ($object) {
         return Resolver::countVotes($object);
     }], "owner" => ["type" => $userType, "resolve" => function ($object) {
         return Resolver::getUser($object["ownerGuid"]);
     }], "comments" => ["type" => function () use(&$objectType) {
         return Type::listOf($objectType);
     }, "resolve" => function ($object) {
         return Resolver::getComments($object);
     }]]]);
     $searchListType = new ObjectType(["name" => "Search", "fields" => ["total" => ["type" => Type::nonNull(Type::int())], "results" => ["type" => Type::listOf($entityInterface)]]]);
     $entityListType = new ObjectType(["name" => "EntityList", "fields" => ["total" => ["type" => Type::nonNull(Type::int())], "canWrite" => ["type" => Type::nonNull(Type::boolean())], "entities" => ["type" => Type::listOf($entityInterface)]]]);
     $viewerType = new ObjectType(["name" => "Viewer", "description" => "The current site viewer", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "loggedIn" => ["type" => Type::nonNull(Type::boolean())], "username" => ["type" => Type::string()], "name" => ["type" => Type::string()], "icon" => ["type" => Type::string()], "url" => ["type" => Type::string()], "bookmarks" => ["type" => $entityListType, "args" => ["offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()]], "resolve" => "Pleio\\Resolver::getBookmarks"]]]);
     $menuItemType = new ObjectType(["name" => "MenuItem", "fields" => ["guid" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::nonNull(Type::string())], "link" => ["type" => Type::nonNull(Type::string())], "js" => ["type" => Type::nonNull(Type::boolean())]]]);
     $siteType = new ObjectType(["name" => "Site", "description" => "The current site", "fields" => ["id" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::nonNull(Type::string())], "menu" => ["type" => Type::listOf($menuItemType)], "accessIds" => ["type" => Type::listOf($accessIdType)], "defaultAccessId" => ["type" => Type::nonNull(Type::int())]]]);
     $queryType = new ObjectType(["name" => "Query", "fields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"], "entity" => ["type" => $entityInterface, "args" => ["guid" => ["type" => Type::nonNull(Type::string())]], "resolve" => "Pleio\\Resolver::getEntity"], "search" => ["type" => $searchListType, "args" => ["q" => ["type" => Type::nonNull(Type::string())], "offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()]], "resolve" => "Pleio\\Resolver::search"], "entities" => ["type" => $entityListType, "args" => ["offset" => ["type" => Type::int()], "limit" => ["type" => Type::int()], "type" => ["type" => $typeEnum], "subtype" => ["type" => Type::string()], "containerGuid" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "resolve" => "Pleio\\Resolver::getEntities"], "site" => ["type" => $siteType, "resolve" => "Pleio\\Resolver::getSite"]]]);
     $loginMutation = Relay::mutationWithClientMutationId(["name" => "login", "inputFields" => ["username" => ["type" => Type::nonNull(Type::string())], "password" => ["type" => Type::nonNull(Type::string())], "rememberMe" => ["type" => Type::boolean()]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::login"]);
     $logoutMutation = Relay::mutationWithClientMutationId(["name" => "logout", "inputFields" => [], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::logout"]);
     $registerMutation = Relay::mutationWithClientMutationId(["name" => "register", "inputFields" => ["name" => ["type" => Type::nonNull(Type::string())], "email" => ["type" => Type::nonNull(Type::string())], "password" => ["type" => Type::nonNull(Type::string())], "newsletter" => ["type" => Type::boolean()], "terms" => ["type" => Type::boolean()]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::register"]);
     $forgotPasswordMutation = Relay::mutationWithClientMutationId(["name" => "forgotPassword", "inputFields" => ["username" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["status" => ["type" => Type::nonNull($statusEnum), "resolve" => function ($return) {
         return $return["status"];
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::forgotPassword"]);
     $forgotPasswordConfirmMutation = Relay::mutationWithClientMutationId(["name" => "forgotPasswordConfirm", "inputFields" => ["userGuid" => ["type" => Type::nonNull(Type::string())], "code" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["status" => ["type" => Type::nonNull($statusEnum), "resolve" => function ($return) {
         return $return["status"];
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::forgotPasswordConfirm"]);
     $subscribeNewsletterMutation = Relay::mutationWithClientMutationId(["name" => "subscribeNewsletter", "inputFields" => ["email" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["viewer" => ["type" => $viewerType, "resolve" => "Pleio\\Resolver::getViewer"]], "mutateAndGetPayload" => "Pleio\\Mutations::subscribeNewsletter"]);
     $addEntityMutation = Relay::mutationWithClientMutationId(["name" => "addEntity", "inputFields" => ["type" => ["type" => Type::nonNull($typeEnum)], "subtype" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::string()], "description" => ["type" => Type::nonNull(Type::string())], "containerGuid" => ["type" => Type::int()], "accessId" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::addEntity"]);
     $editEntityMutation = Relay::mutationWithClientMutationId(["name" => "editEntity", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string())], "title" => ["type" => Type::string()], "description" => ["type" => Type::nonNull(Type::string())], "accessId" => ["type" => Type::int()], "tags" => ["type" => Type::listOf(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::editEntity"]);
     $deleteEntityMutation = Relay::mutationWithClientMutationId(["name" => "deleteEntity", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string())]], "outputFields" => ["entity" => ["type" => $entityInterface, "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::deleteEntity"]);
     $bookmarkMutation = Relay::mutationWithClientMutationId(["name" => "bookmark", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string()), "description" => "The guid of the entity to bookmark."], "isAdding" => ["type" => Type::nonNull(Type::boolean()), "description" => "True when adding, false when removing."]], "outputFields" => ["object" => ["type" => Type::nonNull($objectType), "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::bookmark"]);
     $voteMutation = Relay::mutationWithClientMutationId(["name" => "vote", "inputFields" => ["guid" => ["type" => Type::nonNull(Type::string()), "description" => "The guid of the entity to bookmark."], "direction" => ["type" => Type::nonNull($voteDirectionEnum)]], "outputFields" => ["object" => ["type" => Type::nonNull($objectType), "resolve" => function ($entity) {
         return Resolver::getEntity(null, $entity, null);
     }]], "mutateAndGetPayload" => "Pleio\\Mutations::vote"]);
     $mutationType = new ObjectType(["name" => "Mutation", "fields" => ["login" => $loginMutation, "logout" => $logoutMutation, "register" => $registerMutation, "forgotPassword" => $forgotPasswordMutation, "forgotPasswordConfirm" => $forgotPasswordConfirmMutation, "addEntity" => $addEntityMutation, "editEntity" => $editEntityMutation, "deleteEntity" => $deleteEntityMutation, "subscribeNewsletter" => $subscribeNewsletterMutation, "bookmark" => $bookmarkMutation, "vote" => $voteMutation]]);
     $schema = new Schema($queryType, $mutationType);
     return $schema;
 }
Пример #19
0
 /**
  * Generate Relay compliant arguments.
  *
  * @return array
  */
 public function args()
 {
     $inputType = new InputObjectType(['name' => ucfirst($this->name()) . 'Input', 'fields' => array_merge($this->inputFields(), ['clientMutationId' => ['type' => Type::nonNull(Type::string())]])]);
     return ['input' => ['type' => Type::nonNull($inputType)]];
 }
Пример #20
0
 public function schema()
 {
     $ComplexScalarType = ComplexScalar::create();
     $TestInputObject = new InputObjectType(['name' => 'TestInputObject', 'fields' => ['a' => ['type' => Type::string()], 'b' => ['type' => Type::listOf(Type::string())], 'c' => ['type' => Type::nonNull(Type::string())], 'd' => ['type' => $ComplexScalarType]]]);
     $TestNestedInputObject = new InputObjectType(['name' => 'TestNestedInputObject', 'fields' => ['na' => ['type' => Type::nonNull($TestInputObject)], 'nb' => ['type' => Type::nonNull(Type::string())]]]);
     $TestType = new ObjectType(['name' => 'TestType', 'fields' => ['fieldWithObjectInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => $TestInputObject]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'fieldWithNullableStringInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::string()]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'fieldWithNonNullableStringInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::string())]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'fieldWithDefaultArgumentValue' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::string(), 'defaultValue' => 'Hello World']], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'fieldWithNestedInputObject' => ['type' => Type::string(), 'args' => ['input' => ['type' => $TestNestedInputObject, 'defaultValue' => 'Hello World']], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'list' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::listOf(Type::string())]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'nnList' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::string()))]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'listNN' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::listOf(Type::nonNull(Type::string()))]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }], 'nnListNN' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string())))]], 'resolve' => function ($_, $args) {
         return isset($args['input']) ? json_encode($args['input']) : null;
     }]]]);
     $schema = new Schema(['query' => $TestType]);
     return $schema;
 }
Пример #21
0
 public static function build()
 {
     /**
      * The original trilogy consists of three movies.
      *
      * This implements the following type system shorthand:
      *   enum Episode { NEWHOPE, EMPIRE, JEDI }
      */
     $episodeEnum = new EnumType(['name' => 'Episode', 'description' => 'One of the films in the Star Wars Trilogy', 'values' => ['NEWHOPE' => ['value' => 4, 'description' => 'Released in 1977.'], 'EMPIRE' => ['value' => 5, 'description' => 'Released in 1980.'], 'JEDI' => ['value' => 6, 'description' => 'Released in 1983.']]]);
     $humanType = null;
     $droidType = null;
     /**
      * Characters in the Star Wars trilogy are either humans or droids.
      *
      * This implements the following type system shorthand:
      *   interface Character {
      *     id: String!
      *     name: String
      *     friends: [Character]
      *     appearsIn: [Episode]
      *   }
      */
     $characterInterface = new InterfaceType(['name' => 'Character', 'description' => 'A character in the Star Wars Trilogy', 'fields' => function () use(&$characterInterface, $episodeEnum) {
         return ['id' => ['type' => Type::nonNull(Type::string()), 'description' => 'The id of the character.'], 'name' => ['type' => Type::string(), 'description' => 'The name of the character.'], 'friends' => ['type' => Type::listOf($characterInterface), 'description' => 'The friends of the character, or an empty list if they have none.'], 'appearsIn' => ['type' => Type::listOf($episodeEnum), 'description' => 'Which movies they appear in.'], 'secretBackstory' => ['type' => Type::string(), 'description' => 'All secrets about their past.']];
     }, 'resolveType' => function ($obj) use(&$humanType, &$droidType) {
         return StarWarsData::getHuman($obj['id']) ? $humanType : $droidType;
     }]);
     /**
      * We define our human type, which implements the character interface.
      *
      * This implements the following type system shorthand:
      *   type Human : Character {
      *     id: String!
      *     name: String
      *     friends: [Character]
      *     appearsIn: [Episode]
      *     secretBackstory: String
      *   }
      */
     $humanType = new ObjectType(['name' => 'Human', 'description' => 'A humanoid creature in the Star Wars universe.', 'fields' => ['id' => ['type' => new NonNull(Type::string()), 'description' => 'The id of the human.'], 'name' => ['type' => Type::string(), 'description' => 'The name of the human.'], 'friends' => ['type' => Type::listOf($characterInterface), 'description' => 'The friends of the human, or an empty list if they have none.', 'resolve' => function ($human, $args, $context, ResolveInfo $info) {
         $fieldSelection = $info->getFieldSelection();
         $fieldSelection['id'] = true;
         $friends = array_map(function ($friend) use($fieldSelection) {
             return array_intersect_key($friend, $fieldSelection);
         }, StarWarsData::getFriends($human));
         return $friends;
     }], 'appearsIn' => ['type' => Type::listOf($episodeEnum), 'description' => 'Which movies they appear in.'], 'homePlanet' => ['type' => Type::string(), 'description' => 'The home planet of the human, or null if unknown.'], 'secretBackstory' => ['type' => Type::string(), 'description' => 'Where are they from and how they came to be who they are.', 'resolve' => function () {
         // This is to demonstrate error reporting
         throw new \Exception('secretBackstory is secret.');
     }]], 'interfaces' => [$characterInterface]]);
     /**
      * The other type of character in Star Wars is a droid.
      *
      * This implements the following type system shorthand:
      *   type Droid : Character {
      *     id: String!
      *     name: String
      *     friends: [Character]
      *     appearsIn: [Episode]
      *     secretBackstory: String
      *     primaryFunction: String
      *   }
      */
     $droidType = new ObjectType(['name' => 'Droid', 'description' => 'A mechanical creature in the Star Wars universe.', 'fields' => ['id' => ['type' => Type::nonNull(Type::string()), 'description' => 'The id of the droid.'], 'name' => ['type' => Type::string(), 'description' => 'The name of the droid.'], 'friends' => ['type' => Type::listOf($characterInterface), 'description' => 'The friends of the droid, or an empty list if they have none.', 'resolve' => function ($droid) {
         return StarWarsData::getFriends($droid);
     }], 'appearsIn' => ['type' => Type::listOf($episodeEnum), 'description' => 'Which movies they appear in.'], 'secretBackstory' => ['type' => Type::string(), 'description' => 'Construction date and the name of the designer.', 'resolve' => function () {
         // This is to demonstrate error reporting
         throw new \Exception('secretBackstory is secret.');
     }], 'primaryFunction' => ['type' => Type::string(), 'description' => 'The primary function of the droid.']], 'interfaces' => [$characterInterface]]);
     /**
      * This is the type that will be the root of our query, and the
      * entry point into our schema. It gives us the ability to fetch
      * objects by their IDs, as well as to fetch the undisputed hero
      * of the Star Wars trilogy, R2-D2, directly.
      *
      * This implements the following type system shorthand:
      *   type Query {
      *     hero(episode: Episode): Character
      *     human(id: String!): Human
      *     droid(id: String!): Droid
      *   }
      *
      */
     $queryType = new ObjectType(['name' => 'Query', 'fields' => ['hero' => ['type' => $characterInterface, 'args' => ['episode' => ['description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.', 'type' => $episodeEnum]], 'resolve' => function ($root, $args) {
         return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
     }], 'human' => ['type' => $humanType, 'args' => ['id' => ['name' => 'id', 'description' => 'id of the human', 'type' => Type::nonNull(Type::string())]], 'resolve' => function ($root, $args) {
         $humans = StarWarsData::humans();
         return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
     }], 'droid' => ['type' => $droidType, 'args' => ['id' => ['name' => 'id', 'description' => 'id of the droid', 'type' => Type::nonNull(Type::string())]], 'resolve' => function ($root, $args) {
         $droids = StarWarsData::droids();
         return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
     }]]]);
     return new Schema(['query' => $queryType]);
 }
Пример #22
0
 public function schema()
 {
     $TestInputObject = new InputObjectType(['name' => 'TestInputObject', 'fields' => ['a' => ['type' => Type::string()], 'b' => ['type' => Type::listOf(Type::string())], 'c' => ['type' => Type::nonNull(Type::string())]]]);
     $TestType = new ObjectType(['name' => 'TestType', 'fields' => ['fieldWithObjectInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => $TestInputObject]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'fieldWithNullableStringInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::string()]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'fieldWithNonNullableStringInput' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::string())]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'list' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::listOf(Type::string())]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'nnList' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::string()))]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'listNN' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::listOf(Type::nonNull(Type::string()))]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }], 'nnListNN' => ['type' => Type::string(), 'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string())))]], 'resolve' => function ($_, $args) {
         return json_encode($args['input']);
     }]]]);
     $schema = new Schema($TestType);
     return $schema;
 }
 private function getTestSchema()
 {
     $StringBox = new ObjectType(['name' => 'StringBox', 'fields' => ['scalar' => ['type' => Type::string()]]]);
     $IntBox = new ObjectType(['name' => 'IntBox', 'fields' => ['scalar' => ['type' => Type::int()]]]);
     $NonNullStringBox1 = new ObjectType(['name' => 'NonNullStringBox1', 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $NonNullStringBox2 = new ObjectType(['name' => 'NonNullStringBox2', 'fields' => ['scalar' => ['type' => Type::nonNull(Type::string())]]]);
     $BoxUnion = new UnionType(['name' => 'BoxUnion', 'resolveType' => function () use($StringBox) {
         return $StringBox;
     }, 'types' => [$StringBox, $IntBox, $NonNullStringBox1, $NonNullStringBox2]]);
     $Connection = new ObjectType(['name' => 'Connection', 'fields' => ['edges' => ['type' => Type::listOf(new ObjectType(['name' => 'Edge', 'fields' => ['node' => ['type' => new ObjectType(['name' => 'Node', 'fields' => ['id' => ['type' => Type::id()], 'name' => ['type' => Type::string()]]])]]]))]]]);
     $schema = new Schema(new ObjectType(['name' => 'QueryRoot', 'fields' => ['boxUnion' => ['type' => $BoxUnion], 'connection' => ['type' => $Connection]]]));
     return $schema;
 }
Пример #24
0
 /**
  * Available arguments on mutation.
  *
  * @return array
  */
 public function args()
 {
     return ['id' => ['name' => 'id', 'type' => Type::nonNull(Type::string())], 'email' => ['name' => 'email', 'type' => Type::nonNull(Type::string()), 'rules' => ['email']]];
 }
Пример #25
0
 /**
  * Create valid GraphQL input field using field key and definition array.
  *
  * @param string $fieldKey
  * @param array  $fieldValue
  *
  * @return array
  */
 protected function buildInputField($fieldKey, $fieldValue)
 {
     if (!isset($this->inputAlambicTypes[$fieldValue['type']]) && isset($this->alambicTypeDefs[$fieldValue['type']])) {
         $this->loadInputAlambicType($fieldValue['type'], $this->alambicTypeDefs[$fieldValue['type']]);
     }
     $baseTypeResult = $this->inputAlambicTypes[$fieldValue['type']];
     if (isset($fieldValue['multivalued']) && $fieldValue['multivalued']) {
         $baseTypeResult = Type::listOf($baseTypeResult);
     }
     if (isset($fieldValue['required']) && $fieldValue['required']) {
         $baseTypeResult = Type::nonNull($baseTypeResult);
     }
     $fieldResult = ['type' => $baseTypeResult];
     if (!empty($fieldValue['description'])) {
         $fieldResult['description'] = $fieldValue['description'];
     }
     if (!empty($fieldValue['defaultValue'])) {
         $fieldResult['defaultValue'] = $fieldValue['defaultValue'];
     }
     return $fieldResult;
 }
Пример #26
0
 public function testAllowsRecursiveDefinitions()
 {
     // See https://github.com/webonyx/graphql-php/issues/16
     $node = new InterfaceType(['name' => 'Node', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())]]]);
     $blog = null;
     $called = false;
     $user = new ObjectType(['name' => 'User', 'fields' => function () use(&$blog, &$called) {
         $this->assertNotNull($blog, 'Blog type is expected to be defined at this point, but it is null');
         $called = true;
         return ['id' => ['type' => Type::nonNull(Type::id())], 'blogs' => ['type' => Type::nonNull(Type::listOf(Type::nonNull($blog)))]];
     }, 'interfaces' => function () use($node) {
         return [$node];
     }]);
     $blog = new ObjectType(['name' => 'Blog', 'fields' => function () use($user) {
         return ['id' => ['type' => Type::nonNull(Type::id())], 'owner' => ['type' => Type::nonNull($user)]];
     }, 'interfaces' => function () use($node) {
         return [$node];
     }]);
     $schema = new Schema(new ObjectType(['name' => 'Query', 'fields' => ['node' => ['type' => $node]]]));
     $this->assertTrue($called);
     $this->assertEquals([$node], $blog->getInterfaces());
     $this->assertEquals([$node], $user->getInterfaces());
     $this->assertNotNull($user->getField('blogs'));
     $this->assertSame($blog, $user->getField('blogs')->getType()->getWrappedType(true));
     $this->assertNotNull($blog->getField('owner'));
     $this->assertSame($user, $blog->getField('owner')->getType()->getWrappedType(true));
 }
Пример #27
0
 /**
  * Arguments available on node query.
  *
  * @return array
  */
 public function args()
 {
     return ['id' => ['name' => 'id', 'type' => Type::nonNull(Type::id())]];
 }
Пример #28
0
 /**
  * Available fields on type.
  *
  * @return array
  */
 public function fields()
 {
     return ['id' => ['type' => Type::nonNull(Type::id()), 'description' => 'The id of the object.']];
 }
Пример #29
0
 private function schema()
 {
     $dataType = new ObjectType(['name' => 'DataType', 'fields' => ['list' => ['type' => Type::listOf(Type::int())], 'listOfNonNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullList' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'listContainsNull' => ['type' => Type::listOf(Type::int())], 'listOfNonNullContainsNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullListContainsNull' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNullContainsNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'listReturnsNull' => ['type' => Type::listOf(Type::int())], 'listOfNonNullReturnsNull' => ['type' => Type::listOf(Type::nonNull(Type::int()))], 'nonNullListReturnsNull' => ['type' => Type::nonNull(Type::listOf(Type::int()))], 'nonNullListOfNonNullReturnsNull' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::int())))], 'nest' => ['type' => function () use(&$dataType) {
         return $dataType;
     }]]]);
     $schema = new Schema($dataType);
     return $schema;
 }
Пример #30
0
 public static function typeNameMetaFieldDef()
 {
     if (!isset(self::$map['__typename'])) {
         self::$map['__typename'] = FieldDefinition::create(['name' => '__typename', 'type' => Type::nonNull(Type::string()), 'description' => 'The name of the current Object type at runtime.', 'args' => [], 'resolve' => function ($source, $args, $context, ResolveInfo $info) {
             return $info->parentType->name;
         }]);
     }
     return self::$map['__typename'];
 }