Skip to content

Commit

Permalink
skip unmasking for types without fragments (#12152)
Browse files Browse the repository at this point in the history
Co-authored-by: Jerel Miller <[email protected]>
  • Loading branch information
phryneas and jerelmiller authored Nov 20, 2024
1 parent 71c34f9 commit 78137ec
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .api-reports/api-report-cache.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToInte
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
}[keyof FragmentRefs]>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export function createFragmentRegistry(...fragments: DocumentNode[]): FragmentRegistryAPI;

Expand Down Expand Up @@ -733,13 +736,14 @@ export function makeVar<T>(value: T): ReactiveVar<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
export interface MergeInfo {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
// @public (undocumented)
export const concat: typeof ApolloLink.concat;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export const createHttpLink: (linkOptions?: HttpOptions) => ApolloLink;

Expand Down Expand Up @@ -1376,13 +1379,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
export type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
export interface MergeInfo {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-masking.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToInte
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
}[keyof FragmentRefs]>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export interface DataMasking {
}
Expand Down Expand Up @@ -44,13 +47,14 @@ export type MaskedDocumentNode<TData = {

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
export type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
type Prettify<T> = {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export interface Context extends Record<string, any> {
}
Expand Down Expand Up @@ -1122,13 +1125,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
interface DataMasking {
}
Expand Down Expand Up @@ -985,13 +988,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
interface DataMasking {
}
Expand Down Expand Up @@ -982,13 +985,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_hoc.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
interface DataMasking {
}
Expand Down Expand Up @@ -989,13 +992,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_hooks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
interface DataMasking {
}
Expand Down Expand Up @@ -1071,13 +1074,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// Warning: (ae-forgotten-export) The symbol "PreloadQueryFunction" needs to be exported by the entry point index.d.ts
//
// @public
Expand Down Expand Up @@ -1081,13 +1084,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-react_ssr.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
interface DataMasking {
}
Expand Down Expand Up @@ -967,13 +970,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-testing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @internal (undocumented)
type CovariantUnaryFunction<out Arg, out Ret> = {
fn(arg: Arg): Ret;
Expand Down Expand Up @@ -956,13 +959,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-testing_core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ class Concast<T> extends Observable<T> {
// @public (undocumented)
type ConcastSourcesIterable<T> = Iterable<Source<T>>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @internal (undocumented)
type CovariantUnaryFunction<out Arg, out Ret> = {
fn(arg: Arg): Ret;
Expand Down Expand Up @@ -955,13 +958,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
class MissingFieldError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report-utilities.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ export type ConcastSourcesIterable<T> = Iterable<Source<T>>;
// @public (undocumented)
export function concatPagination<T = Reference>(keyArgs?: KeyArgs): FieldPolicy<T[]>;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export function createFragmentMap(fragments?: FragmentDefinitionNode[]): FragmentMap;

Expand Down Expand Up @@ -1664,13 +1667,14 @@ export function maybeDeepFreeze<T>(obj: T): T;

// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
export function mergeDeep<T extends any[]>(...sources: T): TupleToIntersection<T>;
Expand Down
6 changes: 5 additions & 1 deletion .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
// @public (undocumented)
export const concat: typeof ApolloLink.concat;

// @public (undocumented)
type ContainsFragmentsRefs<TData> = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs<TData[keyof TData]> : false;

// @public (undocumented)
export const createHttpLink: (linkOptions?: HttpOptions) => ApolloLink;

Expand Down Expand Up @@ -1557,13 +1560,14 @@ type MaybeAsync<T> = T | PromiseLike<T>;

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ContainsFragmentsRefs" needs to be exported by the entry point index.d.ts
//
// @public
export type MaybeMasked<TData> = TData extends {
__masked?: true;
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
enabled: true;
} ? TData : Unmasked<TData>;
} ? TData : true extends ContainsFragmentsRefs<TData> ? Unmasked<TData> : TData;

// @public (undocumented)
export interface MergeInfo {
Expand Down
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

0 comments on commit 78137ec

Please sign in to comment.