All Projects → deInternetJongens → Lighthouse Utils

deInternetJongens / Lighthouse Utils

Licence: mit
An add-on to Lighthouse to auto-generate CRUD actions from types https://github.com/nuwave/lighthouse

Projects that are alternatives of or similar to Lighthouse Utils

Laravel Graphql
GraphQL implementation with power of Laravel
Stars: ✭ 56 (+115.38%)
Mutual labels:  graphql, eloquent, laravel
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+73611.54%)
Mutual labels:  graphql, graphql-server, relay
Requent
A GraphQL like interface to map a request to eloquent query with data transformation for Laravel.
Stars: ✭ 78 (+200%)
Mutual labels:  graphql, eloquent, laravel
Graphql Up
Get a ready-to-use GraphQL API for your schema
Stars: ✭ 415 (+1496.15%)
Mutual labels:  graphql, graphql-server, relay
Laravel Graphql
Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.
Stars: ✭ 1,793 (+6796.15%)
Mutual labels:  graphql, relay, laravel
Create Graphql
Command-line utility to build production-ready servers with GraphQL.
Stars: ✭ 441 (+1596.15%)
Mutual labels:  graphql, graphql-server, relay
Node Graphql Server
Boilerplate code for scalable, production-ready GraphQL servers
Stars: ✭ 761 (+2826.92%)
Mutual labels:  graphql, graphql-server
Graphql Yoga
🧘 Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
Stars: ✭ 6,573 (+25180.77%)
Mutual labels:  graphql, graphql-server
Graphene
GraphQL framework for Python
Stars: ✭ 6,964 (+26684.62%)
Mutual labels:  graphql, relay
Laravel Sluggable
An opinionated package to create slugs for Eloquent models
Stars: ✭ 831 (+3096.15%)
Mutual labels:  eloquent, laravel
Laravel
Laravel Model Generator
Stars: ✭ 715 (+2650%)
Mutual labels:  eloquent, laravel
Laravel Love
Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
Stars: ✭ 822 (+3061.54%)
Mutual labels:  eloquent, laravel
Graph Node
Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
Stars: ✭ 884 (+3300%)
Mutual labels:  graphql, graphql-server
Eloquent Filter
This simple package helps you filter Eloquent data using query filters.
Stars: ✭ 24 (-7.69%)
Mutual labels:  eloquent, laravel
Graphql Prisma Typescript
🏡 GraphQL server reference implementation (Airbnb clone) in Typescript using Prisma & graphql-yoga
Stars: ✭ 723 (+2680.77%)
Mutual labels:  graphql, graphql-server
Graphqlgen
⚙️ Generate type-safe resolvers based upon your GraphQL Schema
Stars: ✭ 796 (+2961.54%)
Mutual labels:  graphql, graphql-server
Adrenaline
Simple Relay alternative
Stars: ✭ 720 (+2669.23%)
Mutual labels:  graphql, relay
Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+27376.92%)
Mutual labels:  graphql, graphql-server
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (-26.92%)
Mutual labels:  eloquent, laravel
Graphql Server Demo
GraphQL server demo with nodejs
Stars: ✭ 19 (-26.92%)
Mutual labels:  graphql, graphql-server

Lighthouse Utils (no longer maintained)

Build Status Code Coverage Scrutinizer Code Quality Latest Unstable Version

This package can generate queries for the Lighthouse GraphQL library. This is not a standalone package, so Lighthouse is listed as a dependency.

To generate queries, all you need to do is define a couple of GraphQL Types and run the generate command. Scroll down to 'Schema' to learn more.

We also include a couple of Directives and Scalar types. More about that later on.

Installation

Install via composer

composer require deinternetjongens/lighthouse-utils

Alternatively, you can try the example installation below.

Example installation

An example installation is available at: https://github.com/maarten00/lighthouse-utils-example

Register Service Provider

Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.

Add service provider to config/app.php in providers section

deinternetjongens\LighthouseUtils\ServiceProvider::class,

Register Facade

Register package facade in config/app.php in aliases section

deinternetjongens\LighthouseUtils\Facades\LighthouseUtils::class,

Publish Configuration File

php artisan vendor:publish --provider="DeInternetJongens\LighthouseUtils\ServiceProvider" --tag="config"

Contributing

