diff --git a/.api-reports/api-report-cache.api.md b/.api-reports/api-report-cache.api.md index 56f7904f774..271642c9197 100644 --- a/.api-reports/api-report-cache.api.md +++ b/.api-reports/api-report-cache.api.md @@ -225,6 +225,9 @@ type CombineFragmentRefs> = UnionToInte [K in keyof FragmentRefs]-?: UnwrapFragmentRefs>; }[keyof FragmentRefs]>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export function createFragmentRegistry(...fragments: DocumentNode[]): FragmentRegistryAPI; @@ -733,13 +736,14 @@ export function makeVar(value: T): ReactiveVar; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) export interface MergeInfo { diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 59ba909cab2..6b333738827 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -468,6 +468,9 @@ type ConcastSourcesIterable = Iterable>; // @public (undocumented) export const concat: typeof ApolloLink.concat; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export const createHttpLink: (linkOptions?: HttpOptions) => ApolloLink; @@ -1376,13 +1379,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) export interface MergeInfo { diff --git a/.api-reports/api-report-masking.api.md b/.api-reports/api-report-masking.api.md index 225e1e62877..40010434a35 100644 --- a/.api-reports/api-report-masking.api.md +++ b/.api-reports/api-report-masking.api.md @@ -15,6 +15,9 @@ type CombineFragmentRefs> = UnionToInte [K in keyof FragmentRefs]-?: UnwrapFragmentRefs>; }[keyof FragmentRefs]>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export interface DataMasking { } @@ -44,13 +47,14 @@ export type MaskedDocumentNode = TData extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) type Prettify = { diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 0fe374cb7fc..b258c47838e 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -566,6 +566,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export interface Context extends Record { } @@ -1122,13 +1125,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_components.api.md b/.api-reports/api-report-react_components.api.md index 2c93ea485c2..4308bdc7935 100644 --- a/.api-reports/api-report-react_components.api.md +++ b/.api-reports/api-report-react_components.api.md @@ -512,6 +512,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) interface DataMasking { } @@ -985,13 +988,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_context.api.md b/.api-reports/api-report-react_context.api.md index 2703bcf4a31..31053fbb7ec 100644 --- a/.api-reports/api-report-react_context.api.md +++ b/.api-reports/api-report-react_context.api.md @@ -506,6 +506,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) interface DataMasking { } @@ -982,13 +985,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_hoc.api.md b/.api-reports/api-report-react_hoc.api.md index 0172940709b..23faa7d58fa 100644 --- a/.api-reports/api-report-react_hoc.api.md +++ b/.api-reports/api-report-react_hoc.api.md @@ -495,6 +495,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) interface DataMasking { } @@ -989,13 +992,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_hooks.api.md b/.api-reports/api-report-react_hooks.api.md index beae7ff4e42..e788994504f 100644 --- a/.api-reports/api-report-react_hooks.api.md +++ b/.api-reports/api-report-react_hooks.api.md @@ -535,6 +535,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) interface DataMasking { } @@ -1071,13 +1074,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_internal.api.md b/.api-reports/api-report-react_internal.api.md index 4038852a7e9..f2b6535142e 100644 --- a/.api-reports/api-report-react_internal.api.md +++ b/.api-reports/api-report-react_internal.api.md @@ -514,6 +514,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // Warning: (ae-forgotten-export) The symbol "PreloadQueryFunction" needs to be exported by the entry point index.d.ts // // @public @@ -1081,13 +1084,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index 61b56d41e68..8ea4103fbec 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -475,6 +475,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) interface DataMasking { } @@ -967,13 +970,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-testing.api.md b/.api-reports/api-report-testing.api.md index d6e7d4209df..1d5c84806d9 100644 --- a/.api-reports/api-report-testing.api.md +++ b/.api-reports/api-report-testing.api.md @@ -465,6 +465,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @internal (undocumented) type CovariantUnaryFunction = { fn(arg: Arg): Ret; @@ -956,13 +959,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index d04ffbb1842..8fb85f75d96 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -464,6 +464,9 @@ class Concast extends Observable { // @public (undocumented) type ConcastSourcesIterable = Iterable>; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @internal (undocumented) type CovariantUnaryFunction = { fn(arg: Arg): Ret; @@ -955,13 +958,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) class MissingFieldError extends Error { diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 3ec50c2993b..7b5014b63ad 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -595,6 +595,9 @@ export type ConcastSourcesIterable = Iterable>; // @public (undocumented) export function concatPagination(keyArgs?: KeyArgs): FieldPolicy; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export function createFragmentMap(fragments?: FragmentDefinitionNode[]): FragmentMap; @@ -1664,13 +1667,14 @@ export function maybeDeepFreeze(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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) export function mergeDeep(...sources: T): TupleToIntersection; diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index ee8dc636743..b5ad5884992 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -565,6 +565,9 @@ type ConcastSourcesIterable = Iterable>; // @public (undocumented) export const concat: typeof ApolloLink.concat; +// @public (undocumented) +type ContainsFragmentsRefs = TData extends object ? " $fragmentRefs" extends keyof TData ? true : ContainsFragmentsRefs : false; + // @public (undocumented) export const createHttpLink: (linkOptions?: HttpOptions) => ApolloLink; @@ -1557,13 +1560,14 @@ type MaybeAsync = T | PromiseLike; // 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 extends { __masked?: true; } ? Prettify> : DataMasking extends { enabled: true; -} ? TData : Unmasked; +} ? TData : true extends ContainsFragmentsRefs ? Unmasked : TData; // @public (undocumented) export interface MergeInfo { diff --git a/.changeset/perfect-jobs-flow.md b/.changeset/perfect-jobs-flow.md new file mode 100644 index 00000000000..594b7c26ba5 --- /dev/null +++ b/.changeset/perfect-jobs-flow.md @@ -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 diff --git a/src/masking/internal/types.ts b/src/masking/internal/types.ts index 02d8fdc99b6..86d11ca4abb 100644 --- a/src/masking/internal/types.ts +++ b/src/masking/internal/types.ts @@ -31,3 +31,10 @@ export type RemoveMaskedMarker = Omit; // force distrubution when T is a union with | undefined export type RemoveFragmentName = T extends any ? Omit : T; + +export type ContainsFragmentsRefs = + TData extends object ? + " $fragmentRefs" extends keyof TData ? + true + : ContainsFragmentsRefs + : false; diff --git a/src/masking/types.ts b/src/masking/types.ts index c7e4817133f..90b250b4f70 100644 --- a/src/masking/types.ts +++ b/src/masking/types.ts @@ -1,5 +1,6 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; import type { + ContainsFragmentsRefs, RemoveFragmentName, RemoveMaskedMarker, UnwrapFragmentRefs, @@ -39,7 +40,8 @@ export type FragmentType = export type MaybeMasked = TData extends { __masked?: true } ? Prettify> : DataMasking extends { enabled: true } ? TData - : Unmasked; + : true extends ContainsFragmentsRefs ? Unmasked + : TData; /** * Unmasks a type to provide its full result.