galahad / graphoquent
将Eloquent模型暴露为GraphQL查询和突变
dev-master
2017-08-18 03:31 UTC
Requires
- php: >=5.6
- illuminate/database: 5.3.*|5.4.*|5.5.*
- illuminate/http: 5.3.*|5.4.*|5.5.*
- illuminate/routing: 5.3.*|5.4.*|5.5.*
- illuminate/support: 5.3.*|5.4.*|5.5.*
- phpdocumentor/reflection-docblock: ^3.2
- webonyx/graphql-php: ~0.9.13
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ~5.7.19
This package is auto-updated.
Last update: 2024-08-29 04:31:30 UTC
README
Graphoquent是一个Laravel扩展包,它将Eloquent模型转换为可查询的GraphQL对象。
自动类型推断
默认情况下,Graphoquent会尝试从三个地方推断您的模型类型
- 模型的
$casts
数组 - 模型的
$dates
数组 - 模型的
@property
和@property-read
DocBlock注释
给定以下模型
/** * @property int $count */ class Foo extends Model { use \Galahad\Graphoquent\Queryable; protected $casts = [ 'stars' => 'float', ]; protected $dates = [ 'created_at', ]; }
Graphoquent将构建以下GraphQL类型
type Foo { count: Int stars: Float created_at: String }
授权
门和策略
Graphoquent使用Laravel门(Gates)进行默认授权
expose
: 该用户(如果没有登录则为null
)能否使用自省来了解此类型?
自定义
您可以通过在模型上定义一个authorizeGraphQL
方法来为任何模型提供自定义授权
public function authorizeGraphQL($actor, $ability) { if ('expose' === $ability) { return true; } return $actor && $actor->id === $this->owner_id; }