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

The future of Nexus Prisma Plugin #1039

Closed
martzoukos opened this issue Jan 27, 2021 · 146 comments
Closed

The future of Nexus Prisma Plugin #1039

martzoukos opened this issue Jan 27, 2021 · 146 comments

Comments

@martzoukos
Copy link
Collaborator

martzoukos commented Jan 27, 2021

👉 Go to the new Prisma plugin for Nexus: https://github.com/prisma/nexus-prisma


Hello Prisma friends,

it has not been a secret that maintenance work of the nexus-prisma-plugin has lagged behind the past few months. In this GitHub issue, we want to provide an update on the current state of the plugin and give you a taste of what is coming next.

State of the codebase

The initial version of the codebase was created in a short period of time and has accumulated a lot of technical debt since then. This makes it difficult for us to maintain, and even more difficult to bring new features to the plugin at the moment.

The new Nexus Prisma Plugin

Considering the current state of the codebase and the varying types of issues, it is clear to us that we need to take a step back and, with all the accumulated knowledge so far, rethink how we want this to work.

The vision we came up with is a lighter plugin which will replace the current API (like t.modeland the experimental t.crud) with a set of more programmatic capabilities for you to iterate over your Prisma Schema and create functionality like the existing and more.

This will allow us to properly maintain and support this new plugin surface in the long term and it will enable you to solve many of the issues you face like iterating over a large number of models or creating custom middleware.

What happens in the current releases

The unfortunate news are that in order to focus all of our efforts in the new version of the plugin, we will need to limit our time in maintaining the current versions, so we will have to temporarily drop support for the current versions of the plugin, which means that:

  • We will not be able to fix any issues for the current versions of the plugin.
  • No new releases of the plugin to keep it up to date with new Prisma Client versions will be made, so the latest supported Client version is 2.14.0. If you want to use the newer Prisma versions, you can remove the Prisma plugin and still enjoy the Prisma benefits with Nexus. Feel free to reach out to us (e.g. on Slack) if you have any questions about removing the the nexus-plugin-prisma from your application. We also plan to write a migration guide for this and we'll let you know in the coming weeks about it.

We apologize for the inconvenience and the delay in resolving your issues! Hopefully the improvements we introduce will make your wait worthwhile.

Let us know if you have any questions by posting a comment in this issue, we're always happy to help! 💚

@martzoukos martzoukos pinned this issue Jan 27, 2021
@narciero
Copy link

@martzoukos Thanks for the update and the work you guys are doing...are you able to provide a rough estimate/timeline of when this new version of the plugin will be available? I think that would help those of us trying to decide whether to ditch the plugin or wait it out with the current version. Thanks!

@martzoukos
Copy link
Collaborator Author

Hey @narciero , that's a good question.

Our current estimates are end of Q1 or beginning of Q2. We're still early in this journey, so we'll be able to provide more frequent and accurate updates in the coming months.

@lvauvillier
Copy link
Contributor

Thanks a lot for this update. This is good news 👍

I think the community can help to maintain the current codebase to match future version of prisma and let you guys focus on the next version.

