Skip to content

An experiment to try and auto generate graphQL types and queries from Laravel models for Lighthouse PHP

License

Notifications You must be signed in to change notification settings

dpwilhelmsen/lighthouse-model-migrator

Repository files navigation

Lighthouse Model Migrator

This is an experimental proof of concept to try to automagically generate GraphQL types & queries for Lighthouse PHP from Laravel Eloquent models.

Installation

To install this package, you'll have to update the composer.json to pull from the github repository.

// composer.json

"require": {
	"dpwilhelmsen/lighthouse-model-migrator": "dev-master"
},
"repositories": [
    {
        "type": "vcs",
    	"url": "https://github.com/dpwilhelmsen/lighthouse-model-migrator"
	}
]

Usage

This package will attempt to generate graphql types and queries from existing Eloquent models. It will append the results to schema.graphql file created by Lighthouse PHP

To run, use the following artisan command.

$ php artisan lighthouse:migrate

How it works

This package uses the models namespaces defined in config/lighthouse.php. It finds all Eloquent models, figures out the table names and derives the attributes from the table schema. Then it analyzes the php code and looks for methods that implement Laravel relationship methods. Then, it generates basic types and queries for the models.

Known issues

This package is experimental and hasn't been thoroughly tested. There are likely many use cases where this will fail.

  • This relies on a database connection. Not all column types are supported or properly mapped to graphQL types
  • Doesn't currently support polymorphic relations
  • Traits & inheritance has not been tested and likely won't work

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Credits

License

license. Please see the license file for more information.

About

An experiment to try and auto generate graphQL types and queries from Laravel models for Lighthouse PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages