Skip to content

Commit 2bcb78a

Browse files
committed
Added RQB relations support, fixed entities generating types for non-tables in schema, various minor improvements & fixes
1 parent 8b0ddb6 commit 2bcb78a

File tree

24 files changed

+3596
-2679
lines changed

24 files changed

+3596
-2679
lines changed

.github/workflows/release.yaml

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
name: Release
2-
3-
on: workflow_dispatch
4-
5-
jobs:
6-
release:
7-
permissions: write-all
8-
strategy:
9-
fail-fast: false
10-
matrix:
11-
package:
12-
- drizzle-graphql
13-
runs-on: ubuntu-20.04
14-
steps:
15-
- uses: actions/checkout@v4
16-
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: 18
20-
registry-url: 'https://registry.npmjs.org'
21-
22-
- uses: pnpm/action-setup@v3
23-
name: Install pnpm
24-
id: pnpm-install
25-
with:
26-
version: latest
27-
run_install: false
28-
29-
- name: Get pnpm store directory
30-
id: pnpm-cache
31-
shell: bash
32-
run: |
33-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
34-
35-
- uses: actions/cache@v4
36-
name: Setup pnpm cache
37-
with:
38-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
39-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
40-
restore-keys: |
41-
${{ runner.os }}-pnpm-store-
42-
43-
- name: Install dependencies
44-
run: pnpm install
45-
46-
- name: Build
47-
run: |
48-
pnpm build
49-
50-
- name: Pack
51-
shell: bash
52-
env:
53-
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
54-
run: |
55-
npm run pack
56-
57-
- name: Publish
58-
shell: bash
59-
env:
60-
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
61-
run: |
62-
version="0.1.0"
63-
64-
echo "Publishing ${{ matrix.package }}@$version"
65-
npm run publish --access public --otp ${{ secrets.NPM_OTP }}
66-
67-
echo "npm: \`+ ${{ matrix.package }}@$version\`" >> $GITHUB_STEP_SUMMARY
1+
name: Release
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
release:
7+
permissions: write-all
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
package:
12+
- drizzle-graphql
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 18
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- uses: pnpm/action-setup@v3
23+
name: Install pnpm
24+
id: pnpm-install
25+
with:
26+
version: latest
27+
run_install: false
28+
29+
- name: Get pnpm store directory
30+
id: pnpm-cache
31+
shell: bash
32+
run: |
33+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
34+
35+
- uses: actions/cache@v4
36+
name: Setup pnpm cache
37+
with:
38+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
39+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
40+
restore-keys: |
41+
${{ runner.os }}-pnpm-store-
42+
43+
- name: Install dependencies
44+
run: pnpm install
45+
46+
- name: Build
47+
run: |
48+
pnpm build
49+
50+
- name: Pack
51+
shell: bash
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
54+
run: |
55+
npm run pack
56+
57+
- name: Publish
58+
shell: bash
59+
env:
60+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
61+
run: |
62+
version="0.1.0"
63+
64+
echo "Publishing ${{ matrix.package }}@$version"
65+
npm run publish --access public --otp ${{ secrets.NPM_OTP }}
66+
67+
echo "npm: \`+ ${{ matrix.package }}@$version\`" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
node_modules
2-
package-lock.json
3-
dist
4-
*.sqlite
5-
**/Test
6-
**/Tests
7-
vitest.config.ts
8-
drizzle.config.ts
9-
*.tgz
10-
temp.ts
11-
dist-dts
12-
dist.new
1+
node_modules
2+
package-lock.json
3+
dist
4+
*.sqlite
5+
**/Test
6+
**/Tests
7+
vitest.config.ts
8+
drizzle.config.ts
9+
*.tgz
10+
temp.ts
11+
dist-dts
12+
dist.new
13+
Server

