ayimdomnic / graph-ql-l5.3
为 Laravel 开发者提供的 Facebook GraphQl
v2.0.2-beta.1
2016-08-29 13:56 UTC
Requires
- php: ^7.0
- illuminate/support: ^5.3
- shavy/qcache: ^1.0
- webonyx/graphql-php: ^0.6.4
Requires (Dev)
- orchestra/testbench: ~3.1
- phpunit/phpunit: 5.5.*
This package is auto-updated.
Last update: 2024-09-15 23:27:08 UTC
README
在内罗毕开发者研讨会之后,我决定从 REST 转向 GraphQL,这是一个辅助我开发 Laravel API 的包。
#要求
- PHP 5.6 及以上
- Laravel 5.3
#安装
composer require ayimdomnic/graph-ql-l5.3
- 将
Ayimdomnic\GraphQl\GraphQlServiceProvider::class,
添加到config/app
- 将
'GraphQl' => 'Ayimdomnic\GraphQl\Helper\Facade\GraphQl',
添加到 Facades - 发布
php artisan vendor:publish
#用法
#创建查询(#creating-a-query)
namespace App\GraphQl\Type; use GraphQL\Type\Definition\Type; use Ayimdomnic\GraphQl\Helper\Type as GraphQLType; class UserType extends GraphQLType { protected $attributes = [ 'name' => 'User', 'description' => 'A user' ]; public function fields() { return [ 'id' => [ 'type' => Type::nonNull(Type::string()), 'description' => 'The id of the user' ], 'email' => [ 'type' => Type::string(), 'description' => 'The email of user' ] ]; } #########If you want to resolve the field yourself, you can declare a method ###################with the following format resolve[FIELD_NAME]Field() protected function resolveEmailField($root, $args) { return strtolower($root->email); } }