-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implement fragment unmasking utility types #9380
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
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f18151a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6667693
to
e8152b4
Compare
a37e437
to
6c2dba5
Compare
@charpeni just wanted to provide feedback as our team attempted to utilize these proposed types in our application. In our case, any fragment over 2 to 3 levels deep caused widespread |
@brandonwestcott Do you believe it's something that could be reproduced on TypeScript Playground? Not directly related to GraphQL Code Generator, but I noticed some weird behaviors starting with TypeScript 5.0 and worse with 5.1 related to I tried to reproduce it on TypeScript Playground with one query and five nested fragments, and I couldn't: 🔗 TypeScript Playground. But! Weirdly enough, I was able to reproduce it when trying to unmask a type that couldn't be resolved: 🔗 TypeScript Playground. ![]() |
I like the idea a lot. But here's my problem: I'm in Vue, using bindings from @urql/vue ( const rawQuery = graphql(`...`);
const queryResData = useQuery({
query: rawQuery
}).data as UnmaskResultOf<typeof rawQuery> which is quite entangled. I'd love to be able to write a function const queryRes = unmaskAllFragments(useQuery({
query: graphql(`...`)
}); This would require the generic type accepted by I'll dig around a bit more, maybe I'll find a way to achieve this, but I wouldn't bet on it ;) |
Just to note, the utility type doesn't work on fragments applied to nested objects of the query, which my team unfortunately depends on. |
Adapted your implementation to take it one step further, and I've tested for:
The implementation can be found here. |
No more updates? |
Description
Implementation of fragment unmasking to support an incremental adoption of fragment masking or utils for tests.
When you enable Fragment Masking, all fragments and operations are automatically masked, even though not all fragments or operations use Fragment Masking.
We can expose the following utility types:
UnmaskResultOf<TypedDocumentNode>
&UnmaskFragmentType<TType>
.It checks whether we're inside an operation or directly within a fragment and then recursively flattens fragments by resolving
$fragmentRefs
and merging them to the root fragment.Related #9075
I also introduced
expect-type
to test those newly generated TypeScript utilities to prevent regressions. Currently, there's no way to test it before generatingfragment-masking.ts
as definitions are living within strings, so we need to generate examples and then rely on a Jest test withinapollo-client
's example combined withexpect-type
to test them.Type of change
Screenshots/Sandbox (if appropriate/relevant):
How Has This Been Tested?