#[SOLVED] Regenerate sdls after changing schema

1 messages · Page 1 of 1 (latest)

silent plaza
#

Is there a way to update the sdl files after you've made changes to the prisma schema? Say I have a model that I removed and now my sdl files are stale and not in sync with the schema, rw g types doesn't fix it because it complains about an unknown type now (since I removed that model).

The only workaround I know is to delete the sdl/service and generate it again using the CLI.

silent plaza
#

I guess I'll write a script to iterate overall sdl files and run this command:

yarn redwood g sdl <model> --force --no-tests
#

Sadly that overwrites the service as well 🤔 if I already have code in there I'll have to think of a way to save it before regenerating

lyric shard
#

It's been on my mind before to ask why sdl generates service but service doesn't generate sdl

#

perhaps the way would be to create your own generator? 😬

#

somehow customize this

#

yarn rw setup generator sdl and see if you can prevent the service file from being written

#

What if you can delete the sdl files but leave the service files - would it generate the sdl then stop when it finds the service file. if it rolls back the sdl file then that approach won't work.

silent plaza
#

I'll give it a try

lyric shard
#

Some generators roll everything back with any error

silent plaza
#

It would be sweet if there was a yarn rw regenerate sdls command that would exactly do that, essentially not touch the service resolvers and only regenerate the sdls that exist

lyric shard
#

Idk if it would work

#

Could you add a flag and submit a pr?

silent plaza
#

Would be sweet if that could work, I'll look into the CLI

#

For sure, if I get it working I'll put in a pr

lyric shard
#

—no-service or something

silent plaza
#

👍

#

I'm honestly just surprised nobody has done that so far 😂

#

I'm sure many of us go back and edit our schema and have to regenerate these sdls

lyric shard
#

How’s it been going? Youve been quiet since schools out

silent plaza
#

for proper typing

#

Busy man, just knocking out all the devops and then I got stuck with other things. I'm programming like a horse.

#

I'm juggling like 30 models

#

And the functionality on the frontend is extensive

lyric shard
#

I’ve had it typed out a couple of times to ask, but stopped short!

silent plaza
#

No worries, I think I just develop differently than most maybe?

#

I worked on the backend and business logic a lot but I always find myself going back and adding more

#

So maybe other teams or devs just flesh it out and never have to regenerate the sdls really

woeful matrix
#

This has been an ongoing discussion for some years actually— do generators generate or regrenerate aka update? Personally I’ve taken the stance that the generate aka run once . Instead …

#

I do two things I keep all my generated code generated … meaning the files it generates I leave alone so that I can force generate. I then add any new services to new service files . Ideal? No but for most things it’s fine

#

More recently I rely on AI updates using Cursor to add a field to Prisma and then it’s smart enough to update the sdl and service and even the Ui

#

Cursor can also have AI commands like “regenerate all my sdls”

#

The sdl and service are together because the query and mutation operations are the service functions

#

Why could be the optimal solution is a way to generate with a diff that you can see and accept. The team has discussed this but we found that most people used generators once and then managed themselves.

#

I still think the future of RW generators is more use of LLMs

#

Lastly while a 1-1 map of Prisma to sdl type is often what you want , it isn’t always the case. In many cases you have specific types for services to return just what you want in your api and not the full type. Or you have a type that is a combination for a query

silent plaza
silent plaza
silent plaza
#

Life changer, it's incredible what cursor can do. I see what you meant now, this is a huge boost in productivity.

woeful matrix
#

It takes some getting used to — and knowing how to chat or ask — at the least it takes the tedium out of common dev tasks. And at the best it lets you create and experiment faster

#

I still have some ideas for redwood ai dev tools. And hope to share soon. Still talking to team but if goes as plan I’ll have blogs and short videos to accompany

silent plaza
#

[SOLVED] Regenerate sdls after changing schema