Download the PHP package decowood/laravel-eloquent-to-graphql without Composer
On this page you can find all versions of the php package decowood/laravel-eloquent-to-graphql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download decowood/laravel-eloquent-to-graphql
More information about decowood/laravel-eloquent-to-graphql
Files in decowood/laravel-eloquent-to-graphql
Package laravel-eloquent-to-graphql
Short Description Automatically turn Eloquent models into GraphQL
License MIT
Informations about the package laravel-eloquent-to-graphql
laravel-eloquent-to-graphql
This package generates a static GraphQL schema from your Eloquent models.
It is suggested to be used with lighthouse.
Setup
-
Install the package:
-
Type-hint your models' relationships:
- (Optional) Publish the configuration file:
Usage
This will generate a schema for all your models in a single file at graphql/generated.graphql
.
There are several options for customizing the way the schema is generated. Please have a look at them with
php artisan e2gql --help
.
Configuration
Automatic Updates
To automatically update the schema every time one of your Eloquent models changes, you can register the command in your IDE of choice with the --force
option, which disables all prompts.
If you are using VSCode, this can be achieved using the Run on Save extension. After installing the extension, you can add the following to .vscode/settings.json
:
With standard project structure, this will update your schema every time an Eloquent model changes.
Custom Type Mappings
If your tables have columns with types unknown to DBAL, the command will let you know. In this case, you have two options:
-
Let the command know which type that is known by DBAL you would like to map the unkown type to. You can do this by adding both to
custom_type_mappings
inconfig/eloquent_to_graphql.php
: - Ignore the columns entirely using the
--exclude-columns
option. You can then later add them by hand.
TODO
- [ ] Option to automatically update the schema after migrations are run
- [ ] Way to keep changes made by the user when regenerating a schema
- [ ] More customizable type resolution