Skip to content
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

Merged
merged 3 commits into from
Oct 13, 2023

Conversation

janpio
Copy link
Contributor

@janpio janpio commented Sep 5, 2023

see comments

@vercel
Copy link

vercel bot commented Sep 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 13, 2023 7:37pm

@@ -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
Copy link
Contributor Author

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

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)

Comment on lines +43 to 50
## 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)
Copy link
Contributor Author

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

This PR probably requires the following redirects to be added to vercel.json:

  • This PR does not change any pages in a way that would require a redirect.

Comment on lines 52 to +56
### 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.
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Comment on lines +106 to +108
## Other considerations

bla bla, other things to be aware or take advantage of
Copy link
Contributor Author

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

Comment on lines 116 to 141
## 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top

…t-extensions/140-shared-extensions.mdx

Co-authored-by: Jon Harrell <[email protected]>
@janpio janpio requested a review from jharrell October 13, 2023 19:33
@janpio
Copy link
Contributor Author

janpio commented Oct 13, 2023

Fixed the conflict. Review and merge would be appreciated to avoid having to do that again.

@jharrell jharrell merged commit d3769ad into shared-extensions-improvements Oct 13, 2023
@jharrell jharrell deleted the janpio-patch-27 branch October 13, 2023 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants