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

[Data masking] Ensure @unmask can be used with the fragment registry #12029

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e634509
Add failing test for looking up unmasked fragments in the fragment re…
jerelmiller Aug 23, 2024
70f07f1
Provide a lookupFragment function on the base cache
jerelmiller Aug 24, 2024
7a30aa3
Override lookupFragment in inMemoryCache that uses the fragment confi…
jerelmiller Aug 24, 2024
5f7c3be
Update how result is returned for fragment test
jerelmiller Aug 24, 2024
5928957
Add a lookup for fragment registry for maskOperation
jerelmiller Aug 24, 2024
3ac0b63
Fix incorrect check in test
jerelmiller Aug 24, 2024
22d9f04
Ensure maskFragment can lookup fragments by name from fragment registry
jerelmiller Aug 24, 2024
f2144be
Use object for maskOperation options
jerelmiller Aug 24, 2024
a20d1b3
Add a maskOperation function to QueryManager
jerelmiller Aug 24, 2024
8807d32
Use queryManager.maskOperation in ObservableQuery
jerelmiller Aug 24, 2024
639f792
Make fragmentMatches public
jerelmiller Aug 24, 2024
ac951b7
Move maskFragment over to QueryManager
jerelmiller Aug 24, 2024
a00229c
Remove core cache tests for cache.maskFragment
jerelmiller Aug 24, 2024
001904a
Move maskOperation to QueryManager
jerelmiller Aug 24, 2024
b286015
Remove core cache tests for cache.maskOperation
jerelmiller Aug 24, 2024
13a627b
Destructure cache from this
jerelmiller Aug 24, 2024
1bc29e6
Rerun api report
jerelmiller Aug 24, 2024
1ee2991
Pass cache to maskOperation and maskFragment instead of individual fu…
jerelmiller Aug 24, 2024
bcc742b
Move check for cache APIs over to masking
jerelmiller Aug 24, 2024
214228f
Add ! since we know cache implements interface
jerelmiller Aug 24, 2024
8752477
Move warning to external function to keep message in one place
jerelmiller Aug 24, 2024
34c3453
Make fragmentName optional
jerelmiller Aug 24, 2024
7e59500
Update masking tests to pass cache
jerelmiller Aug 24, 2024
b033d63
Update size limits
jerelmiller Aug 24, 2024
da12339
Move the mask options types to QueryManager
jerelmiller Aug 24, 2024
620500c
Use ternary to handle masking in QueryManager
jerelmiller Aug 24, 2024
2b6beb2
Rerun api report
jerelmiller Aug 24, 2024
62c6a1d
Move core fragment masking logic back to cache
jerelmiller Aug 27, 2024
995f394
Add back maskFragment to queryManager for useFragment
jerelmiller Aug 27, 2024
9f6697e
Update size limits
jerelmiller Aug 27, 2024
5dbab89
Cache the result of the fragment lookup in the fragment map
jerelmiller Aug 28, 2024
f6466d8
Clean up Prettier, Size-limit, and Api-Extractor
jerelmiller Aug 28, 2024
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
17 changes: 5 additions & 12 deletions .api-reports/api-report-cache.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
abstract evict(options: Cache_2.EvictOptions): boolean;
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
protected fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
Expand All @@ -40,9 +40,7 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// (undocumented)
maskOperation<TData = unknown>(document: DocumentNode, data: TData): TData;
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
// (undocumented)
Expand Down Expand Up @@ -583,7 +581,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// (undocumented)
extract(optimistic?: boolean): NormalizedCacheObject;
// (undocumented)
protected fragmentMatches(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(options?: {
resetResultCache?: boolean;
Expand All @@ -596,6 +594,8 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
readonly makeVar: typeof makeVar;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
Expand Down Expand Up @@ -704,13 +704,6 @@ export function makeReference(id: string): Reference;
// @public (undocumented)
export function makeVar<T>(value: T): ReactiveVar<T>;

// @public (undocumented)
export interface MaskFragmentOptions<TData> {
data: TData;
fragment: DocumentNode | TypedDocumentNode<TData>;
fragmentName?: string;
}

// @public (undocumented)
export interface MergeInfo {
// (undocumented)
Expand Down
35 changes: 25 additions & 10 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
abstract evict(options: Cache_2.EvictOptions): boolean;
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
protected fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
Expand All @@ -54,12 +54,8 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
getMemoryInternals?: typeof getApolloCacheMemoryInternals;
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// (undocumented)
maskOperation<TData = unknown>(document: DocumentNode, data: TData): TData;
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
// (undocumented)
Expand Down Expand Up @@ -1113,7 +1109,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// (undocumented)
extract(optimistic?: boolean): NormalizedCacheObject;
// (undocumented)
protected fragmentMatches(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(options?: {
resetResultCache?: boolean;
Expand All @@ -1126,6 +1122,8 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// (undocumented)
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
readonly makeVar: typeof makeVar;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
Expand Down Expand Up @@ -1317,11 +1315,22 @@ export function makeVar<T>(value: T): ReactiveVar<T>;

// @public (undocumented)
interface MaskFragmentOptions<TData> {
// (undocumented)
data: TData;
fragment: DocumentNode | TypedDocumentNode<TData>;
// (undocumented)
fragment: DocumentNode;
// (undocumented)
fragmentName?: string;
}

// @public (undocumented)
interface MaskOperationOptions<TData> {
// (undocumented)
data: TData;
// (undocumented)
document: DocumentNode;
}

// @public (undocumented)
type MaybeAsync<T> = T | PromiseLike<T>;

Expand Down Expand Up @@ -1857,8 +1866,14 @@ class QueryManager<TStore> {
onQueryUpdated?: OnQueryUpdated<any>;
keepRootFields?: boolean;
}, cache?: ApolloCache<TStore>): Promise<FetchResult<TData>>;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// Warning: (ae-forgotten-export) The symbol "MaskOperationOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskOperation<TData = unknown>(options: MaskOperationOptions<TData>): TData;
// (undocumented)
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
// (undocumented)
Expand Down Expand Up @@ -2343,8 +2358,8 @@ interface WriteContext extends ReadMergeModifyContext {
// src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:116:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:117:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:144:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:389:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:152:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:397:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts

Expand Down
31 changes: 22 additions & 9 deletions .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
abstract evict(options: Cache_2.EvictOptions): boolean;
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
protected fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
Expand All @@ -52,12 +52,8 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
//
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// (undocumented)
maskOperation<TData = unknown>(document: DocumentNode, data: TData): TData;
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
// Warning: (ae-forgotten-export) The symbol "Transaction" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1074,11 +1070,22 @@ type LocalStateOptions<TCacheShape> = {

// @public (undocumented)
interface MaskFragmentOptions<TData> {
// (undocumented)
data: TData;
fragment: DocumentNode | TypedDocumentNode<TData>;
// (undocumented)
fragment: DocumentNode;
// (undocumented)
fragmentName?: string;
}

// @public (undocumented)
interface MaskOperationOptions<TData> {
// (undocumented)
data: TData;
// (undocumented)
document: DocumentNode;
}

// @public (undocumented)
type MaybeAsync<T> = T | PromiseLike<T>;

Expand Down Expand Up @@ -1635,8 +1642,14 @@ class QueryManager<TStore> {
onQueryUpdated?: OnQueryUpdated<any>;
keepRootFields?: boolean;
}, cache?: ApolloCache<TStore>): Promise<FetchResult<TData>>;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// Warning: (ae-forgotten-export) The symbol "MaskOperationOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskOperation<TData = unknown>(options: MaskOperationOptions<TData>): TData;
// (undocumented)
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
// (undocumented)
Expand Down Expand Up @@ -2367,8 +2380,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:116:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:117:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:144:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:389:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:152:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:397:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
Expand Down
31 changes: 22 additions & 9 deletions .api-reports/api-report-react_components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
abstract evict(options: Cache_2.EvictOptions): boolean;
abstract extract(optimistic?: boolean): TSerialized;
// (undocumented)
protected fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
// (undocumented)
gc(): string[];
// Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts
Expand All @@ -52,12 +52,8 @@ abstract class ApolloCache<TSerialized> implements DataProxy {
//
// (undocumented)
identify(object: StoreObject | Reference): string | undefined;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// (undocumented)
maskOperation<TData = unknown>(document: DocumentNode, data: TData): TData;
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
// (undocumented)
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache_2.ModifyOptions<Entity>): boolean;
// Warning: (ae-forgotten-export) The symbol "Transaction" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -935,11 +931,22 @@ type LocalStateOptions<TCacheShape> = {

// @public (undocumented)
interface MaskFragmentOptions<TData> {
// (undocumented)
data: TData;
fragment: DocumentNode | TypedDocumentNode<TData>;
// (undocumented)
fragment: DocumentNode;
// (undocumented)
fragmentName?: string;
}

// @public (undocumented)
interface MaskOperationOptions<TData> {
// (undocumented)
data: TData;
// (undocumented)
document: DocumentNode;
}

// @public (undocumented)
type MaybeAsync<T> = T | PromiseLike<T>;

Expand Down Expand Up @@ -1449,8 +1456,14 @@ class QueryManager<TStore> {
onQueryUpdated?: OnQueryUpdated<any>;
keepRootFields?: boolean;
}, cache?: ApolloCache<TStore>): Promise<FetchResult<TData>>;
// Warning: (ae-forgotten-export) The symbol "MaskFragmentOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
// Warning: (ae-forgotten-export) The symbol "MaskOperationOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
maskOperation<TData = unknown>(options: MaskOperationOptions<TData>): TData;
// (undocumented)
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
// (undocumented)
Expand Down Expand Up @@ -1846,8 +1859,8 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:116:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:117:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:144:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:389:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:152:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:397:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
Expand Down
Loading
Loading