README.md

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
1-
# Drizzle-GraphQL
2-
3-
Automatically create GraphQL schema or customizable schema config fields from Drizzle ORM schema
4-
5-
## Usage
6-
7-
- Pass your drizzle database instance and schema into builder to generate `{ schema, entities }` object
8-
- Use `schema` if pre-built schema already satisfies all your neeeds. It's compatible witn any server that consumes `GraphQLSchema` class instance
9-
10-
Example: hosting schema using [GraphQL Yoga](https://the-guild.dev/graphql/yoga-server)
11-
12-
```Typescript
13-
import { createServer } from 'node:http'
14-
import { createYoga } from 'graphql-yoga'
15-
import { buildVanillaSchema } from 'drizzle-graphql'
16-
17-
// db - your drizzle instance, schema - your drizzle tables
18-
import { db, schema as dbSchema } from './database'
19-
20-
const { schema } = buildVanillaSchema(db, dbSchema)
21-
22-
const yoga = createYoga({ schema })
23-
24-
server.listen(4000, () => {
25-
console.info('Server is running on http://localhost:4000/graphql')
26-
})
27-
```
28-
29-
- If you want to customize your schema, you can use `entities` object to build your own new schema
30-
31-
```Typescript
32-
import { createServer } from 'node:http'
33-
import { GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema } from 'graphql'
34-
import { createYoga } from 'graphql-yoga'
35-
import { buildVanillaSchema } from 'drizzle-graphql'
36-
37-
// Schema contains 'Users' and 'Customers' tables
38-
import { db, schema as dbSchema } from './database'
39-
40-
const { entities } = buildVanillaSchema(db, dbSchema)
41-
42-
// You can customize which parts of queries or mutations you want
43-
const schema = new GraphQLSchema({
44-
query: new GraphQLObjectType({
45-
name: 'Query',
46-
fields: {
47-
// Select only wanted queries out of all generated
48-
users: entities.queries.users,
49-
customer: entities.queries.customersSingle,
50-
51-
// Create a custom one
52-
customUsers: {
53-
// You can reuse and customize types from original schema
54-
type: new GraphQLList(new GraphQLNonNull(entities.types.UsersItem)),
55-
args: {
56-
// You can reuse inputs as well
57-
where: {
58-
type: entities.inputs.UsersFilters
59-
}
60-
},
61-
resolve: async (source, args, context, info) => {
62-
// Your custom logic goes here...
63-
const result = await db.select(schema.Users).where()...
64-
65-
return result
66-
}
67-
}
68-
}
69-
}),
70-
// Same rules apply to mutations
71-
mutation: new GraphQLObjectType({
72-
name: 'Mutation',
73-
fields: entities.mutations
74-
}),
75-
// In case you need types inside your schema
76-
types: [...Object.values(entities.types), ...Object.values(entities.inputs)]
77-
})
78-
79-
const yoga = createYoga({
80-
schema
81-
})
82-
83-
server.listen(4000, () => {
84-
console.info('Server is running on http://localhost:4000/graphql')
85-
})
86-
```
1+
# Drizzle-GraphQL
2+
3+
Automatically create GraphQL schema or customizable schema config fields from Drizzle ORM schema
4+
5+
## Usage
6+
7+
- Pass your drizzle database instance and schema into builder to generate `{ schema, entities }` object
8+
- Use `schema` if pre-built schema already satisfies all your neeeds. It's compatible witn any server that consumes `GraphQLSchema` class instance
9+
10+
Example: hosting schema using [GraphQL Yoga](https://the-guild.dev/graphql/yoga-server)
11+
12+
```Typescript
13+
import { createServer } from 'node:http'
14+
import { createYoga } from 'graphql-yoga'
15+
import { buildVanillaSchema } from 'drizzle-graphql'
16+
17+
// db - your drizzle instance, schema - your drizzle tables
18+
import { db, schema as dbSchema } from './database'
19+
20+
const { schema } = buildVanillaSchema(db, dbSchema)
21+
22+
const yoga = createYoga({ schema })
23+
24+
server.listen(4000, () => {
25+
console.info('Server is running on http://localhost:4000/graphql')
26+
})
27+
```
28+
29+
- If you want to customize your schema, you can use `entities` object to build your own new schema
30+
31+
```Typescript
32+
import { createServer } from 'node:http'
33+
import { GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema } from 'graphql'
34+
import { createYoga } from 'graphql-yoga'
35+
import { buildVanillaSchema } from 'drizzle-graphql'
36+
37+
// Schema contains 'Users' and 'Customers' tables
38+
import { db, schema as dbSchema } from './database'
39+
40+
const { entities } = buildVanillaSchema(db, dbSchema)
41+
42+
// You can customize which parts of queries or mutations you want
43+
const schema = new GraphQLSchema({
44+
query: new GraphQLObjectType({
45+
name: 'Query',
46+
fields: {
47+
// Select only wanted queries out of all generated
48+
users: entities.queries.users,
49+
customer: entities.queries.customersSingle,
50+
51+
// Create a custom one
52+
customUsers: {
53+
// You can reuse and customize types from original schema
54+
type: new GraphQLList(new GraphQLNonNull(entities.types.UsersItem)),
55+
args: {
56+
// You can reuse inputs as well
57+
where: {
58+
type: entities.inputs.UsersFilters
59+
}
60+
},
61+
resolve: async (source, args, context, info) => {
62+
// Your custom logic goes here...
63+
const result = await db.select(schema.Users).where()...
64+
65+
return result
66+
}
67+
}
68+
}
69+
}),
70+
// Same rules apply to mutations
71+
mutation: new GraphQLObjectType({
72+
name: 'Mutation',
73+
fields: entities.mutations
74+
}),
75+
// In case you need types inside your schema
76+
types: [...Object.values(entities.types), ...Object.values(entities.inputs)]
77+
})
78+
79+
const yoga = createYoga({
80+
schema
81+
})
82+
83+
server.listen(4000, () => {
84+
console.info('Server is running on http://localhost:4000/graphql')
85+
})
86+
```

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"name": "drizzle-graphql",
33
"type": "module",
44
"author": "Drizzle Team",
5-
"version": "0.1.1",
5+
"version": "0.2.0",
66
"description": "Automatically generate GraphQL schema or customizable schema config fields from Drizzle ORM schema",
77
"scripts": {
88
"build": "pnpm tsx scripts/build.ts",
99
"b": "pnpm build",
1010
"pack": "(cd dist && npm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz",
11-
"publish": "npm publish package.tgz"
11+
"publish": "npm publish package.tgz",
12+
"server-test:pg": "DB_TYPE=pg tsx watch Server/server.ts",
13+
"server-test:mysql": "DB_TYPE=mysql tsx watch Server/server.ts",
14+
"server-test:sqlite": "DB_TYPE=sqlite tsx watch Server/server.ts"
1215
},
1316
"license": "Apache-2.0",
1417
"devDependencies": {
@@ -65,7 +68,7 @@
6568
"url": "git+https://github.com/Sukairo-02/drizzle-graphql.git"
6669
},
6770
"peerDependencies": {
68-
"drizzle-orm": ">=0.30.1",
71+
"drizzle-orm": ">=0.30.4",
6972
"graphql": ">=16.8.1"
7073
}
7174
}

0 commit comments

Comments
 (0)