You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue proposes a stricter definition for OperationResult types.
I couldn't narrow down the type of data after checking error.
Present:
import{registerUrql}from'@urql/next/rsc';const{ getClient }=registerUrql(...);exportdefaultasyncfunctionHome(){const{ data, error }=awaitgetClient().query(PokemonsQuery,{});if(!error)returnnull;console.log(data);// type is `object | undefined`return ...
}
Expected Behavior:
exportdefaultasyncfunctionHome(){const{ data, error }=awaitgetClient().query(PokemonsQuery,{});if(!error)returnnull;console.log(data);// type is `object`return ...
}
Now that doesn't mean that it's entirely incorrect to do what you're doing but the impact would be a push into the wrong direction. If the user chooses to render a different UI just because there is an error would mean that they would discard what in theory could just be one leaf-field that failed to complete its result. The beautiful part is that if you generate TypeScript types based on your schema is that you are already preparing for these scenario's due to how null bubbling works in GraphQL.
The only distinction between a legitimate null and a null resulting from an error is that the latter would be in your array of GraphQLErrors and you can trace it back because the path of said GraphQLError will match up with your missing data.
Thank you for your quick response!
I appreciate the explanation about how GraphQL handles errors and null bubbling.
Thanks again for taking the time to clarify!😄
Summary
This issue proposes a stricter definition for
OperationResult
types.I couldn't narrow down the type of data after checking error.
Present:
Expected Behavior:
Proposed Solution
I propose the following changes:
ea609b1
This ensures that the type of data is narrowed after checking for error.
Requirements
The text was updated successfully, but these errors were encountered: