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

Integration with Prisma #217

Closed
MichalLytek opened this issue Dec 23, 2018 · 17 comments
Closed

Integration with Prisma #217

MichalLytek opened this issue Dec 23, 2018 · 17 comments
Labels
Discussion 💬 Brainstorm about the idea Enhancement 🆕 New feature or request

Comments

@MichalLytek
Copy link
Owner

MichalLytek commented Dec 23, 2018

Originally posted by @ntziolis in #77 (comment)

There are various reasons why we feel when solving this issue a lot of other goodness would come from it:

  • prisma has a VERY poor data model migration story, in particular:
    • no versioning of schema during dev time
    • deployment of the same schema causes deployment errors in many cases breaking CI pipelines
    • no support for up/down migrations
  • using partial or changed types in public schema only possible via copy&paste
    • using the same types in your public schema minus a few fields requires copy&pasting the type (and related types) and manually removing the fields in question
    • causes errors when our devs update prisma data model but forget todo the same on the public side (lets be honest this happens a lot)

In order to clean this up and follow DRY here is how we wanted to use type-graphql

  • type-graphql becomes our way of defining both public & prisma schema
  • at the same time be able to generate type safe resolvers for the public schema
  • and use the additional features to standardize on DI etc most of which is handled manually / project by project today with different libs

I understand this might have been the initial intention of type-graphql but I can tell you after the 10th+ graphql project: The need for a framework that is the beginning and end where types originate is VERY high especially when using a graphql datasource underneath (we have tried various beyond prisma).

@MichalLytek MichalLytek added Enhancement 🆕 New feature or request Discussion 💬 Brainstorm about the idea labels Dec 23, 2018
@MichalLytek MichalLytek added this to the Future release milestone Dec 23, 2018
@ntziolis
Copy link

I should add, being able to control the schema via code would also allow for up/down migrations to be coded. While its possible todo this today it would mean creating yet another instance of the schema in another language to be able to manipulate it.

@bmayen
Copy link

bmayen commented Jan 27, 2019

This is a killer feature that would really drive adoption of type-graphq via the Prisma community. Prisma's generator uses the SDL as the source of truth and requires manual copy/paste to keep everything in sync. If type-graphql could be used instead, I imagine it would be the goto solution for Prisma users.

@MichalLytek
Copy link
Owner Author

@bmayen
The Prisma Team choosed other approach for creating schema and types:
https://github.com/prisma/nexus-prisma

I will look where this approach will lead us and if there is a gap, I will for sure try to fill it with decorators 😉

@bmayen
Copy link

bmayen commented Jan 27, 2019

Might make sense for Nexus to support decorators natively. Opened an issue there to see what their thoughts are.

@schickling
Copy link

Hi @19majkel94! We're still very interested in supporting you with a seamless Prisma integration. Given the very nature of developers, there will always be some opinionated preferences and we're trying to work with framework authors like you to fit Prisma as well as possible into your API design and ecosystem.

We're currently working towards Prisma 2 which will also include the prisma-sdk which allows you to programmatically use all Prisma features (such as DB introspection, client generation, migration system, query engine, ...) individually. Could you even decide to "hide" to the developer that Prisma is being used and come up with your own UX flows that use Prisma under the hood.

Here's an idea how the API could look like:

@ObjectType
@Prisma({
  model: 'Product',
  pick: ['id', 'name', 'type', 'brand', 'variants'],
})
export class Product {

  @Field
  options(args?: { showAll?: boolean }): Promise<Option[]> {
    return this.ctx.prisma.options()
  }

  @Mutation({ name: "setProductPrice" })
  setPrice(price: number) {
    // ...
  }

}

@MichalLytek
Copy link
Owner Author

@schickling

We're currently working towards Prisma 2 which will also include the prisma-sdk which allows you to programmatically use all Prisma features

That's great! SDK with programmatical way to register Prisma types and generate client, etc. would be great, as printing a prisma.datamodel file with directives is not possible with graphql-js.

Wrapping/hiding this under the decorator-based API is the simplest thing to do 😉 Can't wait to try the alpha/beta of the SDK!

@JonnyBGod
Copy link

JonnyBGod commented Feb 17, 2019

@schickling

We're currently working towards Prisma 2 which will also include the prisma-sdk which allows you to programmatically use all Prisma features

Great news indeed.
Any information available atm on this? Like roadmap, possible to alpha/beta test, documentation and specs?

I am currently prototyping an extendable framework and I want prisma to be a prime citizen. Also considering type-graph and maybe nexus as plugin schema definition providers.
But one feature that is mandatory is to define a single schema composed of modules and use it to resolve both database and business logic schemas. And with that update Prisma with latest schema changes on the fly.

Would really appreciate at least a generic idea of when would this be possible to plan my roadmap accordingly.

Thanks.

@gotexis
Copy link

gotexis commented Jun 25, 2019

+100

Really looking forward to this. I think we shouldn't need datamodel.prisma.

Generating GraphQL types is OK and a necessity in the near future.

@FluorescentHallucinogen

Looking forward to TypeGraphQL integration with Prisma. 👀 I don't like the Nexus syntax.

prisma+typegraphql

The first preview of Prisma 2 is out. But I don’t understand how all that will fit and work together.

  1. I write Prisma schema file. (I believe the correct term is data model, not schema, because it contains only models, not operations.)
  2. Then I generate the JavaScript/TypeScript API using PhotonJS.
  3. What's next? 🤔

My final goal is to get the full OpenCRUD GraphQL API.

Will it possible to define the data model using TypeGraphQL's classes and decorators instead of Prisma format?

@sarthakagrawal
Copy link

sarthakagrawal commented Jul 18, 2019

My company is very excited to try out the type-graphql/prisma 2 integration. When can we expect this to be available? @19majkel94

@MichalLytek
Copy link
Owner Author

@sarthakagrawal
Prisma 2 release is scheduled in about 2-3 months, so this fall might be a real term of the fully working, prisma-first TypeGraphQL integration 😉

@FluorescentHallucinogen

@19majkel94 What about my questions?

@MichalLytek
Copy link
Owner Author

MichalLytek commented Jul 26, 2019

@FluorescentHallucinogen

  1. I write Prisma schema file. (I believe the correct term is data model, not schema, because it contains only models, not operations.)
  2. Then I generate the JavaScript/TypeScript API using PhotonJS.
  3. What's next? 🤔
  1. Step 2 also generates TypeGraphQL types and resolvers classes, using a custom typegraphql-prisma generator, that you can use and extend to enhance or limit the basic crud capabilities.

@webnoob
Copy link
Contributor

webnoob commented Oct 11, 2019

Any news on this one? Really don't like nexus syntax and would love to see this in action! :)

@MichalLytek
Copy link
Owner Author

I have a working basic integration on a private repo 💪 Waiting for feedback from Prisma team and for some changes in the Prisma generator API to make it easier work on non-UNIX OSes 😉

@webnoob
Copy link
Contributor

webnoob commented Oct 11, 2019

Sounds excellent. I'm early on in a project (prototyping) so hit me up if you need some testing done. Also, if we can poke a GitHub issue to aid you getting some feedback, let us know :)

p.s Thanks for your hard work.

@MichalLytek
Copy link
Owner Author

MichalLytek commented Nov 27, 2019

The preview of the integration is now publicly available 🎉

https://twitter.com/MichalLytek/status/1199708285622005761

Closing this issue in favor of #476 to indicate that only the new Prisma Framework (Prisma 2) will be supported 🔒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion 💬 Brainstorm about the idea Enhancement 🆕 New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants