Hiya. I was trying to create GraphQL resolvers that wouldn’t call the database, however got an error that yarn rw g sdl/service requires a model.
I worked around it by creating a dummy model that I can then write a service for, however a few questions:
- Am I doing something wrong? In this case, the endpoint creates a file in S3, but doesn’t need to read/write to the database.
- What is the right way to do create GraphQL resolvers without a model?
Hi @articulatehat currently the generators for sdl and service are focus on generating files for a Prisma model.
If you want a custom SDL and service tk interact with an outside api (which is very common) simple write the sdl and service yourself — just name the sdl and service files accordingly so they can match up your operations (queries and mutations) automatically. You can use the pattern seen in the database backed files.
There is an RFC to have new generators that can build an sdl from an api schema like JSONApi or others — or something I thought of last night actually might be to have a “query” and a “mutation” generator that stubs out an sdl and service file given some names.
But for now, welting your own sdl and service is the way to go and is how everyone does non Prisma table backed services. In fact most wrote custom sdl and services even when they want to query Prisma but have the sdl expose only a subset of fields.