-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Masked Fragment inference with Remix/React Router useLoaderData
pattern
#110
Comments
The issue here seems to be that I don't know what that type does and haven't looked at it. But if I had to guess, it's meant to prevent you from trying to transfer non-JSON values over loaders, since that wouldn't be possible. I'm not sure if they have an escape hatch for that, as otherwise you'd be forced to unmask fragments (or disable masking entirely). But since masked fragments are a type-level protection for us, it's probably advisable to simply turn off / circumvent the The easiest way to circumvent this, if there's no built-in solution for this, is to write a wrapper for |
useLoaderData
pattern
Hi @kitten, thanks for your reply. How do you explain that the |
Depending on what you're using for codegen it first of all depends what you did before. However, assuming you're using GraphQL Code Generator with the This basically means:
This is actually intended behaviour, in a way. We're choosing to use a unique symbol exactly because fragment masks are neither real nor serializable. Once you have a fragment mask, the data basically “lies” about what its shape is and omits information rather than showing it. So, you can either disable fragment masking, and lose its benefits, enforcing fragment composition strictly, or you'll have to avoid going through On a side note, Remix is definitely doing the right thing here, because they're basically enforcing that unserializable data can never make it across, since it's presumably serialized as JSON. But this being a virtual property, rather than omitting it, their helper makes it incompatible, since they likely only expect this to be a problem in case of any mistakes. |
I found that #126 happens to fix this, since |
Wow, we look forward to try it out with the next version. Thanks. |
I confirm that is fixed. Thanks Kitten! |
Describe the bug
I'm trying to migrate from codegen to gql.tada but TypeScript complains about types not being compatible when data comes from a Remix or React Router loader.
This may be related to how TypeScript handles union types when a function can return different types... But I'm not sure.
As you can see, I reproduced a case here https://stackblitz.com/edit/remix-run-remix-rckuw2?file=app%2Froutes%2Ftada%2Froute.tsx
TypeScript complains when using the result of
useLoaderData<typeof loader>()
. As far as I'm concerned they should be compatible though.You can see that there is no issue when using
useQuery
inside the component's body.And if you look in the
routes/codegen
directory, you can see that I re-created the exact same use case but with codegen and it seems to go along with this without any issue.What is the difference between codegen and gql.tada approach here?
This is clearly a blocker for us because we don't want to be forced to redeclare every loader return types manually as this wouldn't be a very good DX.
Reproduction
https://stackblitz.com/edit/remix-run-remix-rckuw2?file=app%2Froutes%2Ftada%2Froute.tsx
gql.tada version
gql.data 1.2.1
Validations
The text was updated successfully, but these errors were encountered: