galahad / graphoquent
Expose your eloquent models as GraphQL queries and mutations
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Type:project
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-11-29 05:09:41 UTC
README
Graphoquent is a Laravel packages that turns Eloquent models into queryable GraphQL objects.
Automatic Type Inference
By default, Graphoquent tries to infer your model's type from three places:
- The model's
$casts
array - The model's
$dates
array - The model's
@property
and@property-read
DocBlock annotations
Given the following model:
/** * @property int $count */ class Foo extends Model { use \Galahad\Graphoquent\Queryable; protected $casts = [ 'stars' => 'float', ]; protected $dates = [ 'created_at', ]; }
Graphoquent will build the following GraphQL Type:
type Foo { count: Int stars: Float created_at: String }
Authorization
Gates & Policies
Graphoquent uses Laravel Gates for default authorization:
expose
: Can this user (ornull
if not logged in) use introspection to lear about this Type?
Custom
You may provide custom authorization for any Model by defining an
authorizeGraphQL
method on the model:
public function authorizeGraphQL($actor, $ability) { if ('expose' === $ability) { return true; } return $actor && $actor->id === $this->owner_id; }