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

Related tags

CMS graphql laravel twill
Overview

Twill CMS GraphQL 🔭

WIP - not stable

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

Currently, only queries are supported, mutations will come after @guard implementation

Technologies

This package uses nuwave/lighthouse and 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

The package is not yet submitted and is a matter of change.
For development, you could manually download it and load it up in composer as dev-master  
After that composer update should be run.

Configuration

Deploy default graphql schema

$ php artisan twill:graphql:deploy

Deploy lighthouse config

$ 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.

'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).

    '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

  • Create wrapper around Twill default models for relations
  • Add examples
  • Write tests
  • Create composer package (publish)
  • Create guards example
  • Create mutations
  • More tests
  • 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.

// app/Models/Category.php


namespace App\Models;

use A17\Twill\Models\Model;

class Category extends Model 
{
  
    protected $fillable = [
        'published',
        'title',
        'description',
    ];
    
}

Edit graphql/schema.graphql

scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")  

type Query {

  "Query on Category module"
  categories: [Category!]! @all @softDeletes
  category(id: Int! @eq): Category @find

} 

type Category {
  id: ID!
  published: Int!
  title: String
  description: String
  created_at: DateTime
  updated_at: DateTime
}

Let's load Graphql playground and test it.

All categories

{
    categories {
        id
        published
        title
        description
        created_at
        updated_at
    }
}

Result

{
    "data": {
        "categories": [
        {
            "id": "1",
            "published": 1,
            "title": "Books",
            "description": "Just a plain description of the books category",
            "created_at": "2022-02-06 18:49:16",
            "updated_at": "2022-02-06 18:58:10"
        },
        {
            "id": "2",
            "published": 1,
            "title": "Cars",
            "description": "Cars are awesome.",
            "created_at": "2022-02-08 01:54:21",
            "updated_at": "2022-02-08 01:54:35"
        }
        ]
    }
}

Query specific category by id

{
    category(id: 2) {
        id
        published
        title
        description
        created_at
        updated_at
    }
}

Result

{
    "data": {
        "category": {
            "id": "2",
            "published": 1,
            "title": "Cars",
            "description": "Cars are awesome.",
            "created_at": "2022-02-08 01:54:21",
            "updated_at": "2022-02-08 01:54:35"
        }
    }
}

Query on Twill default models

Query Feature

All features

{
    features {
        id
        feature_id
        feature_type
        bucket_key
        position
        starred
        created_at
        updated_at
    }
}

Specific feature

{
    feature(id: 1) {
        id
        feature_id
        feature_type
        bucket_key
        position
        starred
        created_at
        updated_at
    }
}

All Block

{
    blocks {
        id
        blockable_id
        blockable_type
        position
        content
        type
        child_key
        parent_id
    }
}

Specific block

{
    block(id: 1) {
        id
        blockable_id
        blockable_type
        position
        content
        type
        child_key
        parent_id
    }
}

Query File

All files

{
    files {
        id
        created_at
        updated_at
        filename
        uuid
        size
    }
}

Specific file by id

{
    file(id: 2) {
        id
        created_at
        updated_at
        filename
        uuid
        size
    }
}

Query Media

All medias

{
    medias {
        id
        uuid
        alt_text
        width
        height
        caption
        filename
        created_at
        updated_at
    }
}

Specific media by id

{
    media(id: 1) {
        id
        uuid
        alt_text
        width
        height
        caption
        filename
        created_at
        updated_at
    }
}

Query Setting

All settings

{
    settings {
        id
        key
        section
        created_at
        updated_at
    }
}

Specific setting by id

{
    setting(id: 1) {
        id
        key
        section
        created_at
        updated_at
    }
}

Query Tag

All tags

{
    tags {
        id
        namespace
        slug
        name
        count
    }
}

Specific tag

{
    tag(id: 1) {
        id
        namespace
        slug
        name
        count
    }
}

Query User

All users

{
    users {
        id
        published
        name
        email
        role
        title
        description
        language
        created_at
        updated_at
    }
}

Specific user by id

{
    user(id: 1) {
        id
        published
        name
        email
        role
        title
        description
        language
        created_at
        updated_at
    }
}

Notes

  • If you have clients which are not residing on the same domain you should enable CORS in ./config/cors.php
