Skip to content

Commit 161ae5c

Browse files
Update GraphQL examples with prisma.config.ts and pg adapter (#8345)
1 parent fcdff40 commit 161ae5c

49 files changed

Lines changed: 306 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

orm/fastify-graphql-sdl-first/package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"dependencies": {
1313
"@graphql-tools/schema": "10.0.26",
1414
"@prisma/client": "6.18.0",
15-
"@prisma/extension-accelerate": "2.0.2",
16-
"dotenv": "16.6.1",
15+
"@prisma/adapter-pg": "6.18.0",
16+
"dotenv": "^17.2.1",
1717
"fastify": "5.6.1",
1818
"graphql": "16.11.0",
1919
"graphql-scalars": "1.24.2",
@@ -24,8 +24,5 @@
2424
"prisma": "6.18.0",
2525
"tsx": "4.20.6",
2626
"typescript": "5.8.2"
27-
},
28-
"prisma": {
29-
"seed": "tsx prisma/seed.ts"
3027
}
31-
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig, env } from 'prisma/config'
2+
import 'dotenv/config'
3+
4+
export default defineConfig({
5+
schema: 'prisma/schema.prisma',
6+
migrations: {
7+
path: 'prisma/migrations',
8+
seed: 'tsx ./prisma/seed.ts',
9+
},
10+
engine: 'classic',
11+
datasource: {
12+
url: env('DATABASE_URL'),
13+
},
14+
})
15+
16+

orm/fastify-graphql-sdl-first/prisma/seed.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { PrismaClient, Prisma } from './generated/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
2+
import { PrismaPg } from '@prisma/adapter-pg'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
const userData: Prisma.UserCreateInput[] = [
78
{

orm/fastify-graphql-sdl-first/src/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { PrismaPg } from '@prisma/adapter-pg'
12
import { PrismaClient } from '../prisma/generated/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
export interface Context {
78
prisma: typeof prisma

orm/fastify-graphql/README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,21 @@ We found an existing schema.prisma file in your current project directory.
7272
7373
--- Database URL ---
7474
75-
Connect Prisma ORM to your Prisma Postgres database with this URL:
76-
77-
prisma+postgres://accelerate.prisma-data.net/?api_key=...
75+
Connect Prisma ORM to your Prisma Postgres database with the provided URL. Add it to your `.env` as `DATABASE_URL`.
7876
7977
--- Next steps ---
8078
8179
Go to https://pris.ly/ppg-init for detailed instructions.
8280
83-
1. Install and use the Prisma Accelerate extension
84-
Prisma Postgres requires the Prisma Accelerate extension for querying. If you haven't already installed it, install it in your project:
85-
npm install @prisma/extension-accelerate
86-
87-
...and add it to your Prisma Client instance:
88-
import { withAccelerate } from "@prisma/extension-accelerate"
89-
90-
const prisma = new PrismaClient().$extends(withAccelerate())
81+
1. Install the `@prisma/adapter-pg` driver adapter and configure your Prisma Client instance
82+
```bash
83+
npm install @prisma/adapter-pg
84+
```
85+
```ts
86+
import { PrismaPg } from '@prisma/adapter-pg'
87+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
88+
const prisma = new PrismaClient({ adapter: pool })
89+
```
9190

9291
2. Apply migrations
9392
Run the following command to create and apply a migration:
@@ -119,7 +118,7 @@ Now, paste the URL into it as a value for the `DATABASE_URL` environment variabl
119118

120119
```bash
121120
# .env
122-
DATABASE_URL=prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
121+
DATABASE_URL=postgres://<username>:<password>@<host>:<port>/<database>
123122
```
124123

125124
Run the following command to create tables in your database. This creates the `User` and `Post` tables that are defined in [`prisma/schema.prisma`](./prisma/schema.prisma):
@@ -584,24 +583,9 @@ Learn more about the different connection configurations in the [docs](https://w
584583

585584
<details><summary>Expand for an overview of example configurations with different databases</summary>
586585

587-
### Remove the Prisma Client extension
588-
589-
Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres:
590-
591-
```terminal
592-
npm uninstall @prisma/extension-accelerate
593-
```
594-
595-
Remove the client extension from your `PrismaClient`:
596-
597-
```diff
598-
- const prisma = new PrismaClient().$extends(withAccelerate())
599-
+ const prisma = new PrismaClient()
600-
```
601-
602586
### Your own PostgreSQL database
603587

604-
To use your own PostgreSQL database remove the `@prisma/extension-accelerate` package and remove the Prisma client extension.
588+
To use your own PostgreSQL database, set `DATABASE_URL` to your connection string (e.g. `postgres://<username>:<password>@<host>:<port>/<database>`). Ensure your app initializes `PrismaClient` with the `@prisma/adapter-pg` driver adapter as shown above.
605589

606590
### SQLite
607591

orm/fastify-graphql/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"@prisma/client": "6.18.0",
10-
"@prisma/extension-accelerate": "2.0.2",
10+
"@prisma/adapter-pg": "6.18.0",
1111
"dotenv": "16.6.1",
1212
"fastify": "5.6.1",
1313
"graphql": "16.11.0",
@@ -17,11 +17,9 @@
1717
},
1818
"devDependencies": {
1919
"@types/node": "22.18.12",
20+
"dotenv": "^17.2.1",
2021
"prisma": "6.18.0",
2122
"tsx": "4.20.6",
2223
"typescript": "5.8.2"
23-
},
24-
"prisma": {
25-
"seed": "tsx prisma/seed.ts"
2624
}
27-
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig, env } from 'prisma/config'
2+
import 'dotenv/config'
3+
4+
export default defineConfig({
5+
schema: 'prisma/schema.prisma',
6+
migrations: {
7+
path: 'prisma/migrations',
8+
seed: 'tsx ./prisma/seed.ts',
9+
},
10+
engine: 'classic',
11+
datasource: {
12+
url: env('DATABASE_URL'),
13+
},
14+
})
15+
16+

orm/fastify-graphql/prisma/seed.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { PrismaClient, Prisma } from './generated/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
2+
import { PrismaPg } from '@prisma/adapter-pg'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
const userData: Prisma.UserCreateInput[] = [
78
{

orm/fastify-graphql/src/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { PrismaPg } from '@prisma/adapter-pg'
12
import { PrismaClient } from '../prisma/generated/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
export interface Context {
78
prisma: typeof prisma

orm/graphql-auth/package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"dependencies": {
1919
"@apollo/server": "4.12.2",
2020
"@prisma/client": "6.18.0",
21-
"@prisma/extension-accelerate": "2.0.2",
22-
"bcryptjs": "3.0.3",
23-
"dotenv": "16.6.1",
21+
"@prisma/adapter-pg": "6.18.0",
22+
"bcryptjs": "3.0.2",
23+
"dotenv": "^17.2.1",
2424
"graphql": "16.11.0",
2525
"graphql-middleware": "6.1.35",
2626
"graphql-scalars": "1.24.2",
@@ -35,8 +35,5 @@
3535
"prisma": "6.18.0",
3636
"tsx": "4.20.6",
3737
"typescript": "5.8.2"
38-
},
39-
"prisma": {
40-
"seed": "tsx prisma/seed.ts"
4138
}
42-
}
39+
}

0 commit comments

Comments
 (0)