public static story ( ) : |
||
Результат |
public function __construct() { $config = ['name' => 'Query', 'fields' => ['user' => ['type' => Types::user(), 'description' => 'Returns user by id (in range of 1-5)', 'args' => ['id' => Types::nonNull(Types::id())]], 'viewer' => ['type' => Types::user(), 'description' => 'Represents currently logged-in user (for the sake of example - simply returns user with id == 1)'], 'stories' => ['type' => Types::listOf(Types::story()), 'description' => 'Returns subset of stories posted for this blog', 'args' => ['after' => ['type' => Types::id(), 'description' => 'Fetch stories listed after the story with this ID'], 'limit' => ['type' => Types::int(), 'description' => 'Number of stories to be returned', 'defaultValue' => 10]]], 'lastStoryPosted' => ['type' => Types::story(), 'description' => 'Returns last story posted for this blog'], 'deprecatedField' => ['type' => Types::string(), 'deprecationReason' => 'This field is deprecated!'], 'fieldWithException' => ['type' => Types::string(), 'resolve' => function () { throw new \Exception("Exception message thrown in field resolver"); }], 'hello' => Type::string()], 'resolveField' => function ($val, $args, $context, ResolveInfo $info) { return $this->{$info->fieldName}($val, $args, $context, $info); }]; parent::__construct($config); }
public function resolveType($object, Types $types) { if ($object instanceof User) { return Types::user(); } else { if ($object instanceof Image) { return Types::image(); } else { if ($object instanceof Story) { return Types::story(); } } } }
public function __construct() { $config = ['name' => 'SearchResultType', 'types' => function () { return [Types::story(), Types::user()]; }, 'resolveType' => function ($value) { if ($value instanceof Story) { return Types::story(); } else { if ($value instanceof User) { return Types::user(); } } }]; parent::__construct($config); }
public function __construct() { // Option #1: using composition over inheritance to define type, see ImageType for inheritance example $this->definition = new UnionType(['name' => 'SearchResultType', 'types' => function () { return [Types::story(), Types::user()]; }, 'resolveType' => function ($value) { if ($value instanceof Story) { return Types::story(); } else { if ($value instanceof User) { return Types::user(); } } }]); }
public function __construct() { $config = ['name' => 'User', 'description' => 'Our blog authors', 'fields' => function () { return ['id' => Types::id(), 'email' => Types::email(), 'photo' => ['type' => Types::image(), 'description' => 'User photo URL', 'args' => ['size' => Types::nonNull(Types::imageSizeEnum())]], 'firstName' => ['type' => Types::string()], 'lastName' => ['type' => Types::string()], 'lastStoryPosted' => Types::story(), 'fieldWithError' => ['type' => Types::string(), 'resolve' => function () { throw new \Exception("This is error field"); }]]; }, 'interfaces' => [Types::node()], 'resolveField' => function ($value, $args, $context, ResolveInfo $info) { if (method_exists($this, $info->fieldName)) { return $this->{$info->fieldName}($value, $args, $context, $info); } else { return $value->{$info->fieldName}; } }]; parent::__construct($config); }
public function __construct() { // Option #1: using composition over inheritance to define type, see ImageType for inheritance example $this->definition = new ObjectType(['name' => 'User', 'description' => 'Our blog authors', 'fields' => function () { return ['id' => Types::id(), 'email' => Types::email(), 'photo' => ['type' => Types::image(), 'description' => 'User photo URL', 'args' => ['size' => Types::nonNull(Types::imageSizeEnum())]], 'firstName' => ['type' => Types::string()], 'lastName' => ['type' => Types::string()], 'lastStoryPosted' => Types::story(), 'fieldWithError' => ['type' => Types::string(), 'resolve' => function () { throw new \Exception("This is error field"); }]]; }, 'interfaces' => [Types::node()], 'resolveField' => function ($value, $args, $context, ResolveInfo $info) { if (method_exists($this, $info->fieldName)) { return $this->{$info->fieldName}($value, $args, $context, $info); } else { return $value->{$info->fieldName}; } }]); }