ayimdomnic/graph-ql-l5.3

为 Laravel 开发者提供的 Facebook GraphQl

安装: 13

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 3

分支: 0

开放问题: 1

类型:项目

v2.0.2-beta.1 2016-08-29 13:56 UTC

README

在内罗毕开发者研讨会之后,我决定从 REST 转向 GraphQL,这是一个辅助我开发 Laravel API 的包。

#要求

  1. PHP 5.6 及以上
  2. Laravel 5.3

#安装

  1. composer require ayimdomnic/graph-ql-l5.3
  2. Ayimdomnic\GraphQl\GraphQlServiceProvider::class, 添加到 config/app
  3. 'GraphQl' => 'Ayimdomnic\GraphQl\Helper\Facade\GraphQl', 添加到 Facades
  4. 发布 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);
		}
        
    }

创建一个突变