segbedji/graphql-typed
最新稳定版本:v0.2.0
Composer 安装命令:
composer require segbedji/graphql-typed
包简介
A Statamic addon that adds type-safe GraphQL arguments for collections, filters, and enums.
README 文档
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
CollectionNameenum from your Statamic collections - Overrides the default
entryandentriesqueries 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:
- CollectionNameEnum - A GraphQL enum type that dynamically generates values from
Collection::all() - TypedEntryQuery - Extends the default
EntryQuerybut uses theCollectionNameenum for thecollectionargument - TypedEntriesQuery - Extends the default
EntriesQuerybut uses theCollectionNameenum for thecollectionargument
Future Improvements
- Add typed filter inputs per collection based on blueprint fields
- Add typed sort options based on available fields
统计信息
- 总下载量: 53
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-23