I already made a PR (#1033) to support prisma 2.15.0.

@martzoukos
Copy link
Collaborator Author

I think the community can help to maintain the current codebase to match future version of prisma and let you guys focus on the next version.

That would be amazing 👌. Any help is appreciated!

Thank you Luc.

@lewebsimple
Copy link

lewebsimple commented Jan 29, 2021

Excellent news for the long-term stability of Nexus / Prisma integration !
Middleware support is exciting stuff, are there public RFC somewhere ?

@PerfectedApp
Copy link

Please support multiple Prisma clients! :-/ #992

@bw
Copy link

bw commented Feb 1, 2021

Side note — Are there other companies using Prisma and/or Nexus in production settings? If so, I would love to reach out to you and create a "support group" of sorts as we work through what this all means, and what good paths forward remain. My email is on my GitHub profile.

My guess is that our needs are a bit different from folks just building smaller projects or using these frameworks as gateways to experiment with GraphQL. All these transitions and migrations have serious capital and productivity costs. Every migration as a package gets deprecated is expensive, and often we make these calls expecting that the migration will be the last one for a while. While I don't mean to be negative or ungrateful, we've just spent weeks migrating over from Nexus Framework after the migration guide for it specifically mentioned "Nexus Schema Prisma plugin is not being shut down." A stop of all bugfixes and being pegged to an old package is certainly cause for concern.

Of course, I'm very appreciative of the open source community and developers working hard to improve this project, which I understand can mean making tough decisions like this. It's just that the business side of me needs to make practical decisions; the developer side of me wish you all a great rewrite & success story!

@nikolasburk
Copy link
Contributor

Hey everyone!

We just published the first half of the migration guide covering the migration from t.model() to vanilla Nexus here. The path to migrate CRUD operations from t.crud() will be added very soon, sorry for the delay! 🙏

I also would like to add a few things to Spiros' (@martzoukos) initial message above!

We are very aware that the decision to rewrite the plugin and temporarily remove support for it came very suddenly and without prior notice. This understandably caused a lot of frustration among a lot of you and we want to sincerely apologize for that! Note that during the rewrite we'll try to merge PRs from the community on a best effort basis that helps keep the plugin in sync with Prisma releases. Shoutout to @lvauvillier for his amazing work on the first PR! 💪

As Spiros mentioned before, the plugin had been initially developed in a very short period of time and accumulated a lot of technical debt since its initial release. Little thought went into architectural decisions at the beginning which left the entire codebase in a "prototype" state. Additionally, several organizational changes at Prisma over the past year had led to it not having a clear owner within our organization. This resulted in poor internal and external communication about the general state of the plugin and its codebase.

We are very sorry for the frustration this poor communication has caused. We understand that a lot of you are building mission-critical software on top of our tools and these kinds of changes have real impacts on real businesses. While we strongly believe that a rewrite is the only viable path forward to maintain the plugin long-term, we want to help you as best as possible when making decisions about how to move forward with your stack. Feel free to reach out to me personally or leave a comment in this issue if you have any further questions!

We also want to emphasize that we're doing our very best to not end up in a similar situation again! The good news in that regard is that the plugin now has a dedicated Product Manager (@martzoukos) with a commitment to make it a proper long-term solution for folks that want to build GraphQL servers with Prisma and Nexus. Additionally, you can now also track the development of the rewrite on Prisma's official roadmap.

@homoky
Copy link

homoky commented Feb 5, 2021

I don't get the enthusiasm here with dropping the support of new prisma versions. There is literally nobody here that uses Nexus Prisma plugin in production? I guess that you don't care about keeping up to date with the "stack" that you have been slowly forced over the time and now peacefully accept that we will stop for a few months till it will be ready again so we can update our projects. Then after a year or two same thing will happen again, and again. The same thing happened with Yoga, then with Nexus "project" itself, and so on. I think the size of "product" reached some level and it should be kept update till new version is available. Same as with the Prisma migrate.

@homoky
Copy link

homoky commented Feb 5, 2021

And I would like also add that I am pretty sure that a lot of people using this in production don't have any idea that this will happen and would be very surprised about this decision.

@mikkelsl
Copy link

mikkelsl commented Feb 5, 2021

I have been frustrated as well, especially with the Nexus framework deprecation.

But at the end of the day moving fast and breaking things is what enables the end product to become so **** good. Our confidence and productivity would never have been the same without the tools that you're making, even after taking migrations into account. As soon as it stabilizes, I can't even imagine, how fast we'll be able to move.

Thank you for creating so much value for absolute free. We look forward to becoming a customer at some point.

@lvauvillier
Copy link
Contributor

The current plugin has lacks of control on what capabilities cruds exposes. Some nested operation are available (create, connect etc.) and it can open serious security issues. This results on a lot of extra code and validation / filtering hacks before going to production which breaks the main purpose of this plugin: simplicity.

After spending some time in the plugin codebase to figure out how to add hooks to add more control, i agree that adding new features is currently painful. I'm really happy to hear that Prisma takes it seriously and start a complete rewrite having this in mind, this is a really good thing.

For people that are using it in production:

The rewrite is planned to end of Q1 / beginning of Q2, so this is a relatively short timeframe and Prisma Team now accepts community PR to support new version of prisma 🙏.

I just don't understand why you are pushing to remove the plugin. If you can share the new API draft, this will definitely helps us to make a decision to wait the new version or to start removing the plugin.

@homoky
Copy link

homoky commented Feb 5, 2021

I just don't understand why you are pushing to remove the plugin. If you can share the new API draft, this will definitely helps us to make a decision to wait the new version or to start removing the plugin.

Yeah, it does not make any sense.

@nikolasburk
Copy link
Contributor

nikolasburk commented Feb 5, 2021

I just don't understand why you are pushing to remove the plugin.

Sorry if this was misinterpreted: I don't think we're pushing anyone to remove the plugin but we definitely want to provide the option for folks who want to do this, that's why we're publishing the guide.

I elaborated a bit on in which scenarios it might make sense for folks to remove the plugin from their projects on Slack today:

  • Do you want/need to upgrade your app to the latest Prisma release in the next few months? If yes, you should probably migrate away to be able to do that. If you don't care about upgrading your Prisma versions too much, you can consider keeping the plugin as is. Also note that we're merging PRs that keep the plugin in sync with Prisma releases on a best effort basis, so in the best case it can be kept up to date for the coming weeks (however, since it's on best effort basis, we can't fully guarantee this).
  • The rewrite of the plugin also most likely will come with a new API, resulting in breaking changes. Therefore, even when upgrading to the rewritten version you'll need to make changes to your codebase.
  • It also depends a bit on the size of your datamodel and which features of the plugin you're using. If you're using mostly t.model without pagination, filtering and ordering enabled on list relation fields, the migration should be very quick. If you are using these pagination, filtering and ordering capabilities and/or t.crud a lot in your API, the migration will probably require you to write a lot of boilerplate in which case you have to be aware that this migration might be quite a time investment. (By the way, if your entire API is only based on t.crud, you might even consider switching to TypeGraphQL which similarly to the Nexus plugin provides a very quick way to generate a full CRUD API for Prisma models, we we just added one to our prisma-examples repo.)
Screenshot of the Slack convo

image

So, ultimately, this is a decision that you need to make in the context of your project (the good ol' "it depends" 🙃 ). If you have any questions and would like some individual advice, don't hesitate to reach out to me!

If you can share the new API draft, this will definitely helps us to make a decision to wait the new version or to start removing the plugin.

We definitely want the development process to be transparent and share as much info as possible with you. I've raised this internally and will keep you posted about any updates in that regard! 🙏

@BjoernRave
Copy link

I'm confident, that the community will manage to bridge the migration time with keeping the prisma version up to date :)

@jasonkuhrt

This comment has been minimized.

@TLadd
Copy link

TLadd commented Feb 7, 2021

@jasonkuhrt Thank you for sharing those design sketches. It was very helpful for me to understand the general direction y'all are heading when evaluating what I wanted to do about our current nexus-plugin-prisma usage. Thankfully we were mostly just using t.model so the migration to vanilla nexus shouldn't be too bad. Although I was initially a bit frustrated, when I look at how little we're actually using nexus-plugin-prisma due to shortcomings (t.crud exposing too much, wanting to use relay pagination etc), it makes a lot of sense to start back at building good primitives.

@cesarve77
Copy link

I don't get the enthusiasm here with dropping the support of new prisma versions. There is literally nobody here that uses Nexus Prisma plugin in production? I guess that you don't care about keeping up to date with the "stack" that you have been slowly forced over the time and now peacefully accept that we will stop for a few months till it will be ready again so we can update our projects. Then after a year or two same thing will happen again, and again. The same thing happened with Yoga, then with Nexus "project" itself, and so on. I think the size of "product" reached some level and it should be kept update till new version is available. Same as with the Prisma migrate.

Same happens with GraphCool, Prisma 1, Nexus Framework, now this.

I have a big project running on Prisma 1, with no more support, and basic missing functionalities (they promise to finish soon hehe of curse).

Prisma guys, you need to find better guidance

@BiscuiTech
Copy link

I don't get the enthusiasm here with dropping the support of new prisma versions. There is literally nobody here that uses Nexus Prisma plugin in production? I guess that you don't care about keeping up to date with the "stack" that you have been slowly forced over the time and now peacefully accept that we will stop for a few months till it will be ready again so we can update our projects. Then after a year or two same thing will happen again, and again. The same thing happened with Yoga, then with Nexus "project" itself, and so on. I think the size of "product" reached some level and it should be kept update till new version is available. Same as with the Prisma migrate.

With any package that is tagged 0.xx.xx, you are taking the risk of having stuff like this happen. Their liability ends at the right semver semantics. If you include such a package into your business critical path, the risks are on you and you need to have developers ready to swap out the next version.

@MikaStark
Copy link

I agree with @homoky. I use Nexus Plugin Prisma in production for internal back-office projects and so I use CRUD feature a lot (really). Dropping support for this wonderful plugin is a big shame for me and migrating to a "native solution" (see @nikolasburk proposal) is just impossible (too much work, regression risks, etc.).
I used Yoga and Prisma1 in production once. I'm a really big fan of Prisma since the very beginning and like @homoky said, it was very painful each time Prisma team drop one of it product support. You have each time to find (quickly) a proper and production-ready alternative (write my own subscriptions, convince my boss to use experimental migration engine, writting raw SQL, ...). My biggest fear about prisma plugin support drop is that the rework will miss some of the current plugin features (like CRUD capability, which is a top requested feature in my case).
On another hand, it's very cool to see Prisma team is perfectionnist and always seek a way to do things more efficiently. I'm really supportive for that way of thinking but don't let your fans down guys :). Even if you don't add more features until the rework, please at least made it compatible with lastest Prisma versions (even if new Prisma features are not supported, that's fine for me)

Anyway, I don't want just to complain, I want to thank you Prisma team to your amazing work. I will be patient and looking forward the new Nexus Plugin Prisma no matter what :)

@jasonkuhrt
Copy link
Contributor

jasonkuhrt commented Feb 26, 2021

An initial unstable release will be coming this Tuesday. You can check it out here as a PR currently https://github.com/prisma/nexus-prisma/tree/feat/emit-model-props-scalars.

Unstable releases will be cut every sprint (2 weeks). Same interval as Prisma Client.

Unstable releases mean less than 1.0.0 😊. These releases are not intended for production, are missing features, tests, etc.

The GitHub gist from before is now out of date and attention should be directed toward the repo, issues there, etc. Marking that comment as outdated now.

I already have some ideas that need writing up about how nexus-prisma will be a dual Prisma plugin and Nexus plugin nexus-prisma/plugin, indepently usable as such. Maybe they will complement each other even but so far no ideas about that. I'll try to pen some specs about how I'm seeing this in the coming week or so.

@cmidgley
Copy link

Do you expect the GraphQL schema (specifically, meaning filters, order-by, and pagination) to be the same with the new plugin as with the old one? Meaning, without a ton of boilerplate that I have to do myself, would my consumers of our QL API not notice that we migrated from the old to the new? Do you expect this to be the case on the root crud query/mutations as well as the model's (including if we use filtering/etc on those models)?

@jasonkuhrt
Copy link
Contributor

@cmidgley Hard to say but I think it would be great if the high-level Nexus Prisma API were flexible enough to do that, or at least come close. I could see the current one being like a subset of the new one potentially. However, zero effort on your part and zero noticing change by your API consumers part is an unlikely nirvana. So strictly speaking the answer is no. But maybe we can get like ~80% there? We'll see.

It might be interesting to go back to a revised spec of something like Open CRUD. Just a default that would then be highly customizable. I wonder if having/using a spec would help users feel more confident about forwarding the contract to their API clients.

Anyways, this still far out as we're currently focused on the low-level API which is the Prisma generator. After that we'd probably see what the appetite looks like for the high level API which would be the Nexus plugin. Both neatly packed into nexus-prisma package.

@Newbie012
Copy link

Would be nice if the plugin will support aggregations as well - https://www.opencrud.org/#sec-Queries-Aggregations

@Akxe
Copy link

Akxe commented Mar 10, 2021

I spent at least an hour reading through this (sadly not in order), but at last, I figured out that is going on. Initially, I was happy, that a new more updated plugin will be made, but soon after I read the post "Removing nexus-plugin-prisma from your project". That scared me a bit, but after being able to look at the plugin in development, it all got better. I think that anyone that uses primarily model will be able to transition easily.

@orefalo
Copy link

orefalo commented Mar 15, 2021

I spent at least an hour reading through this (sadly not in order), but at last, I figured out that is going on. Initially, I was happy, that a new more updated plugin will be made, but soon after I read the post "Removing nexus-plugin-prisma from your project". That scared me a bit, but after being able to look at the plugin in development, it all got better. I think that anyone that uses primarily model will be able to transition easily.

Still very confused about the removal, the addition and the link between the orm and graphql. I have the api fine, but the tooling is error-prone, not providing the errors it must.

@jasonkuhrt
Copy link
Contributor

jasonkuhrt commented Mar 16, 2021

This past sprint we shipped the beginnings of custom scalars "workflow". Workflow in quotes because what has been shipped is mostly just some convenience and guides.

In the next sprint we will probably ship support for projecting enums. Something interesting about this feature is that it was actually never possible with Nexus and nexus-plugin-prisma. While this was because of a limitation of the Nexus API that in theory could be lifted, it is still valuable that the new Prisma generator approach gives us another way to solve the issue. Refer to the issue for details.

Once this lands flushing out the workflow for the remaining custom scalars will probably be a priority.

Once that is done it will make Nexus Prisma complete in terms of its generated scalars story and potentially something you might want to use if your use-case fits within this scope.

A next juicy item will probably then be relations. This will require automating usage of Prisma Client at runtime and thus a significantly more complex undertaking than the scalars where relying on the default resolvers works in Nexus.

Relations will also finally bring to a head issues like pagination ordering and filtering. Further topics will lie within these, such as Relay connection spec compatibility (under pagination aspect).

Hopefully that gives some sense of what is on the foreseeable roadmap.

--edit

We've added a micro roadmap summarizing the above https://github.com/prisma/nexus-prisma#roadmap

@marceloverdijk
Copy link

Sorry to say but I also migrated to Pothos using it's Prisma plugin.

Migration went smoothly and it's maintainer @hayes is also very helpful.

To be honest I looked into Pothos already like 6 months but decided then to stick with the Nexus Prisma Plugin - hoping the project would be picked up...

One thing to mention for others going the Pothos path is that it will be unlikely that there will be some t.crud functionality to automatically expose Prisma models with all it's fields and relations (like the old nexus-plugin-prisma had).
See this thread for more details.
So you have to expose all the fields and relations explicitly like:

builder.prismaObject('Person', {
  fields: (t) => ({
    id: t.exposeString('id'),
    name: t.exposeString('name'),
    nationality: t.relation('nationality'),
    ..

@Cauen
Copy link

Cauen commented Jul 9, 2022

Hi guys, I came here to share the project I'm doing to bring to Pothos, something like we had in the old plugin with nexus-plugin-prisma.

I think that Pothos is a upgrade of Nexus (because of its no-runtime generation and type safety).

Currently, the Pothos Prisma plugin is able to:

  • Create Object Types from Prisma Models with type safety
  • These objects can auto manage prisma includes to get relations from the Model, based on the Graphql request.

But, cant be able to:

  • Easily create input types to use in create, read, delete operations. So you need to create manually all input types for finding a User, for example.
  • Easily filter for Relations, like: get latest 10 draft posts from a user

I discussed with the Pothos author about the possible implementation of something like we had here.

And since those are not the intentions for now. I'm creating a codegen

It will generate the InputTypes for all Prisma operations. Then it will only be necessary to import and use as args from Pothos.

Something like this:

import * as Inputs from './generated/inputs'

builder.queryFields((t) => ({
  findManyUser: t.field({
    type: [User],
    args: {
      where: t.arg({ type: Inputs.UserWhereInput }),
      orderBy: t.arg({ type: [Inputs.UserOrderByWithRelationInput] }),
      cursor: t.arg({ type: Inputs.UserWhereUniqueInput }),
      take: t.arg({ type: 'Int' }),
      skip: t.arg({ type: 'Int' }),
      distinct: t.arg({ type: [Inputs.UserScalarFieldEnum] }),
    },
    resolve: async (root, args) => {
      const user = await db.user.findMany({
        where: args.where || undefined,
        cursor: args.cursor || undefined,
        take: args.take || undefined,
        distinct: args.distinct || undefined,
        skip: args.skip || undefined,
        orderBy: args.orderBy || undefined,
      })

      return user
    }
  }),
}))

The first release was published at prisma-generator-pothos-codegen - npm

This project will evolve, to the point that we can create an entire and customized crud from a Prisma Schema. Having the same thing we had with nexus-plugin-prism. But with all the advantages of Pothos.

The roadmap:

  • Generator code for all input fields.
  • Generator for all Objects, Queries and Mutations. Something like prisma-tools do with Prisma and Nexus.

It's just beginning, so any contribution is more than welcome.

---- Edit 2022-07-13 ----

Published version 0.2.0 with generator for all Objects, Queries and Mutations.
With a lot of new options:

Click to see configs options
{
  inputs?: {
    prismaImporter?: string // default: import { Prisma } from ".prisma/client"
    builderImporter?: string // default: import { builder } from "./builder"
    excludeInputs?: string[] // default: undefined
    excludeScalars?: string[] // default: undefined
    outputFilePath?: string // path to generate file, from project root
    replacer?: (generated: string, position: ReplacerPosition) => string // a function to replace generated source
  },
  crud?: {
    disabled?: boolean // disable generaton of crud. default: false
    includeResolversExact?: string[] // generate only resolvers with name in the list. default: undefined. ie: ['createOneUser']
    includeResolversContain?: string[] // generate only resolvers with name included in the list. default: undefined. ie: ['User'].
    excludeResolversExact?: string[] // default: undefined. ie: ['createOneComment']
    excludeResolversContain?: string[] // default: undefined. ie: ['createOne']
    resolversImports?: string // default: what to import inside resolver
    dbCaller?: string // how to call prisma. default: context.db
    inputsImporter?: string // default: import * as Inputs from "@/generated/inputs";
    builderImporter?: string // default: import { builder } from "./builder"
    outputFolderPath?: string // path to generate files, from project root. default: ./generated
    replacer?: (generated: string, position: ReplacerPosition) => string // a function to replace generated source
  },
  global?: {
    replacer?: (generated: string, position: ReplacerPosition) => string // a function to replace generated source
  }
}

See example: click here

---- Edit 2022-09-07 ----

We published version 0.4.0 with input type field omit from prisma schema. (0.3.0)
And now, the generated code are base files for definition of objects, queries and mutations. (0.4.0)

This changes everything, as now the generated code can be freely replaced, without affecting the customizations already made in the project and maintaining type safety.

@shtse8
Copy link

shtse8 commented Jul 17, 2022

Tried https://github.com/hayes/pothos
It's the best prisma graphql plugin I have ever use.

@jbeckton
Copy link

What ever happened to the good ole days when Separation of Concerns was still a thing? Why are people wanting to couple their API to their database schema? I can only imagine the headaches this must cause. Scale much?

@adarnon
Copy link

adarnon commented Jul 20, 2022

When you're a startup/small company, speed is more valuable than scale.

@iddan
Copy link

iddan commented Jul 20, 2022

What ever happened to the good ole days when Separation of Concerns was still a thing? Why are people wanting to couple their API to their database schema? I can only imagine the headaches this must cause. Scale much?

It's not coupled, it just reduces duplicating the things that are actually one-to-one. You still have separation and can decide what to expose or not

huv1k added a commit to huv1k/nextjs-auth-prisma that referenced this issue Jul 31, 2022
👋 Hey strangers,

this PR updates this template with a couple of changes. 

## Schema builder
I decided to switch to [Pothos GraphQL](https://github.com/hayes/pothos) instead of Nexus, because there is [no future](graphql-nexus/nexus-plugin-prisma#1039 (comment)) for `nexus-prisma`, so it doesn't make sense to keep it inside this template. @hayes is doing a great job with Pothos and everything about it is good 🙌

## Move to JWT
I moved the session strategy to `JWT` so it's prepared for edge computing and Next.js middleware.

## New database
I decided to move to [PlanetScale](https://planetscale.com), they provide really generous free tier. They are a new cool kid in the block with database branching which is a perfect feature. If this doesn't suit, you can still you another database that Prisma supports. 

## Fixes
I fixed some problems with types and now it should work as expected. When `JWT` token is not presented, there is a fallback to `userId` and `userRole`. Fixes #29
@homoky
Copy link

homoky commented Aug 2, 2022

https://mobile.twitter.com/nikolasburk/status/1554381468998291456

@marceloverdijk
Copy link

Thx for sharing @homoky
I'm glad I made the switch to Pothos and didn't kept waiting / hoping for the better.

@nikolasburk it would be good to update the README's of both nexus-plugin-prisma and nexus-prisma to explain this to the users.

@MikaStark
Copy link

So... does that means that nexus will be abandonned too ?

@rostislav-simonik
Copy link

Even if that could happen in our team we cannot afford immediate migration, we are interested to keep maintenance. Waiting for the final decision, and then based on that we will pick a strategy how to maintain prisma-nexus and nexus. @nikolasburk

@MikaStark
Copy link

MikaStark commented Aug 5, 2022

In other words, migrating to Pothos is encouraged if long term maintenance is wanted

@AssisrMatheus
Copy link

In other words, migrating to Pothos is encouraged if long term maintenance is wanted

But how can we be sure that the same thing won't happen to Photos?

@rostislav-simonik
Copy link

rostislav-simonik commented Aug 5, 2022

I'd wait for the official statement from the Prisma team, I've seen so many hypes of the year in the past, so I'd invest to long-term maintenance, then migrate every two years to something new. Our colleague did feasibly check and unfortunately, we are not able to migrate to Pothos even though we would like to it's still missing some features, nexus has.

@homoky
Copy link

homoky commented Aug 5, 2022

I'd wait for the official statement from the Prisma team, I've seen so many hypes of the year in the past, so I'd invest to long-term maintenance, then migrate every two years to something new. Our colleague did feasibly check and unfortunately, we are not able to migrate to Pothos even though we would like to it's still missing some features, nexus has.

What features?

@rostislav-simonik
Copy link

@homoky I'll come back later, to summarize them if it's ok, currently I'm busy. @hayes asked me the same on Twitter.

@MikaStark
Copy link

Starting migrating to Pothos. And so far I really like it.

@rostislav-simonik
Copy link

rostislav-simonik commented Aug 9, 2022

Summary from our feasibility check, the following features from nexus are critical for us

  • Explicitly generated types
    • We are sharing definitions through shared modules where we can configure which attributes are applicable/enabled in the schema by initial configuration. We haven't found a way how to achieve this in Pothos because types are inferred directly from declarations.
  • Custom attributes on fields
    • We have such custom plugins as nonNullOptional that allows declaring on optional graphql fields that can be optional but not nullable. Such can also be done in Pothos, but due to different internals, we haven't found how to access given custom attribute value on graphql-middleware resolver interceptors where we are doing args validations based on that attribute value.

Then there is maintainability risk

  • one person mainly contributes Pothos, mostly because it's the young package, of course, it can change in the future with greater support, but at this moment we need to be more conservative. Who will take over if something happens to him?

There are a few others, but mostly minors, we could live with them.

@hayes
Copy link

hayes commented Aug 9, 2022

Summary from our feasibility check, the following features from nexus are critical for us

Thanks for sharing this, it's always helpful to hear what things people are looking for, and might be blockers to adoption!

Explicitly generated types

We are sharing definitions through shared modules where we can configure which attributes are applicable/enabled in the schema by initial configuration. We haven't found a way how to achieve this in Pothos because types are inferred directly from declarations.

I'm not sure how exactly what you mean here, but I'll try to address a few interpretations:

Pothos doesn't currently have a good way to define standalone types. Currently all types need to be defined through a shared SchemaBuilder instance, which can make it more challenging to build modular schemas where types are defined across multiple packages. This is still possible, but it takes more work, and and can be trickier to set up: It's possible to create a builder package that exports a builder instance, this can be used by each package that defines schema types. Another pattern I've used is to export functions that take the builder as an argument and create the relevant types inside a callback (this is useful for building utility types, or reusable/shared logic, but can be a bit verbose when just defining normal parts of a schema).

The above workarounds are definitely not an optimal experience, but work well enough once set up. Long term, if this is a common problem we can definitely look into making it easier to build modular types with Pothos that don't require a shared builder instance. I have some ideas on how this could work without significant changes to the current API.

The other interpretation of the above issue is you want to generate/export typescript definitions based on types you are defining with Pothos. This unfortunately is not possible. The closes option would probably be using something like graphql-code-generator to generate types based on the built schema.

A final note about this: You mentioned wanting to have some intial config that determins what fields are enabled/included in a schema: This sounds a lot like what we do in the SubGraph schema. This plugin effectively lets you declare a set of sub-graphs that fields/types can be a part of, and then on each field/type can decare which of these subGraphs it is a part of. When you call toSchema on the builder, you can pass in one or more subGraphs and it will create a schema with just the fields that declared themeselves as part of that graph. If this doesn't fit your use case, the plugin is pretty simple, and likely could be easily adapted to to something similar that is more specific to what you need.

Custom attributes on fields

We have such custom plugins as nonNullOptional that allows declaring on optional graphql fields that can be optional but not nullable. Such can also be done in Pothos, but due to different internals, we haven't found how to access given custom attribute value on graphql-middleware resolver interceptors where we are doing args validations based on that attribute value.

Adding custom plugins and schema meta-data was one of the core requirements when I first started building Pothos at airbnb. We had specific metadata we needed to attach to each field, so this should be easy to achieve.

There are a couple of built in options that would not require anything custom. Every field and type has an extensions option that can take arbitrary metadata. This maps to the built in graphql extensions property of all core graphql objects, and is easily accessible at runtime.

There is also a directive plugin, this can be used to define type-safe options that can be added as directives to various parts of the schema. These will also be serialized into an extensions property. This might look something like t.int({ directives: { myOption: someValue }, resolve: () => ...}).

In addition to these existing options, it is also very easy to add a plugin that adds additonal custom options. In the simplest case, it is as easy as just writing a type decaration for the new option field you want to add. Any option passed to a field will be accessible via field.extensions.pothosOptions.yourOption at run time, but you can also easily use one of the plugin hooks to take that options value at attach it somewhere else.

Then there is maintainability risk

one person mainly contributes Pothos, mostly because it's the young package, of course, it can change in the future with greater support, but at this moment we need to be more conservative. Who will take over if something happens to him?

This is definitely a valid concern. This discussion is happening on a thread about a deprecated/unsupported project, so we all know this can happen.

I have a lot of feelings about this, and have deleted a few long paragraphs trying to summarize them, but ultimately it comes down to finding the best path forward. There is definitely maintainability risk with Pothos, but I would argue that the risk is less than with any good alternative I can think of.

Here are a few things Pothos has going for it from a maintainability standpoint:

  • It has been very actively maintained since it's creation (~3 years)
  • Adoption is growing quickly
  • It is used at several fairly large companies (including airbnb and netflix)
  • I am working at a company (stellate) that is very invested in the future of open source graphql tooling (we have core maintainers for pothos, graphiql and urql) and plan to continue investing heavily in maintaining these tools that make building and using graphQL APIs a great experience

The best thing we can do to reduce maintainability risk is to get more people involved. The direction things are heading with Pothos looks very promising, but you are correct that one maintainer isn't great, but it's better than nothing, and I would be very excited to see more contributions from others in the future.

@MikaStark
Copy link

MikaStark commented Aug 9, 2022

one person mainly contributes Pothos, mostly because it's the young package, of course, it can change in the future with greater support, but at this moment we need to be more conservative. Who will take over if something happens to him?

that actually the problem with Nexus… young package, not very maintained, lots of breaking changes between versions (not really since nexus v1 but I remember the nonNull argument typing struggle). I think @nikolasburk is right and Prisma team should be focused on Prisma itself as it is the main project and intended to not be bound to any backend tech (unlike Prisma1). I also think Pothos deserves to be more spotlighted as it’s good, it provides a fantastic Prisma plugin and could be a very strong alternative to Nexus. If Prisma team officially encourage devs to migrate to Pothos, @hayes will get more support from the community.

@rostislav-simonik
Copy link

@hayes thanks, very helpful.

Pothos doesn't currently have a good way to define standalone types. Currently all types need to be defined through a shared SchemaBuilder instance, which can make it more challenging to build modular schemas where types are defined across multiple packages. This is still possible, but it takes more work, and and can be trickier to set up: It's possible to create a builder package that exports a builder instance, this can be used by each package that defines schema types.

This is actually ok, we have a mechanism to share singletons to shared packages.

Another pattern I've used is to export functions that take the builder as an argument and create the relevant types inside a callback (this is useful for building utility types, or reusable/shared logic, but can be a bit verbose when just defining normal parts of a schema).

yes, that's also an option.

The other interpretation of the above issue is you want to generate/export typescript definitions based on types you are defining with Pothos. This unfortunately is not possible. The closes option would probably be using something like graphql-code-generator to generate types based on the built schema.

This is our case, we literally have something like

if (config.isFeatureEnabled) {
     t.string('some')
}

A final note about this: You mentioned wanting to have some intial config that determins what fields are enabled/included in a schema: This sounds a lot like what we do in the SubGraph schema. This plugin effectively lets you declare a set of sub-graphs that fields/types can be a part of, and then on each field/type can decare which of these subGraphs it is a part of. When you call toSchema on the builder, you can pass in one or more subGraphs and it will create a schema with just the fields that declared themeselves as part of that graph. If this doesn't fit your use case, the plugin is pretty simple, and likely could be easily adapted to to something similar that is more specific to what you need.

we would need to investigate this feature more, we somehow misunderstood the concept, because we thought that this subgraph is an isolated subgraph and types can not be shared with other subgraphs.

There is also a directive plugin, this can be used to define type-safe options that can be added as directives to various parts of the schema. These will also be serialized into an extensions property. This might look something like t.int({ directives: { myOption: someValue }, resolve: () => ...}).

In addition to these existing options, it is also very easy to add a plugin that adds additonal custom options. In the simplest case, it is as easy as just writing a type decaration for the new option field you want to add. Any option passed to a field will be accessible via field.extensions.pothosOptions.yourOption at run time, but you can also easily use one of the plugin hooks to take that options value at attach it somewhere else.

Exactly that's what we need, but we haven't found our option in the extensions object, let us check again, probably we did a mistake on our side.

The best thing we can do to reduce maintainability risk is to get more people involved. The direction things are heading with Pothos looks very promising, but you are correct that one maintainer isn't great, but it's better than nothing, and I would be very excited to see more contributions from others in the future.

Yes, I understand, I believe Pothos is an optimistic package but would be good if people would be more careful when proposing sunsetting packages. If there is still a will to maintain the package, then it can live together with others, especially if package was already used in existing solutions. It's not easy and cheap to migrate to another package. It's not just about writing a code but also knowledge, processes etc. That's the nature of production, there is a reasonable obligation to clients that they won't need to invest money every year to refactors.

@martzoukos
Copy link
Collaborator Author

Hey all.

I'm happy that you are coming together to figure out workarounds to your current situation but I'm concerned that this discussion is getting way off topic, potentially also for folks who keep notifications on for a potential update on nexus-prisma.

I would kindly suggest that you continue the detailed discussion in another channel, feel free however to come back to share the outcome of your discussions in case they help other folks.

Thank you.

@MercurialWeb
Copy link

Hi guys, while we wait for the new plugin I have brought this old plugin to version 4.5.0 of Prisma. I don't guarantee it will work for you too, my structure is quite simple and works well.
@mercurialweb/nexus-plugin-prisma

@martzoukos
Copy link
Collaborator Author

Hello everyone,

I'd like to share some positive news on the future of nexus-prisma, which is going to be handed over to the great @rostislav-simonik who is going to maintain it going forward.

You can read more information in the announcement message and I'm going to close this long issue.

I'd like to thank you for your patience so far and all the best from the Prisma team.

colincode7 pushed a commit to colincode7/next-auth-prisma that referenced this issue Jun 11, 2024
👋 Hey strangers,

this PR updates this template with a couple of changes. 

## Schema builder
I decided to switch to [Pothos GraphQL](https://github.com/hayes/pothos) instead of Nexus, because there is [no future](graphql-nexus/nexus-plugin-prisma#1039 (comment)) for `nexus-prisma`, so it doesn't make sense to keep it inside this template. @hayes is doing a great job with Pothos and everything about it is good 🙌

## Move to JWT
I moved the session strategy to `JWT` so it's prepared for edge computing and Next.js middleware.

## New database
I decided to move to [PlanetScale](https://planetscale.com), they provide really generous free tier. They are a new cool kid in the block with database branching which is a perfect feature. If this doesn't suit, you can still you another database that Prisma supports. 

## Fixes
I fixed some problems with types and now it should work as expected. When `JWT` token is not presented, there is a fallback to `userId` and `userRole`. Fixes huv1k/nextjs-auth-prisma#29
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

No branches or pull requests