Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kallefrombosnia/twill-graphql

twill-graphql provides GraphQL wrapper for Twill CMS
https://github.com/kallefrombosnia/twill-graphql

api graphql laravel php twill

Last synced: 3 months ago
JSON representation

twill-graphql provides GraphQL wrapper for Twill CMS

Awesome Lists containing this project

README

        

# Twill CMS GraphQL :telescope:

Twill GraphQL provides easy access to query-specific fields from Twill CMS modules and user-defined modules with GraphQL.

The project is heavily inspired by [twill-api](https://github.com/area17/twill-api)

### Documentation

Check the [documentation.](https://github.com/kallefrombosnia/twill-graphql/tree/master/docs)

### Technologies

This package uses [nuwave/lighthouse](https://github.com/nuwave/lighthouse) and [mll-lab/laravel-graphql-playground](https://github.com/mll-lab/laravel-graphql-playground) for providing easy access to models and playground UI for exploring server schemas and testing.

Big props to them and Twill developers for creating such amazing projects.

Per default graphql endpoint serves on `/graphql` and playground is available on `/graphql-playground`

### Install package

**From composer**

```sh
composer require kallefrombosnia/twill-graphql
```

### Configuration

Deploy default graphql schema
```sh
$ php artisan twill:graphql:deploy
```

Deploy `lighthouse` config
```sh
$ php artisan vendor:publish --tag=lighthouse-config
```

> This is not hardcoded into our config since lighthouse is constantly changing their codebase

After deploying lighthouse config, find it in the `./config/lighthouse.php`

Find `namespaces` which should look like this.

```php
'namespaces' => [
'models' => ['App', 'App\\Models'],
'queries' => 'App\\GraphQL\\Queries',
'mutations' => 'App\\GraphQL\\Mutations',
'subscriptions' => 'App\\GraphQL\\Subscriptions',
'interfaces' => 'App\\GraphQL\\Interfaces',
'unions' => 'App\\GraphQL\\Unions',
'scalars' => 'App\\GraphQL\\Scalars',
'directives' => ['App\\GraphQL\\Directives'],
'validators' => ['App\\GraphQL\\Validators'],
],
```

At the moment only config option needed for us is `models`
Change it like this to load default Twill modules into it (make sure you have Twill CMS installed).

```php
'namespaces' => [
'models' => ['A17\\Twill\\Models', 'App', 'App\\Models'],
...
],
```

This will autoload all package models first so make sure your Laravel models and Twill custom models are not named the same as Twill CMS modules.

Reserved: `Feature`, `Block`, `File`, `Media`, `Setting`, `Tag`, `User`.

And you are ready to go.

### Project roadmap

- [x] Create wrapper around Twill default models for relations
- [x] Add examples
- [x] Write tests
- [x] Create composer package (publish)
- [x] Create guards example
- [x] Create mutations
- [x] More tests
- [ ] Subscriptions
- [ ] Tests for subscribtions
- [ ] TBA

### Query on Twill custom user models

For example, we have the `Category` model which is located in `app\Models`
By `lighthouse` configuration this model is also loaded.

```php
// app/Models/Category.php