Skip to content
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

skip unmasking for types without fragments #12152

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-jobs-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Add a helper that will skip the TS unmasking alorithm when no fragments are present on type level
7 changes: 7 additions & 0 deletions src/masking/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ export type RemoveMaskedMarker<T> = Omit<T, "__masked">;
// force distrubution when T is a union with | undefined
export type RemoveFragmentName<T> =
T extends any ? Omit<T, " $fragmentName"> : T;

export type ContainsFragmentsRefs<TData> =
TData extends object ?
" $fragmentRefs" extends keyof TData ?
true
: ContainsFragmentsRefs<TData[keyof TData]>
: false;
4 changes: 3 additions & 1 deletion src/masking/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
import type {
ContainsFragmentsRefs,
RemoveFragmentName,
RemoveMaskedMarker,
UnwrapFragmentRefs,
Expand Down Expand Up @@ -39,7 +40,8 @@ export type FragmentType<TData> =
export type MaybeMasked<TData> =
TData extends { __masked?: true } ? Prettify<RemoveMaskedMarker<TData>>
: DataMasking extends { enabled: true } ? TData
: Unmasked<TData>;
: true extends ContainsFragmentsRefs<TData> ? Unmasked<TData>
: TData;

/**
* Unmasks a type to provide its full result.
Expand Down
Loading