SDL, Services and Cells

I read through the docs and this is how I visualize the DX when it comes to the /api side of RedwoodJS. I understand that we use the ‘Cell’ component to talk to the api handling the data in 4 states. This is what makes it so amazing, you can get all this by just:

g cell student
g sdl student
g service student

Here’s the issue:

Let’s say I’ve done the above. I ran those 3 generate commands and now I want to use the ‘scaffold’ command on the same table ‘Student’. It fails because the sdl file already exists, HOWEVER I would like it to just skip making the sdl file. Is there a way to do this? Add a simple -skip command to scaffold?

Also, where does “FindStudentQuery2” in my example (image) come from? Do I get to define what its named?

I understand the SDL checks for auth, but what about authorization? Do we need to check with hasRole() in our Page before we allow user to see the component?

Just playing around with Redwood and I appreciate any help to clear up how I understand the framework. Thank you for the amazing work the community and team have put into this. It’s amazing to use as a developer working with React for the first time.

1 Like

I usually start with typing out my model in schema.prisma like you’ve done. This is on the backend side. Next step for me is usually bridging the gap between backend <-> frontend. For this we need the graphql resolvers (services) on the backend and the SDL that defines the api interface between backend and frontend. If I want to build a quick admin-like interface I use the scaffolds, so in that case the next step after defining my model is yarn rw g scaffold Student. If I want a more custom visualization of my data I reach for yarn rw g sdl Student. Both the scaffold generator and the sdl generator will generate both services and the sdl files. The scaffold generator will also generate the cells you need, and pages too, so you’re pretty much done at this stage for the scaffolds. If you went the g sdl route, you probably want to finish up on the Frontend by generating a cell to display your data, yarn rw g cell Student, and a page for the cell, yarn rw g page Student.

I very rarely reach for the service generator.

2 Likes

Yeah you can run the scaffold command with -f to force it - this will overwrite all the files it’s generating.

yarn redwood generate scaffold <model> -f

But as Tobbe was mentioning, you typically don’t use those other generator commands and then scaffold. Just create the DB schema Model, then run the scaffold command for that Model if you want to scaffold.

1 Like

Yes, I see what you mean. I think the issue arose from the fact I did it the opposite way: I implemented my own page and cell, then the service/sdl. Afterwards I decided I needed an admin scaffold, but at that point the backend had already been created. So simply decide if the model needs a full CRUD, implement scaffold first and then later down if the frontend requires it create the cell that attaches to the service. Heh, funny I got it mixed up like that but I appreciate your help in clearing up my confusion. Thank you both.

On my last question, does the name for the gql query like ‘FindStudentQuery’ map to anything or can I change that right then and there without having to elsewhere?

Yeah you can change that name, I have.