question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to customise the Promise returned from a resolver

See original GitHub issue

Context 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dac09commented, Aug 15, 2022

Closing this issue - confirmed that you can use prisma findUniques!

Thanks so much @enisdenjo

2reactions
dac09commented, Aug 15, 2022

Union members are indeed evaluated one by one, the following example proves the point:

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to return resolve in promise function inside module ...
You don't "return" from a promise callback. You call resolve() or reject(), you don't do return resolve() . Just resolve() .
Read more >
How to Fix “Promise resolver undefined is not a function” in ...
If you're running into the “Promise resolver undefined is not a function” error, your code may look like this new Promise() instead of...
Read more >
Promise - JavaScript - MDN Web Docs
Returns a new Promise object that is rejected with the given reason. Returns a new Promise object that is resolved with the given...
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
First, let us create a generic function that accepts a PokeAPI URL as argument and returns a Promise. If the API call is...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
new Promise((resolve, reject) => { throw new Error("Whoops! ... we can analyze the error and maybe rethrow it if it can't be handled....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found