-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP/POC support prisma 5.4 serverless driver adapters #8847
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Example Project - Extend Prisma Schema | ||
|
||
This project implements an example of mutating the Prisma Schema to: | ||
|
||
- Set the Prisma Binary Target; | ||
- Add a multi-column column unique constraint to a list; and | ||
- Add a NOT NULL relationship field | ||
|
||
These show three separate ways of mutating the Prisma Schema see `keystone.ts` and `schema.ts`. | ||
|
||
## Instructions | ||
|
||
To run this project, clone the Keystone repository locally, run `pnpm` at the root of this repository, then navigate to this directory and run: | ||
|
||
```shell | ||
pnpm dev | ||
``` | ||
|
||
This will start the Admin UI at [localhost:3000](http://localhost:3000). | ||
You can use the Admin UI to create items in your database. | ||
|
||
You can also access a GraphQL Playground at [localhost:3000/api/graphql](http://localhost:3000/api/graphql), which allows you to directly run GraphQL queries and mutations. | ||
|
||
Congratulations, you're now up and running with Keystone! 🚀 | ||
|
||
## Try it out in CodeSandbox 🧪 | ||
|
||
You can play with this example online in a web browser using the free [codesandbox.io](https://codesandbox.io/) service. To launch this example, open the URL <https://githubbox.com/keystonejs/keystone/tree/main/examples/extend-prisma-schema>. You can also fork this sandbox to make your own changes. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { config } from '@keystone-6/core'; | ||
import { Pool, neonConfig } from '@neondatabase/serverless'; | ||
import { PrismaNeon } from '@prisma/adapter-neon'; | ||
import { WebSocket } from 'undici'; | ||
import { fixPrismaPath } from '../example-utils'; | ||
import { lists } from './schema'; | ||
import { PrismaClient } from '.myprisma/client'; | ||
|
||
export default config({ | ||
db: { | ||
provider: 'sqlite', | ||
url: process.env.DATABASE_URL || 'file:./keystone-example.db', | ||
|
||
prismaClient: config => { | ||
neonConfig.webSocketConstructor = WebSocket; | ||
|
||
const pool = new Pool({ connectionString: process.env.DATABASE_URL }); | ||
const adapter = new PrismaNeon(pool); | ||
return new PrismaClient({ | ||
...config, | ||
adapter, | ||
}); | ||
}, | ||
|
||
extendPrismaSchema: (schema: any) => { | ||
return schema.replace( | ||
/(generator [^}]+)}/g, | ||
['$1previewFeatures = ["driverAdapters"]', '}'].join('\n') | ||
); | ||
}, | ||
|
||
// WARNING: this is only needed for our monorepo examples, dont do this | ||
...fixPrismaPath, | ||
}, | ||
lists, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@keystone-6/example-custom-prisma-driver-adapter", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "keystone dev", | ||
"start": "keystone start", | ||
"build": "keystone build", | ||
"postinstall": "keystone postinstall --fix" | ||
}, | ||
"dependencies": { | ||
"@keystone-6/core": "^5.2.0", | ||
"@keystone-6/fields-document": "^8.0.0", | ||
"@neondatabase/serverless": "^0.6.0", | ||
"@prisma/adapter-neon": "^5.4.0", | ||
"@prisma/client": "^5.4.0", | ||
"undici": "^5.25.0" | ||
}, | ||
"devDependencies": { | ||
"prisma": "^5.4.0", | ||
"typescript": "~5.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"template": "node", | ||
"container": { | ||
"startScript": "keystone dev", | ||
"node": "18" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole directory (custom-prisma-driver-adapter) is the copy of the
extend-prisma-schema
example.This could also be the start of showing an example with prisma client extensions like https://github.com/prisma/extension-read-replicas
would be super beneficial for users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking we might use Prisma extensions for hooks in the near future, so it does have me thinking about how this functionality might impact the order of operations there.
As is, if we supported the custom
PrismaClient
, Keystone would be.extend
ing the custom client, which I think is ok?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as far as I know and my testing has gone you call
$extend()
on the prisma client and get a new instance of the prisma client back which extends the "old" prisma client instance but doesn't modify it.The only issue with the current setup of keystone is, that when you call
context.prisma.xxxx
you won't have access to the user or keystone defined extensions as the infered type of the prisma client comes from what ever@prisma/client
resolves to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcousens I love this idea and would make the usage of
context.prisma
overcontext.db
much easier if you have custom logic in list hooks