Creating new mutations

This is hopefully super simple for someone who knows what they are doing, but I am new to both GraphQL and to RedwoodJS, so not for me

I have my generated model called Block. I would like to have the ability to delete multiple blocks at one time in a deleteBlocks function in the blocks service. I start by adding to the SDL Mutation:
deleteBlocks(ids: [String]!): Prisma.BatchPayload @requireAuth
When I go to create the function in the service, I am going to need an updated MutationResolvers type (I am using Typescript). How do I get that? I assume graphql.d.ts is auto-generated, so after adding that line to the SDL, I run yarn rw g types and get an error about unknown type ‘Block’

My question is, what is the process for adding new service functions and mutation definitions? Thanks!

Hi, i am having the same problem. Any help here ?
Thanks a lot!

EDIT… edit the related sdl file. If you add new mutations there, yarn rw g types will then generate all types accordingly

what is the process for adding new service functions and mutation definitions?

I have to admit I always forget the order too, but off the top of my head:

  • Add mutation defintion to SDL first
  • Run yarn rw g types - if typegen is failing, you likely have made a mistake.
  • If you are defining new SDL types, for example in your case it sounds like you’ve used Blocks somewhere, make sure you’ve added the definition it to your .sdl file (doesn’t have to be the same file).
  • Sometimes TS will cache the old generated types, so worth doing a Cmd+P and restarting TS server
  • Generate your service or add the relevant mutation function. You should have the types available now.

Thanks,
Danny

1 Like