Before committing, please run ./automate.sh

This script will run all code style checks and phpunit tests. Fix all errors before opening a pull request.

Usage

This package uses Laravel Auto Discovery to register itself with your application. It exposes a GraphQL interface interface on the /graphql route.

To get started, run the following command in your Laravel application:

php artisan vendor:publish --provider="Nuwave\Lighthouse\Providers\LighthouseServiceProvider"
php artisan vendor:publish --provider="DeInternetJongens\LighthouseUtils\ServiceProvider" --tag="migrations"
php artisan migrate

A config file will be generated: config/lighthouse.php. You can change these values if you want.

Schema generation

Define your GraphQL schema by adding Types, Queries and Mutations in app/GraphQL/Types, app/GraphQL/Queries and app/GraphQL/Mutations directories. If you want to change these paths, publish the config file for this package and change the paths there.

Currently this package only supports custom Types, Queries and Mutations are ignored. You can define your custom types and run the command below to auto-generate queries and mutations for those types. In the future it will be possible to add custom queries and mutations to the above directories. These will then also be used in the generated schema.

For more information on schemas and basic Lighthouse usage, check the Lighthouse docs

To generate your schema.graphql file, run the following command:

php artisan lighthouse-utils:generate-schema

The schema will be generated to the path as defined in the Lighthouse config, lighthouse.schema.register

Custom Queries and Mutations

It might happen that you need a custom query or mutation beside the generated schema. In this package you have the ability to add custom queries and mutations by creating .graphql files in the default directories app/GraphQL/Queries and app/GraphQL/Mutations (These directories are adjustable by editing the config/lighthouse.php file)

Take for example a custom query to retrieve an instance of a model:

type Query{
    customQuery(id: ID! @eq): Model! @find(model: "Model")
}

This query will be parsed after running the schema generation command and will be added to the Query section of the schema.graphql

Scalar types

Currently two scalar types are included. More about scalar type usage can be found here.

Date

A date string with format Y-m-d. Example: "2018-01-01"

scalar Date @scalar(class: "DeInternetJongens\\LighthouseUtils\\Schema\\Scalars\\Date")

DateTimeTZ

A date string with format Y-m-d H:i:s+P. Example: "2018-01-01 13:00:00+00:00"

scalar DateTimeTz @scalar(class: "DeInternetJongens\\LighthouseUtils\\Schema\\Scalars\\DateTimeTz")

PostalCodeNl

A postal code as valid for The Netherlands, format 1111aa. Example: "7311SZ"

Email

An RFC 5321 compliant e-mail

FullTextSearch

Indicates that a field searches through multiple fields. To use this scalar, you need to add a scope on your model scopeFullTextSearch. Example:

public function scopeFullTextSearch(Builder $builder, $value)
{
    return $builder->whereRaw("column_one % ? OR column_two % ?", [$value, $value])
        ->orderByRaw('column_two <-> ?', [$value]);
}

In the scope you can basically define whatever kind of query you want.

Directives

To run more advanced queries, a couple of directives are included. These are automatically registered with Lighthouse, so you can use them at your own discretion.

Currently these directives are included:

  • contains
  • ends_with
  • gte
  • gt
  • lte
  • lt
  • in (comma seperated string)
  • not_contains
  • not_ends_with
  • not
  • not_in (comma seperated string)
  • not_starts_with
  • starts_with
  • fullTextSearch

Migrations

This package stores the generated schema in the database, so the schema is available outside the schema.graphql and can be used to sync permission. Publish the migration and migrate the database.

php artisan vendor:publish --provider="DeInternetJongens\LighthouseUtils\ServiceProvider" --tag="migrations"
php artisan migrate

Authorization

To protect your queries and migrations from unauthorized users, you can enable the Authorization feature. To enable authorization, make sure you have published the config for this package and add the following line to your .env file:

LIGHTHOUSE_UTILS_AUTHORIZATION=true

When a schema is generated the event DeInternetJongens\LighthouseUtils\Events\GraphQLSchemaGenerated will be fired. In your application you can listen for this event to sync the generated permissions with your application. The event has a schema variable with the generated schema.

The generated queries and their corresponding permissions will also be persisted to your database to the graphql_schema table. An Eloquent model for this table is included with this package.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].