You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I worry that in time you reach the same conclusion and you end up with a schema language that tries to solve everything but is not as good as a real programming language.
I think having a real general purpose programming language at your disposal is always a good idea. (take Webpack config or many other tools for example)
I understand that Prisma is a cross language tool (Go driver for example) but it is also written in JS and Generator and Lift need node to run. So I see no harm in having a schema.prisma.js option.
Note that a good foundation for a code-first API might be the Prisma SDK. This issue is used to discuss the possibilities and pros/cons of the approaches.
Reacted by Rado Konuch, Mohsin Amajd, Vaughan Rouesnel, Daniel Yogel, Maxime, TCLNA, Josias Iquabius, Rafael Vidaurre, Shingo Chijiiwa, Tepy Thai and 14 more
Reacted by Hossein Saniei, Peter Pistorius, Jed, Fran Dios, Nathan Huesmann, div, Ericnr, djskinner, Varun Singh, Alecu Marian-Alexandru and 22 more
changed the title [-]Discussion: Schema-first vs Code-first Prisma schema[/-][+]Discussion: Schema-first vs Code-first Prisma schema API[/+]on Jul 24, 2019
I think if provide this approach as an option the schema file should be a generated artefact anyways to get a better overview of database structure in a readable format.
One thing pointed out in that issue is with env variables, which I've ran into playing with prisma2 is that docker postgres & prisma2 would use different env variables. This means I either need another env variable composed of my docker postgres variables, I need to combine my env variables to generate a new env variable for prisma2, or the schema needs to support multiple env variables at once so I could build the url inline.
If this were just a js file, I could load my normal .env files and build up the postgres url without resorting to needing new schema features, a .env loader that could build from other variables, or providing another env variable.
Hey! Been asked to raise my use case for, at least optionally, being able to not embed env/config variables into bundles. I originally raised this in #287.
In our pipeline we only ever generate stateless builds. This means that you can take a build from a development branch, through staging and production without ever rebuilding. Ie. The code you develop, test and QA is exactly the same as what your users are exposed to in production.
In practice this essentially boils down to never compile configuration into your application bundles and simply allow runtime configuration - commonly through environment variables. For example see the recommendation on heroku for their pipleines.
Right now prisma generate breaks these design principles by forcing the evaluation of env() expressions in the schema definition at build time.
It would be great to have a mode whereby when generating your runtime you could configure it to be stateless so that env("MY_ENV") is compiled to process.env.MY_ENV rather than evaluated at generation time.
Reacted by Nikolas, Michał Chmura, Vladimir Djurdjevic, div, Michał Lytek, Jason Kuhrt, Peter Pistorius, Kyle Roach, djskinner, Rafael Kraut and 8 more
I think another benefit of a JS based schema definition (code-first approach) is that we don't need to discuss issues like "how to have a modular schema?" (#92) anymore as node.js module system already handles it for us.
You've sparked a lively debate internally about this decision ☺️
The reason we went with a declarative format rather than a code-first format is that we're describing the layout of your datasource, we're not providing implementations for this schema (unlike graphql's resolvers). In this sense, we're more like JSON schema or terraform than GraphQL. We also want to be able to migrate your database based on this schema file.
We do understand that you may want to simply generate database clients and bring your own migration engine, so for that we're planning to introduce the Prisma SDK to work with Prisma without generating a schema.
It is very good to see that you value community opinions so much. @matthewmueller I understand the points you make here. The Lift needs a static snapshot of current schema to make migrations.
I still think having a JavaScript compatible schema like JSON schema is a good idea (at least as an alternative to current schema language). Lift can simply save a snapshot of the JSON object to the migrations folder.
I think the best and most successful example for my idea is Webpack config file. Finally you can generate the prisma schema file for readability.
IMHO by introducing a new schema definition language:
the developers have to learn yet another language
you have to support that language and add features to it
only benefit here is readability and more expressive schema declaration
At the end of the day it is the trade-off that you as the platform developers should consider.
The TS API parses both TS and JS files, providing a solid AST, from which a Prisma schema can be generated. You might even be able to leverage some type inference when parsing JS.
Learn one language. Apply it everywhere. TypeScript all the things!
It's the missing link to writing a truly full-stack TypeScript application (see above).
Improve confidence by generating TS definitions for client-side applications (and more).
We will have achieved nirvana, the ultimate state of enlightenment.
Reacted by hiepxanh, Nathan Huesmann, Ivan Pianetti, Michał Lytek, numToStr, Klaus Hvam, third-bank-of-the-river, Steve Jacobs, Varun Singh, Jozef Mikuláš and 22 more
Reacted by Daniel Yogel, Ali Alshaikh, Mohsin Amajd, Mladen Knezović and Shingo Chijiiwa
Reacted by Varun Singh, Simon Frenette, Jurien Hamaker, Daniel Yogel, Colin McDonnell, Mladen Knezović, Shingo Chijiiwa and alex
const User = objectType('User', t => {
t.id('id')
t.string('name', { nullable: true })
})
const Query = objectType('Query', t => {
t.field('user', 'User', {
args: { id: idArg() },
resolve: (_, { id })
})
})
It is complex, needs a lot of learning from developer, it's not really easy readable, etc.
I loved SDL-first approach paired with Prisma and graphql-import: this allowed me to make a toolset that allows to generate resolvers over schema and spin up services with rich CRUD interface in matter of minutes after data definition.
Now with lift, photon and nexus it seems I can't do this, and this is a big problem for migration of my toolsets to Prisma2
One thing that I think is mandatory is for photon to generate not only programmatic crud-client, but crud schema also, to make it possible to import crud definitions in application schema. This saves A TON of time, seriously
Reacted by panda, sam, VietKhangLH, Michał Lytek, Ramesh Patel, Kyle Roach, Vignesh T.V., Rory Dent, Wen Jie ITK, Sirvent and 9 more
Reacted by Alex Budure, Tyler Jones and Colin McDonnell
Activity
[-]Discussion: Schema-first vs Code-first Prisma schema[/-][+]Discussion: Schema-first vs Code-first Prisma schema API[/+]janpio commentedon Jul 24, 2019
pantharshit00 commentedon Jul 25, 2019
I think if provide this approach as an option the schema file should be a generated artefact anyways to get a better overview of database structure in a readable format.
Akkuma commentedon Jul 25, 2019
One thing pointed out in that issue is with env variables, which I've ran into playing with prisma2 is that docker postgres & prisma2 would use different env variables. This means I either need another env variable composed of my docker postgres variables, I need to combine my env variables to generate a new env variable for prisma2, or the schema needs to support multiple env variables at once so I could build the url inline.
If this were just a js file, I could load my normal .env files and build up the postgres url without resorting to needing new schema features, a .env loader that could build from other variables, or providing another env variable.
chrisui commentedon Jul 30, 2019
Hey! Been asked to raise my use case for, at least optionally, being able to not embed env/config variables into bundles. I originally raised this in #287.
In our pipeline we only ever generate stateless builds. This means that you can take a build from a development branch, through staging and production without ever rebuilding. Ie. The code you develop, test and QA is exactly the same as what your users are exposed to in production.
In practice this essentially boils down to never compile configuration into your application bundles and simply allow runtime configuration - commonly through environment variables. For example see the recommendation on heroku for their pipleines.
Right now
prisma generatebreaks these design principles by forcing the evaluation ofenv()expressions in the schema definition at build time.It would be great to have a mode whereby when generating your runtime you could configure it to be stateless so that
env("MY_ENV")is compiled toprocess.env.MY_ENVrather than evaluated at generation time.HosseinAgha commentedon Jul 31, 2019
I think another benefit of a JS based schema definition (code-first approach) is that we don't need to discuss issues like "how to have a modular schema?" (#92) anymore as node.js module system already handles it for us.
matthewmueller commentedon Aug 5, 2019
You've sparked a lively debate internally about this decision☺️
The reason we went with a declarative format rather than a code-first format is that we're describing the layout of your datasource, we're not providing implementations for this schema (unlike graphql's resolvers). In this sense, we're more like JSON schema or terraform than GraphQL. We also want to be able to migrate your database based on this schema file.
We do understand that you may want to simply generate database clients and bring your own migration engine, so for that we're planning to introduce the Prisma SDK to work with Prisma without generating a schema.
marcus-sa commentedon Aug 6, 2019
A decorator based approach like https://typegraphql.ml does with GraphQL types would be nice, so you wouldn't have to use multiple classes for the same purpose :)
HosseinAgha commentedon Aug 6, 2019
It is very good to see that you value community opinions so much.
@matthewmueller I understand the points you make here. The Lift needs a static snapshot of current schema to make migrations.
I still think having a JavaScript compatible schema like JSON schema is a good idea (at least as an alternative to current schema language). Lift can simply save a snapshot of the JSON object to the migrations folder.
I think the best and most successful example for my idea is Webpack config file. Finally you can generate the prisma schema file for readability.
IMHO by introducing a new schema definition language:
At the end of the day it is the trade-off that you as the platform developers should consider.
jednano commentedon Aug 8, 2019
Please support a TypeScript, code-first schema!
Benefits of a TypeScript, code-first schema
terion-labs commentedon Aug 20, 2019
I don't like this style of definitions:
It is complex, needs a lot of learning from developer, it's not really easy readable, etc.
I loved SDL-first approach paired with Prisma and graphql-import: this allowed me to make a toolset that allows to generate resolvers over schema and spin up services with rich CRUD interface in matter of minutes after data definition.
Now with lift, photon and nexus it seems I can't do this, and this is a big problem for migration of my toolsets to Prisma2
One thing that I think is mandatory is for photon to generate not only programmatic crud-client, but crud schema also, to make it possible to import crud definitions in application schema. This saves A TON of time, seriously
45 remaining items
[-]Discussion: Schema-first vs Code-first Prisma schema API[/-][+]Code-first Prisma schema API[/+]iddan commentedon Jul 30, 2020
In the midtime, we released a library implementing the proposed AST and code generator: https://github.com/amplication/prisma-schema-dsl
janpio commentedon Jul 30, 2020
dustinlacewell commentedon Nov 14, 2021
Can there be a status update? I have a project which would really benefit from a end-to-end code-first approach.
alexn-s commentedon Oct 9, 2022
is there any progress on this manner?
alexn-s commentedon Oct 9, 2022
for anybody still looking for a solution:
i found a library https://github.com/ridafkih/schemix that
igalklebanov commentedon Dec 26, 2025
Hey 👋
Cloaing this for staleness and being dusty.