Expose your eloquent models as GraphQL queries and mutations
galahad/graphoquent is a Laravel package for expose your eloquent models as graphql queries and mutations.
It currently has 0 GitHub stars and 6 downloads on Packagist.
Install it with composer require galahad/graphoquent.
Discover more Laravel packages by galahad
or browse all Laravel packages to compare alternatives.
Last updated
Graphoquent is a Laravel packages that turns Eloquent models into queryable GraphQL objects.
By default, Graphoquent tries to infer your model's type from three places:
$casts array$dates array@property and @property-read DocBlock annotationsGiven 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
}
Graphoquent uses Laravel Gates for default authorization:
expose: Can this user (or null if not logged in) use introspection
to lear about this Type?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;
}