Skip to content

feat(graphql): add GraphQL plugin with full document CRUD - #1069

Open
lane711 wants to merge 1 commit into
mainfrom
lane711/graphql-integration-plan
Open

feat(graphql): add GraphQL plugin with full document CRUD#1069
lane711 wants to merge 1 commit into
mainfrom
lane711/graphql-integration-plan

Conversation

@lane711

@lane711 lane711 commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds opt-in graphqlPlugin() built on graphql-yoga (Cloudflare Workers-compatible — standard Fetch API, no Node.js http)
  • POST /graphql — query/mutation execution with Bearer API key auth (reuses existing apiKeyAuthMiddleware)
  • GET /graphql — GraphiQL playground
  • Full document ACL enforced per-operation (R1/R3/R4 compliant)
  • README updated with GraphQL section and usage examples

Schema

type Query {
  documents(typeId: String, status: String, limit: Int, cursor: String): DocumentPage!
  document(id: String!): Document
}

type Mutation {
  createDocument(typeId: String!, title: String, slug: String, data: JSON!, publishOnCreate: Boolean): Document!
  updateDocument(id: String!, title: String, slug: String, data: JSON): Document!
  publishDocument(id: String!): Document!
  unpublishDocument(id: String!): Document!
  deleteDocument(id: String!): Boolean!
}

Test plan

  • GET /graphql returns GraphiQL HTML
  • POST introspection returns Query, Mutation, Document, DocumentPage, JSON types
  • documents(status:"all") returns paginated results with keyset cursor
  • Unauthenticated mutation returns auth error (not 500)
  • E2E: 100-graphql.spec.ts @api — mint API key → create → publish → delete flow

Usage

import { graphqlPlugin, createSonicJSApp } from '@sonicjs-cms/core'

export default createSonicJSApp({
  plugins: { register: [graphqlPlugin()] },
})

🤖 Generated with Claude Code

Adds opt-in graphqlPlugin() that mounts a GraphQL API at /graphql
using graphql-yoga (Cloudflare Workers-compatible).

- POST /graphql: query/mutation execution (Bearer API key auth)
- GET /graphql: GraphiQL playground
- Queries: documents(typeId, status, limit, cursor), document(id)
- Mutations: createDocument, updateDocument, publishDocument,
  unpublishDocument, deleteDocument
- JSON scalar, keyset pagination cursor, full document ACL enforcement
- All reads via DocumentRepository (R4), writes via DocumentsService (R1)
- E2E test: tests/e2e/100-graphql.spec.ts @api

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant