-
Notifications
You must be signed in to change notification settings - Fork 787
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
Update 140-shared-extensions.mdx #5277
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -13,21 +13,50 @@ If you would like to build a shareable extension, we also recommend using the [` | |||
|
|||
</TopBlock> | |||
|
|||
## Create a generic extension | |||
## Install a shared extension |
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.
Move the "install" block to the top instead of hiding it at the bottom
This PR changes the following pages (Vercel Preview Deploy links): Changed Vercel links (Note that links will only be valid after Vercel preview deploy succeeded) |
## Create a sharable extension | ||
|
||
When you want to create extensions other users can use, and that are not tailored just for your schema, Prisma provides utilities to allow you to create shareable extensions. | ||
|
||
To create a shareable extension: | ||
|
||
1. Define the extension as a module using `Prisma.defineExtension` | ||
2. Use one of the methods that begin with the `$all` prefix such as [`$allModels`](/concepts/components/prisma-client/client-extensions/model#add-a-custom-method-to-all-models-in-your-schema) or [`$allOperations`](/concepts/components/prisma-client/client-extensions/query#modify-all-prisma-client-operations) |
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.
New intro for the "create" section
This PR probably requires the following redirects to be added to vercel.json:
|
### Define an extension | ||
|
||
Use the `Prisma.defineExtension` method to make your extension shareable. You can use it to package the extension to either separate your extensions into a separate file or share it with other users as an npm package. | ||
|
||
The benefit of `Prisma.defineExtension` is that it provides strict type checks and auto completion for authors of extension in development and users of shared extensions. |
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.
About Prisma.defineExtension
|
||
The benefit of `Prisma.defineExtension` is that it provides strict type checks and auto completion for authors of extension in development and users of shared extensions. | ||
|
||
### Use a generic method |
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.
Section about the generic methods
@@ -70,8 +99,14 @@ export default Prisma.defineExtension({ | |||
|
|||
</details> | |||
|
|||
### Publishing the shareable extension to Npm |
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.
New headline to highlight how to publish to Npm
## Other considerations | ||
|
||
bla bla, other things to be aware or take advantage of |
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.
New intro for the "other" stuff that comes below
## Install a packaged extension | ||
|
||
In your project, you can install any Prisma Client extension that another user has published to `npm`. To do so, run the following command: | ||
|
||
```terminal | ||
npm install prisma-extension-<package-name> | ||
``` | ||
|
||
For example, if the package name for an available extension is `prisma-extension-find-or-create`, you could install it as follows: | ||
|
||
```terminal | ||
npm install prisma-extension-find-or-create | ||
``` | ||
|
||
To import the `find-or-create` extension from the example above, and wrap your client instance with it, you could use the following code. This example assumes that the extension name is `findOrCreate`. | ||
|
||
```ts | ||
import findOrCreate from 'prisma-extension-find-or-create' | ||
|
||
const xprisma = prisma.$extends(findOrCreate) | ||
const user = await xprisma.user.findOrCreate({ ... }) | ||
|
||
xprisma.user.findOrCreate() | ||
``` | ||
|
||
When you call a method in an extension, use the constant name from your `$extends` statement, not `prisma`. In the above example,`xprisma.user.findOrCreate` works, but `prisma.user.findOrCreate` does not, because the original `prisma` is not modified. |
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.
Moved to the top
...200-concepts/100-components/02-prisma-client/053-client-extensions/140-shared-extensions.mdx
Outdated
Show resolved
Hide resolved
…t-extensions/140-shared-extensions.mdx Co-authored-by: Jon Harrell <[email protected]>
Fixed the conflict. Review and merge would be appreciated to avoid having to do that again. |
see comments