Modifiable Files in RedwoodJS

Hi,

I’m new to RedwoodJS so have some notions to make clear.

Based on schema.prisma file, we can generate sdls, services, pages by running generate scaffold command.

If I need to use a custom Query or Mutation in Cells of Web, I do modify relevant sdl, services, api/types/graphql.d.ts files.

Is this normally a good practise?
I assume when we destroy sdls and services and regenerate them, all modifications will get reverted?

Please let me know which files I need to touch when I need to use custom queries or mutations, etc.

Thanks.

Hi @pulanski - great question.

I tend to keep the generated SDL and services intact so that I can regenerate at any time with piggy losing any custom types or code I wrote.

I then make my own SDL and service for custom work — so if I had a myPosts query I may put that in a MyPosts sdl and myPosts service or in a PostsManager sdl and service.

The GraphQL handler merges all sdl and services into a single schema so keeping them separate is perfectly fine and actually makes maintenance a bit easier since can make the code more specific.

Hope that helps.

1 Like

@dthyresson Thanks for your answer. That helped me a lot.

One confirmation question from my original post, is app/types/graphql.d.ts file something I can modify or it’s also a Redwood generated file?

When adding custom service functions in service files, I have experienced the need to add/modify the CustomResolvers in graphql.d.ts file. (Of course, this is in typescript project)

Here’s why I am asking if this file is auto-generated or fully-customizable file and can touch freely…

Thanks.

It is generated via yarn rw g types or yarn rw type-check.

When adding custom service functions in service files, I have experienced the need to add/modify the CustomResolvers in graphql.d.ts file. (Of course, this is in typescript project)

Interesting. I have found I have had to do this as well a few times and have been meaning to collect some examples of such custom queries and services to share with the team.

If you have a few that you could share here and or in a GitHub issue that would help to improve the type generation which we know we’d like to do.

Note: I’ve encountered this more frequently when my service isn’t backed by Prisma, but rather a service fetches data from a third party api (in my case Open Weather Maps) and my SDL and service fetches weather for a City id (and City is a model that is used to make the weather query).

Thanks much!

1 Like

@dthyresson

Interesting. I have found I have had to do this as well a few times and have been meaning to collect some examples of such custom queries and services to share with the team.

Yes. I agree those custom queries and services you added need to be shared with the team to be in sync.

What was your approach here? Probably, just created PR with those changes and others pull it?
Or sharing those files marked with custom ones through chat and do manual adding?

There can be some cases when other team member need to destroy and regenerate those sdl, service files. They may had to spend some time by manually updating those files everytime they regenerate.
How would you deal with this? I’m just curious.

If you have a few that you could share here and or in a GitHub issue that would help to improve the type generation which we know we’d like to do.

I will create an github issue with some examples in the RedwoodJS repo.

Thanks again.

Amazing thanks!

To be honest, I ran into this in an example app that is still work in progress, so I deferred solving that problem until I could understand it better.

Looking forward to the issue and hope we can resolve it with help form the Team and Community.

1 Like