Skip to content

Commit 45b1bc1

Browse files
committed
Introduce a MaskedDocumentNode type and handle masking types (#12064)
1 parent fa34aa2 commit 45b1bc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+6281
-1220
lines changed

.api-reports/api-report-cache.api.md

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
4545
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
4646
// (undocumented)
4747
abstract performTransaction(transaction: Transaction<TSerialized>, optimisticId?: string | null): void;
48+
// Warning: (ae-forgotten-export) The symbol "Unmasked" needs to be exported by the entry point index.d.ts
49+
//
4850
// (undocumented)
49-
abstract read<TData = any, TVariables = any>(query: Cache_2.ReadOptions<TVariables, TData>): TData | null;
51+
abstract read<TData = any, TVariables = any>(query: Cache_2.ReadOptions<TVariables, TData>): Unmasked<TData> | null;
5052
// (undocumented)
51-
readFragment<FragmentType, TVariables = any>(options: Cache_2.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): FragmentType | null;
53+
readFragment<FragmentType, TVariables = any>(options: Cache_2.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): Unmasked<FragmentType> | null;
5254
// (undocumented)
53-
readQuery<QueryType, TVariables = any>(options: Cache_2.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): QueryType | null;
55+
readQuery<QueryType, TVariables = any>(options: Cache_2.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): Unmasked<QueryType> | null;
5456
// (undocumented)
5557
recordOptimisticTransaction(transaction: Transaction<TSerialized>, optimisticId: string): void;
5658
// (undocumented)
@@ -63,9 +65,9 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
6365
// (undocumented)
6466
transformForLink(document: DocumentNode): DocumentNode;
6567
// (undocumented)
66-
updateFragment<TData = any, TVariables = any>(options: Cache_2.UpdateFragmentOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
68+
updateFragment<TData = any, TVariables = any>(options: Cache_2.UpdateFragmentOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
6769
// (undocumented)
68-
updateQuery<TData = any, TVariables = any>(options: Cache_2.UpdateQueryOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
70+
updateQuery<TData = any, TVariables = any>(options: Cache_2.UpdateQueryOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
6971
// (undocumented)
7072
abstract watch<TData = any, TVariables = any>(watch: Cache_2.WatchOptions<TData, TVariables>): () => void;
7173
// Warning: (ae-forgotten-export) The symbol "OperationVariables" needs to be exported by the entry point index.d.ts
@@ -170,7 +172,7 @@ namespace Cache_2 {
170172
// (undocumented)
171173
dataId?: string;
172174
// (undocumented)
173-
result: TResult;
175+
result: Unmasked<TResult>;
174176
}
175177
import DiffResult = DataProxy.DiffResult;
176178
import ReadQueryOptions = DataProxy.ReadQueryOptions;
@@ -214,9 +216,22 @@ export const canonicalStringify: ((value: any) => string) & {
214216
// @public (undocumented)
215217
type CanReadFunction = (value: StoreValue) => boolean;
216218

219+
// Warning: (ae-forgotten-export) The symbol "UnionToIntersection" needs to be exported by the entry point index.d.ts
220+
// Warning: (ae-forgotten-export) The symbol "UnwrapFragmentRefs" needs to be exported by the entry point index.d.ts
221+
// Warning: (ae-forgotten-export) The symbol "RemoveFragmentName" needs to be exported by the entry point index.d.ts
222+
//
223+
// @public (undocumented)
224+
type CombineFragmentRefs<FragmentRefs extends Record<string, any>> = UnionToIntersection<{
225+
[K in keyof FragmentRefs]-?: UnwrapFragmentRefs<RemoveFragmentName<FragmentRefs[K]>>;
226+
}[keyof FragmentRefs]>;
227+
217228
// @public (undocumented)
218229
export function createFragmentRegistry(...fragments: DocumentNode[]): FragmentRegistryAPI;
219230

231+
// @public (undocumented)
232+
interface DataMasking {
233+
}
234+
220235
// @public (undocumented)
221236
export namespace DataProxy {
222237
// (undocumented)
@@ -265,7 +280,7 @@ export namespace DataProxy {
265280
// (undocumented)
266281
export interface WriteOptions<TData> {
267282
broadcast?: boolean;
268-
data: TData;
283+
data: Unmasked<TData>;
269284
overwrite?: boolean;
270285
}
271286
// (undocumented)
@@ -275,8 +290,8 @@ export namespace DataProxy {
275290

276291
// @public
277292
export interface DataProxy {
278-
readFragment<FragmentType, TVariables = any>(options: DataProxy.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): FragmentType | null;
279-
readQuery<QueryType, TVariables = any>(options: DataProxy.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): QueryType | null;
293+
readFragment<FragmentType, TVariables = any>(options: DataProxy.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): Unmasked<FragmentType> | null;
294+
readQuery<QueryType, TVariables = any>(options: DataProxy.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): Unmasked<QueryType> | null;
280295
writeFragment<TData = any, TVariables = any>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
281296
writeQuery<TData = any, TVariables = any>(options: DataProxy.WriteQueryOptions<TData, TVariables>): Reference | undefined;
282297
}
@@ -521,6 +536,17 @@ export interface FragmentRegistryAPI {
521536
transform<D extends DocumentNode>(document: D): D;
522537
}
523538

539+
// @public (undocumented)
540+
type FragmentType<TData> = [
541+
TData
542+
] extends [{
543+
" $fragmentName"?: infer TKey;
544+
}] ? TKey extends string ? {
545+
" $fragmentRefs"?: {
546+
[key in TKey]: TData;
547+
};
548+
} : never : never;
549+
524550
// @internal
525551
const getApolloCacheMemoryInternals: (() => {
526552
cache: {
@@ -704,6 +730,17 @@ export function makeReference(id: string): Reference;
704730
// @public (undocumented)
705731
export function makeVar<T>(value: T): ReactiveVar<T>;
706732

733+
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
734+
// Warning: (ae-forgotten-export) The symbol "RemoveMaskedMarker" needs to be exported by the entry point index.d.ts
735+
// Warning: (ae-forgotten-export) The symbol "DataMasking" needs to be exported by the entry point index.d.ts
736+
//
737+
// @public
738+
type MaybeMasked<TData> = TData extends {
739+
__masked?: true;
740+
} ? Prettify<RemoveMaskedMarker<TData>> : DataMasking extends {
741+
enabled: true;
742+
} ? TData : Unmasked<TData>;
743+
707744
// @public (undocumented)
708745
export interface MergeInfo {
709746
// (undocumented)
@@ -769,6 +806,9 @@ export type Modifiers<T extends Record<string, any> = Record<string, unknown>> =
769806
[FieldName in keyof T]: Modifier<StoreObjectValueMaybeReference<Exclude<T[FieldName], undefined>>>;
770807
}>;
771808

809+
// @public
810+
type NoInfer_2<T> = [T][T extends any ? 0 : never];
811+
772812
// @public
773813
export interface NormalizedCache {
774814
// (undocumented)
@@ -867,6 +907,11 @@ export type PossibleTypesMap = {
867907
[supertype: string]: string[];
868908
};
869909

910+
// @public (undocumented)
911+
type Prettify<T> = {
912+
[K in keyof T]: T[K];
913+
} & {};
914+
870915
// @public (undocumented)
871916
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
872917

@@ -928,6 +973,12 @@ export interface Reference {
928973
readonly __ref: string;
929974
}
930975

976+
// @public (undocumented)
977+
type RemoveFragmentName<T> = T extends any ? Omit<T, " $fragmentName"> : T;
978+
979+
// @public (undocumented)
980+
type RemoveMaskedMarker<T> = Omit<T, "__masked">;
981+
931982
// @public (undocumented)
932983
type SafeReadonly<T> = T extends object ? Readonly<T> : T;
933984

@@ -984,22 +1035,41 @@ export type TypePolicy = {
9841035
};
9851036
};
9861037

1038+
// @public (undocumented)
1039+
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
1040+
1041+
// @public
1042+
type Unmasked<TData> = TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<TData>>> : TData;
1043+
1044+
// Warning: (ae-forgotten-export) The symbol "CombineFragmentRefs" needs to be exported by the entry point index.d.ts
1045+
//
1046+
// @public (undocumented)
1047+
type UnwrapFragmentRefs<TData> = string extends keyof NonNullable<TData> ? TData : " $fragmentRefs" extends keyof NonNullable<TData> ? TData extends {
1048+
" $fragmentRefs"?: infer FragmentRefs extends object;
1049+
} ? Prettify<{
1050+
[K in keyof TData as K extends " $fragmentRefs" ? never : K]: UnwrapFragmentRefs<TData[K]>;
1051+
} & CombineFragmentRefs<FragmentRefs>> : never : TData extends object ? {
1052+
[K in keyof TData]: UnwrapFragmentRefs<TData[K]>;
1053+
} : TData;
1054+
9871055
// @public
9881056
export interface WatchFragmentOptions<TData, TVars> {
9891057
fragment: DocumentNode | TypedDocumentNode<TData, TVars>;
9901058
fragmentName?: string;
991-
from: StoreObject | Reference | string;
1059+
// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
1060+
// Warning: (ae-forgotten-export) The symbol "NoInfer_2" needs to be exported by the entry point index.d.ts
1061+
from: StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string;
9921062
optimistic?: boolean;
9931063
variables?: TVars;
9941064
}
9951065

9961066
// @public
9971067
export type WatchFragmentResult<TData> = {
998-
data: TData;
1068+
data: MaybeMasked<TData>;
9991069
complete: true;
10001070
missing?: never;
10011071
} | {
1002-
data: DeepPartial<TData>;
1072+
data: DeepPartial<MaybeMasked<TData>>;
10031073
complete: false;
10041074
missing: MissingTree;
10051075
};
@@ -1038,6 +1108,7 @@ interface WriteContext extends ReadMergeModifyContext {
10381108

10391109
// Warnings were encountered during analysis:
10401110
//
1111+
// src/cache/core/cache.ts:92:7 - (ae-forgotten-export) The symbol "MaybeMasked" needs to be exported by the entry point index.d.ts
10411112
// src/cache/inmemory/policies.ts:92:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
10421113
// src/cache/inmemory/policies.ts:161:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
10431114
// src/cache/inmemory/policies.ts:161:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts

0 commit comments

Comments
 (0)