segbedji/graphql-typed

A Statamic addon that adds type-safe GraphQL arguments for collections, filters, and enums.

Maintainers

Package info

github.com/JustinyAhin/statamic-graphql-typed

Type:statamic-addon

pkg:composer/segbedji/graphql-typed

Statistics

Installs: 53

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-04-06 13:56 UTC

This package is auto-updated.

Last update: 2026-05-06 14:09:24 UTC


README

A Statamic addon that adds type-safe GraphQL arguments for better developer experience when using typed GraphQL clients.

The Problem

Statamic's default GraphQL schema uses String for collection names and JsonArgument for filters:

entries(collection: [String], filter: JsonArgument, ...): EntryInterfacePagination

This means GraphQL clients like gqty, graphql-codegen, or Apollo can't provide autocomplete or type checking for these arguments.

The Solution

This addon replaces the collection argument with a dynamically generated CollectionName enum based on your actual collections:

enum CollectionName {
  ARTICLES
  PAGES
  # ... auto-generated from your collections
}

entries(collection: [CollectionName], ...): EntryInterfacePagination

Features

  • Dynamically generates CollectionName enum from your Statamic collections
  • Overrides the default entry and entries queries to use the typed enum
  • Zero configuration required - just install and regenerate your client types

Installation

composer require segbedji/graphql-typed

Usage

After installing, regenerate your GraphQL client types. The collection argument will now be typed as CollectionName enum instead of String.

Before (untyped)

query.entries({ collection: ['articles'] }) // 'articles' is just a string, no validation

After (typed)

query.entries({ collection: [CollectionName.ARTICLES] }) // Type-safe enum value

How It Works

The addon registers:

  1. CollectionNameEnum - A GraphQL enum type that dynamically generates values from Collection::all()
  2. TypedEntryQuery - Extends the default EntryQuery but uses the CollectionName enum for the collection argument
  3. TypedEntriesQuery - Extends the default EntriesQuery but uses the CollectionName enum for the collection argument

Future Improvements

  • Add typed filter inputs per collection based on blueprint fields
  • Add typed sort options based on available fields