A Statamic Pro addon that provides alternative GraphQL queries for collections, entries and global sets.

Overview

Statamic Enhanced GraphQL

A Statamic CMS GraphQL Addon that provides alternative GraphQL queries for collections, entries and global sets.

⚠️ This is a POC and while I consider it somewhat stable, it's not thoroughly tested. Use at your own risk.

Features

This addon provides additional GraphQL queries for Statamic Pro.

  • Transforms each collection and global set to individual GraphQL queries.
  • Transform single entries to GraphQL queries.
  • No GraphQL Interfaces.
  • Supports Pagination, Filtering & Sorting.

Why

I use Statamic exclusively in Headless mode and make use of its GraphQL API. For end-to-end type-safety I'm writing frontends in TypeScript. Statamics default GraphQL implementation provides one query to query for all types of collections and another one to fetch individual entries using GraphQL Interfaces, meaning you need to implement a lot of type guards to make use of the GraphQL types in the frontend, adding boilerplate, query properties and susceptibility to error.

This addon aims to provide individual queries for each collection and global set to keep the amount of type guards at a minimum.

Querying for the content of an entry with the slug 'home' in a collection with the handle 'pages' would look like this with Statamics default GraphQL implementation:

query QueryHome {
  entry(collection: "pages", slug: "home") {
    __typename
    ... on Entry_Pages_Pages {
      content
    }
  }
}

Notice the additional __typename to implement a type guard in TypeScript:

const entryIsPage = (entry: EntryInterface): entry is Entry_Pages_Pages => {
  return entry.__typename === 'Entry_Pages_Pages'
}

The query this addon provides makes the type guard obsolete and the query more concise:

query QueryHome {
  pagesEntry(slug: "home") {
    content
  }
}

Furthermore, you can transform individual entries to GraphQL queries:

query QueryHome {
  home {
    content
  }
}

How to Install

composer require legrisch/statamic-enhanced-graphql

Usage

This addon adds a settings section to Statamics Control Panel.

  • Add collections to transform to queries. Make sure the collections only use one blueprint.
  • Add global sets to transform to queries.
  • Add single entry queries to transform to queries.

TODO

  • filter on entries query
  • queries for entries in collections with more than one blueprint
You might also like...
Laravel wrapper for Facebook's GraphQL

Laravel GraphQL Use Facebook's GraphQL with Laravel 6.0+. It is based on the PHP port of GraphQL reference implementation. You can find more informati

A framework for serving GraphQL from Laravel
A framework for serving GraphQL from Laravel

Lighthouse A framework for serving GraphQL from Laravel Lighthouse is a GraphQL framework that integrates with your Laravel application. It takes the

EXPERIMENTAL plugin extending WPGraphQL to support querying (Gutenberg) Blocks as data, using Server Side Block registries to map Blocks to the GraphQL Schema.

WPGraphQL Block Editor This is an experimental plugin to work toward compatiblity between the WordPress Gutenberg Block Editor and WPGraphQL, based on

🍞🧑‍🍳 An on-the-fly GraphQL Schema generator from Eloquent models for Laravel.

An on-the-fly GraphQL Schema generator from Eloquent models for Laravel. Installation Quickstart Model schemas Installation This package requires PHP

Test your PHP GraphQL server in style, with Pest!

Pest GraphQL Plugin Test your GraphQL API in style, with Pest! Installation Simply install through Composer! composer require --dev miniaturebase/pest

GraphQL implementation with power of Laravel

Laravel GraphQL Use Facebook GraphQL with Laravel 5.2 =. It is based on the PHP implementation here. You can find more information about GraphQL in t

Add Price Including tax for Magento's "cart" GraphQl query

Comwrap_GraphQlCartPrices Add Price Including tax for Magento's "cart" GraphQl query Query will looks like following: items { id __typenam

GraPHPinator ⚡ 🌐 ⚡ Easy-to-use & Fast GraphQL server implementation for PHP

Easy-to-use & Fast GraphQL server implementation for modern PHP. Includes features from latest draft, middleware directives and modules with extra functionality.

Place where I record all knowledge gained for GraphQL from Laracasts & other tutorials.

Knowledge from Laracasts series: https://laracasts.com/series/graphql-with-laravel-and-vue What is GraphQL It is a query language for your API, and it

Releases(v1.0.0)
Owner
Grischa Erbe
Grischa Erbe
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Leonardo Losoviz 265 Jan 7, 2023
Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server.

Field Query Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server. Install Via Composer com

PoP 4 Jan 7, 2022
A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of the individual components, but also of the framework.

chubbyphp-framework Description A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of th

chubbyphp 106 Dec 9, 2022
Open Standards Protocol for global Trade & Finance.

Open Standards Protocol for global Trade & Finance. Mitigate Counter-Party Risk by making your Financial Instruments Interoperable & Liquid Start trial under regulatory sandbox environment. Digital Bond, Invoice Factoring, R3 Corda Bridge on XinFin Blockchain

XinFin (eXchange inFinite) 9 Dec 7, 2022
This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Webedia - Overblog 720 Dec 25, 2022
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.

API Platform is a next-generation web framework designed to easily create API-first projects without compromising extensibility and flexibility: Desig

API Platform 7.7k Jan 7, 2023
The server component of API Platform: hypermedia and GraphQL APIs in minutes

API Platform Core API Platform Core is an easy to use and powerful system to create hypermedia-driven REST and GraphQL APIs. It is a component of the

API Platform 2.2k Dec 27, 2022
Proposed REST and GraphQL APIs for Concrete CMS 9.2+

Concrete CMS API Proposal 2022 Hello there! This is a package for Concrete CMS (9.1.1+) that adds a proposed REST API. This API is reasonably comprehe

Concrete CMS 5 Aug 11, 2022
Pure PHP implementation of GraphQL Server – Symfony Bundle

Symfony GraphQl Bundle This is a bundle based on the pure PHP GraphQL Server implementation This bundle provides you with: Full compatibility with the

null 283 Dec 15, 2022
GraphQL Bundle for Symfony 2.

Symfony 2 GraphQl Bundle Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here. Installat

Sergey Varibrus 35 Nov 17, 2022