@graphql-suite/query 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Annexare Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,191 @@
1
+ [![Monthly Downloads](https://img.shields.io/npm/dm/drizzle-graphql-suite.svg)](https://www.npmjs.com/package/drizzle-graphql-suite)
2
+ [![NPM](https://img.shields.io/npm/v/drizzle-graphql-suite.svg 'NPM package version')](https://www.npmjs.com/package/drizzle-graphql-suite)
3
+ [![CI](https://github.com/annexare/drizzle-graphql-suite/actions/workflows/ci.yml/badge.svg)](https://github.com/annexare/drizzle-graphql-suite/actions/workflows/ci.yml)
4
+
5
+ # drizzle-graphql-suite
6
+
7
+ Auto-generated GraphQL CRUD, type-safe clients, and React Query hooks from Drizzle PostgreSQL schemas.
8
+
9
+ ## Overview
10
+
11
+ `drizzle-graphql-suite` is a three-layer toolkit that turns your Drizzle ORM schema into a fully working GraphQL API with end-to-end type safety:
12
+
13
+ 1. **Schema builder** — generates a complete GraphQL schema with CRUD operations, relation-level filtering, per-operation hooks, and runtime permissions from Drizzle table definitions.
14
+ 2. **Client** — provides a type-safe GraphQL client that infers query/mutation types directly from your Drizzle schema, with full TypeScript support for filters, relations, and results.
15
+ 3. **React Query hooks** — wraps the client in TanStack React Query hooks for caching, pagination, and mutations with automatic cache invalidation.
16
+
17
+ Inspired by [`drizzle-graphql`](https://github.com/drizzle-team/drizzle-graphql), rewritten with significant improvements including relation-level filtering, hooks, count queries, configurable schema generation, and code generation.
18
+
19
+ ## Packages
20
+
21
+ | Subpath | Package | Description |
22
+ |---------|---------|-------------|
23
+ | `drizzle-graphql-suite/schema` | [`@drizzle-graphql-suite/schema`](packages/schema/README.md) | GraphQL schema builder with CRUD, filtering, hooks, permissions, and codegen |
24
+ | `drizzle-graphql-suite/client` | [`@drizzle-graphql-suite/client`](packages/client/README.md) | Type-safe GraphQL client with full Drizzle type inference |
25
+ | `drizzle-graphql-suite/query` | [`@drizzle-graphql-suite/query`](packages/query/README.md) | TanStack React Query hooks for the client |
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ bun add drizzle-graphql-suite
31
+ ```
32
+
33
+ ```bash
34
+ npm install drizzle-graphql-suite
35
+ ```
36
+
37
+ ## Peer Dependencies
38
+
39
+ Each subpath import has its own peer dependency requirements:
40
+
41
+ | Subpath | Peer Dependencies |
42
+ |---------|-------------------|
43
+ | `./schema` | `drizzle-orm` >=0.44.0, `graphql` >=16.3.0 |
44
+ | `./client` | `drizzle-orm` >=0.44.0 |
45
+ | `./query` | `react` >=18.0.0, `@tanstack/react-query` >=5.0.0 |
46
+
47
+ ## Quick Start
48
+
49
+ ### 1. Server — Build GraphQL Schema
50
+
51
+ ```ts
52
+ import { buildSchema } from 'drizzle-graphql-suite/schema'
53
+ import { createYoga } from 'graphql-yoga'
54
+ import { createServer } from 'node:http'
55
+ import { db } from './db'
56
+
57
+ const { schema, withPermissions } = buildSchema(db, {
58
+ tables: { exclude: ['session', 'verification'] },
59
+ hooks: {
60
+ user: {
61
+ query: {
62
+ before: async ({ context }) => {
63
+ if (!context.user) throw new Error('Unauthorized')
64
+ },
65
+ },
66
+ },
67
+ },
68
+ })
69
+
70
+ const yoga = createYoga({ schema })
71
+ const server = createServer(yoga)
72
+ server.listen(4000)
73
+ ```
74
+
75
+ #### Per-Role Schemas (Optional)
76
+
77
+ ```ts
78
+ import { permissive, restricted, readOnly } from 'drizzle-graphql-suite/schema'
79
+
80
+ // Cached per id — call withPermissions on each request
81
+ const schemas = {
82
+ admin: schema,
83
+ editor: withPermissions(permissive('editor', { audit: false, user: readOnly() })),
84
+ viewer: withPermissions(restricted('viewer', { post: { query: true } })),
85
+ }
86
+ ```
87
+
88
+ ### 2. Client — Type-Safe Queries
89
+
90
+ ```ts
91
+ import { createDrizzleClient } from 'drizzle-graphql-suite/client'
92
+ import * as schema from './db/schema'
93
+
94
+ const client = createDrizzleClient({
95
+ schema,
96
+ config: { suffixes: { list: 's' } },
97
+ url: '/api/graphql',
98
+ })
99
+
100
+ const users = await client.entity('user').query({
101
+ select: {
102
+ id: true,
103
+ name: true,
104
+ posts: { id: true, title: true },
105
+ },
106
+ where: { name: { ilike: '%john%' } },
107
+ limit: 10,
108
+ })
109
+ ```
110
+
111
+ ### 3. React — Query Hooks
112
+
113
+ ```tsx
114
+ import { GraphQLProvider, useEntity, useEntityList } from 'drizzle-graphql-suite/query'
115
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
116
+
117
+ const queryClient = new QueryClient()
118
+
119
+ function App() {
120
+ return (
121
+ <QueryClientProvider client={queryClient}>
122
+ <GraphQLProvider client={graphqlClient}>
123
+ <UserList />
124
+ </GraphQLProvider>
125
+ </QueryClientProvider>
126
+ )
127
+ }
128
+
129
+ function UserList() {
130
+ const user = useEntity('user')
131
+ const { data, isLoading } = useEntityList(user, {
132
+ select: { id: true, name: true, email: true },
133
+ limit: 20,
134
+ })
135
+
136
+ if (isLoading) return <div>Loading...</div>
137
+ return <ul>{data?.map((u) => <li key={u.id}>{u.name}</li>)}</ul>
138
+ }
139
+ ```
140
+
141
+ ## Framework Integration Examples
142
+
143
+ `buildSchema()` returns a standard `GraphQLSchema` — here's how to serve it from popular frameworks.
144
+
145
+ ### Next.js App Router
146
+
147
+ ```ts
148
+ // app/api/graphql/route.ts
149
+ import { createYoga } from 'graphql-yoga'
150
+ import { buildSchema } from 'drizzle-graphql-suite/schema'
151
+ import { db } from '@/db'
152
+
153
+ const { schema } = buildSchema(db)
154
+
155
+ const { handleRequest } = createYoga({
156
+ schema,
157
+ graphqlEndpoint: '/api/graphql',
158
+ fetchAPI: { Response },
159
+ })
160
+
161
+ export { handleRequest as GET, handleRequest as POST }
162
+ ```
163
+
164
+ ### ElysiaJS
165
+
166
+ ```ts
167
+ // server.ts
168
+ import { Elysia } from 'elysia'
169
+ import { yoga } from '@elysiajs/graphql-yoga'
170
+ import { buildSchema } from 'drizzle-graphql-suite/schema'
171
+ import { db } from './db'
172
+
173
+ const { schema } = buildSchema(db)
174
+
175
+ new Elysia()
176
+ .use(yoga({ schema }))
177
+ .listen(3000)
178
+ ```
179
+
180
+ ## AI Agent Skill
181
+
182
+ This repo includes a [skills.sh](https://skills.sh) skill that provides AI coding agents (Claude Code, Cursor, etc.) with accurate, up-to-date guidance for all three packages.
183
+
184
+ ```bash
185
+ bunx skills add annexare/drizzle-graphql-suite
186
+ # or: npx skills add annexare/drizzle-graphql-suite
187
+ ```
188
+
189
+ ## License
190
+
191
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@drizzle-graphql-suite/query'
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@drizzle-graphql-suite/query'
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@graphql-suite/query",
3
+ "version": "0.8.3",
4
+ "description": "React Query hooks for the Drizzle GraphQL client with caching and automatic invalidation",
5
+ "license": "MIT",
6
+ "author": "https://github.com/dmythro",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/annexare/drizzle-graphql-suite.git",
10
+ "directory": "packages/query"
11
+ },
12
+ "type": "module",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "main": "./index.js",
17
+ "types": "./index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./index.d.ts",
21
+ "import": "./index.js"
22
+ }
23
+ },
24
+ "dependencies": {
25
+ "@drizzle-graphql-suite/query": "0.8.3"
26
+ },
27
+ "peerDependencies": {
28
+ "@drizzle-graphql-suite/client": ">=0.7.0",
29
+ "@tanstack/react-query": ">=5.0.0",
30
+ "react": ">=18.0.0"
31
+ }
32
+ }