Unable to customise the Promise returned from a resolver
See original GitHub issueContext
When using typestrict-resolvers
plugin, and using the mappers
property to map Prisma types
The problem I’m seeing is specific to union types. Prisma’s return types for findUnique is Promise<TModel | null>
vs graphql-codegen expected type is Promise<TModel> | Promise<null>
This means that you can’t just return from a db.model.findUnique
call in a resolver and the only viable solution is to do typecasting, because the Prisma type is more “strict” than the type generated by codegen.
The errors appear as follows (message will vary slightly depending on ResolverFn definition):
Type 'Promise<Post | null>' is not assignable to type 'Promise<null> | Promise<Post>'.
Describe the solution you’d like
Either:
a) The ability to customise how the Promise from a resolver is constructed
OR
b) Use unions inside the generic of the Promise i.e.
✅ Promise<TResult | null>
⚠️ and not Promise<TResult> | Promise<null>
Describe alternatives you’ve considered
- I tried changing the
ResolverTypeWrapper
- but to no effect
Additional context Follow this thread https://github.com/redwoodjs/redwood/issues/5481#issuecomment-1157814297 for a bit more info
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (4 by maintainers)
Closing this issue - confirmed that you can use prisma findUniques!
Thanks so much @enisdenjo
Thanks a bunch @enisdenjo - this is really really great, and super happy to have a concrete explanation for this. ✌️
And appreciate the links to the handbook and your explanation- you have no idea how many people I’ve spoken to to try and get to the bottom of this!
@n1ru4l It looks to me like we can probably close this issue - we still have to look into the other one in #8050 (the whole reaons this problem came up).