return [
-   'paths' => ['api/*', 'sanctum/csrf-cookie'],
+   'paths' => ['api/*', 'graphql', 'sanctum/csrf-cookie'],
    ...
];
  • If you do not want to enable the GraphQL playground in production, you can disable it in the config file. The easiest way is to set the environment variable GRAPHQL_PLAYGROUND_ENABLED=false.

LICENSE

MIT

Comments
Owner
Izet Mulalic
Fullstack developer && full time electrician ⚡
Izet Mulalic
A plugin for Craft CMS 3.X that allows for GraphQL search functionality for matching on fields of nested entries.

Nested Entry GraphQL Plugin This Craft CMS plugin allows for performing graphQL search queries that match on fields on nested entries-as-a-field. What

Rubin EPO 2 Sep 10, 2021
Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.

Grafite CMS Grafite has archived this project and no longer supports or develops this code. We recommend using only as a source of ideas for your own

Grafite Inc 494 Nov 25, 2022
Borgert - A simple CMS to start projects in Laravel containing some modules

A simple CMS to start projects in Laravel containing some modules.Blog, Pages, Products, Mailbox, Image Gallery, Log Viewer and Users.

Borgert Inc. 300 Dec 30, 2022
Baicloud CMS is a lightweight content management system (CMS) based on PHP and MySQL and running on Linux, windows and other platforms

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

null 5 Aug 15, 2022
GetSimple CMS - a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP

GetSimple CMS is a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP.

null 370 Dec 30, 2022
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.

About Craft CMS Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond. It features: An intuitive, user-

Craft CMS 2.9k Jan 1, 2023
Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS

Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS. Building this Content Management System, we focused on simplicity. To achieve this, we implemented a simple but powerful API's.

Flextype 524 Dec 30, 2022
NukeViet 132 Nov 27, 2022
BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the project website for more information.

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

null 5 Aug 15, 2022
Bootstrap CMS - PHP CMS powered by Laravel 5 and Sentry

Bootstrap CMS Bootstrap CMS was created by, and is maintained by Graham Campbell, and is a PHP CMS powered by Laravel 5.1 and Sentry. It utilises many

Bootstrap CMS 2.5k Dec 27, 2022
Front-end user management for October CMS

Front-end user plugin Front-end user management for October CMS. Requirements This plugin requires the Ajax Framework to be included in your layout/pa

The Rain Lab 111 Nov 20, 2022
True Multisite, Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony

True Multisite, Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony

null 4 Oct 28, 2022
PHPVibe Open source video CMS / Video Sharing CMS / Youtube Api v3 / Video Embeds

PHPVibe Video CMS Free Video Sharing CMS The modern choice of design inspired by Youtube and a social videos sharing module that may just cut it for y

MediaVibe 71 Dec 18, 2022
Doptor CMS is a Laravel 5 based CMS

Introduction Doptor CMS is a Laravel 5 based CMS. Find out more about Doptor by reading below. ;) About Doptor CMS Doptor is an Integrated and well-de

DOPTOR 4 Sep 11, 2022
Bismuth CMS is a ready-made Website CMS based on Yii 2 Advance Template

Bismuth CMS is a ready-made Website CMS based on Yii 2 Advance Template, it's the simplest and easy to set up CMS you may come across.

Hamadas Telebrain 1 Feb 11, 2022
Amila Laravel CMS - Free, open-source Simple Bootstrap Laravel CMS

Simple Bootstrap Laravel CMS. Support Laravel 8.x Can integrate into any existing Laravel project. Only add few database tables with prefixes, not affect your existing database tables. Support Laravel 7.x & Laravel 6.x & Laravel 5.x & MySql & PostgreSql - Amila Laravel CMS

Alex Zeng 96 Sep 6, 2022
Provides autocompletion for Craft CMS and plugins in Twig templates.

Autocomplete for Craft CMS Provides autocompletion for Craft CMS and plugins in Twig templates. Currently works with PhpStorm only, as VSCode does not

PutYourLightsOn 12 Nov 23, 2021
Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

Grav Grav is a Fast, Simple, and Flexible, file-based Web-platform. There is Zero installation required. Just extract the ZIP archive, and you are alr

Grav 13.6k Jan 4, 2023