2017 © Pedro Peláez
 

project graphoquent

Expose your eloquent models as GraphQL queries and mutations

image

galahad/graphoquent

Expose your eloquent models as GraphQL queries and mutations

  • Friday, August 18, 2017
  • by inxilpro
  • Repository
  • 2 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Graphoquent

Graphoquent is a Laravel packages that turns Eloquent models into queryable GraphQL objects., (*1)

Automatic Type Inference

By default, Graphoquent tries to infer your model's type from three places:, (*2)

  1. The model's $casts array
  2. The model's $dates array
  3. The model's @property and @property-read DocBlock annotations

Given the following model:, (*3)

/**
 * @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:, (*4)

type Foo {
  count: Int
  stars: Float
  created_at: String
}

Authorization

Gates & Policies

Graphoquent uses Laravel Gates for default authorization:, (*5)

  • expose: Can this user (or null 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:, (*6)

public function authorizeGraphQL($actor, $ability)
{
    if ('expose' === $ability) {
        return true;
    }

    return $actor && $actor->id === $this->owner_id;
}

The Versions