Use RedwoodJS generator to create CRUD operations and GraphQL SDLs from Prisma Scheme

Hi,

I have a Prisma schema that I made, and I’d like to generate a CRUD operations + GraphQL SDLs from it.
Is it possible to do so using RedwoodJS, but without using the framework?

Hi. Just to clarify.

You want to:

  • compose a database schema using Prisma
  • run “something” that converts Prisma schema to SDL
  • take that SDL and create GraphQL resolvers for queries and mutations
  • have those actually implement Prisma CRUD operations (find, findMany, update etc)
  • run codegen to create a GraphQL schema
  • create a GraphQL server that use the schema and handles api requests and returns data

but not use RedwoodJS?

Redwood does this all for you.

You can use the RedwoodJS api/graphql server alone. You don’t necessarily need to write any front end in Redwood web (or even React).

You can use the RW API/GraphQL API from Due, JS, native apps, curl – anything that ca make a GraphQL request.

Hi @dtyhresson thanks for your answer!
I would definitely take a look on server only redwood, but I want to build my server a bit differently and explore different tools.

And it seems like the scaffold generator can be served not only for Redwoodjs ecosystem, since it is a general tool.

and I wish to see it as a standalone tool like other prisma generators :smiley:

You might want to consider https://platformatic.dev. Though it doesn’t use Prisma.

Oh that’s nice tool! yeah but I use Prisma I wish they had the ability to do that with prisma.

A workaround I could think about is to create a redwoodjs project with a copy of Prisma ORM schema, use redwood scaffold to create the SDL + GraphQL schema, and then copy the output to my project, I could make a CI to do that automatically but it just feels very cumbersome.

I asked to export scaffold as a standalone tool on github as a feature request, I think it’s also not much of a work because the output doesn’t depend on nothing rather than the prisma orm schema, so it should be very easy to do that? I assume

, I think it’s also not much of a work because the output doesn’t depend on nothing rather than the prisma orm schema

Actually, it’s not that easy. You are dealing with custom “glue” that combines three separate technologies: Prisma (schema, db migration, types, ORM), GraphQL (SDL, graphql schema, resolvers), a GraphQL Server (Yoga).

Also, RedwoodJS allows you to have separate SDL files and then we merge them into a single GraphQL schema using graphql-tools. This is not common.

Have a look what’s needed to do: redwood/packages/graphql-server/src/makeMergedSchema.ts at main · redwoodjs/redwood · GitHub

Even if – and that a huge if - you were able to make SDL from Prisma models, you’d need the mechanism to reassemble the SDL into the typeDefs and then also assembled all the services (aka resolver) into that to make an executable schema that – again, would need to be handed to whatever GraphQL server you intended to deploy.

Plus this isn’t just the Prisma model to SDL – you need the resolvers, too.

What you are asking for is not trivial to do – an in fact core to the DX of RedwoodJS itself.

I see, thanks for the comprehensive answer

@dthyresson A question about server only, how can i do that with Redwood?

The simplest way is just to use RedwoodJS as is and simply not write any front end or web or React code.

The real question is - how and where do you intend to deploy. And also what is the way your intend to consume the GraphQL api.

There may be some tweaks needed to the cli commands to omit web side artifacts.

I’d suggest working normally with RedwoodJS and then when you get to the point of deploying revisit anything to make deploying the api alone more efficient

So if I get it right, it’s not possible to not generate front end code, but rather i should just ignore it / delete it?

It will make more sense when you start using RedwoodJS but the answer[quote=“Tsimopak, post:10, topic:7174, full:true”]
So if I get it right, it’s not possible to not generate front end code, but rather i should just ignore it / delete it?
[/quote]

is yes and no.

Some commands could generate some web side code like types and if you scaffold instead of just using the service or sdl generators.

Running the dev server will still stattleship both the api and web side sides but you have the option or building and serving up just the api.

Even if the is web code you can just ignore it.

Buta

But that’s why I asked how you plan to deploy and consume your API