Skip to content

An example implementation of an auto-generated GraphQL CRUD api

License

Notifications You must be signed in to change notification settings

maarten00/lighthouse-utils-example

Repository files navigation

lighthouse-utils-example

An example implementation of an auto-generated GraphQL CRUD API with Laravel.

Included with this example:

Installation

Run the following script in the root of this project:

./install.sh

Alternatively, you can run the following commands yourself:

  • composer install
  • cp -r .env.example .env

Update the DB_* values in the .env file to the database you want to use, then run the migrations and seeds using the following command:

php artisan migrate --seed

When that's finished run php artisan serve and go to the URL provided in your console. (Usually localhost:8000)

GraphQL

Setup

In order to use the GraphQL interface, you need to generate the schema. The schema generator reads the *.graphql files in the app/Http/GraphQL/Types folder. the Schema is generated by running following command:

php artisan lighthouse-utils:generate-schema

Note: Every time you modify the GraphQL types, the schema has to be re-generated.

Usage

Now that everything is up and running, you can try out the GraphQL API by navigating to: http://localhost:8000/graphql-playground

On the right you will see a button Schema, you can inspect all the available queries and mutations there.

Some example queries:

Retrieve all articles and the corresponding author
{
  articles {
    title
    author{
      name
    }
  }
}
Retrieve all articles with a certain word in the title
{
  articles(title_contains: "turtle") {
    title
  }
}
Retrieve user with ID 1 and all articles they have commented on
{
  user(id: 1) {
    name
    comments {
      article {
        title
      }
    }
  }
}

About

An example implementation of an auto-generated GraphQL CRUD api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages