Skip to content

Commit c97b145

Browse files
authored
Create mechanism to add experimental features to Apollo Client (#12915)
* Create mechanism to add experimental features to Apollo Client * add comment, v1 * Clean up Prettier, Size-limit, and Api-Extractor --------- Co-authored-by: phryneas <[email protected]>
1 parent 36e2413 commit c97b145

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

.api-reports/api-report-core.api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ export namespace ApolloClient {
195195
}
196196
}
197197
// (undocumented)
198+
export interface Experiment {
199+
// (undocumented)
200+
(this: ApolloClient, options: ApolloClient.Options): void;
201+
// (undocumented)
202+
v: 1;
203+
}
204+
// (undocumented)
198205
export type MutateOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = {
199206
optimisticResponse?: Unmasked<NoInfer<TData>> | ((vars: TVariables, { IGNORE }: {
200207
IGNORE: IgnoreModifier;
@@ -231,6 +238,7 @@ export namespace ApolloClient {
231238
documentTransform?: DocumentTransform;
232239
// (undocumented)
233240
enhancedClientAwareness?: ClientAwarenessLink.EnhancedClientAwarenessOptions;
241+
experiments?: ApolloClient.Experiment[];
234242
incrementalHandler?: Incremental.Handler<any>;
235243
link: ApolloLink;
236244
// (undocumented)
@@ -1132,7 +1140,7 @@ export type WatchQueryOptions<TVariables extends OperationVariables = OperationV
11321140

11331141
// Warnings were encountered during analysis:
11341142
//
1135-
// src/core/ApolloClient.ts:353:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1143+
// src/core/ApolloClient.ts:362:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
11361144
// src/core/ObservableQuery.ts:368:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
11371145
// src/core/QueryManager.ts:180:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
11381146

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ export namespace ApolloClient {
201201
variables?: TVariables;
202202
}
203203
}
204+
// (undocumented)
205+
export interface Experiment {
206+
// (undocumented)
207+
(this: ApolloClient, options: ApolloClient.Options): void;
208+
// (undocumented)
209+
v: 1;
210+
}
204211
// Warning: (ae-forgotten-export) The symbol "VariablesOption" needs to be exported by the entry point index.d.ts
205212
//
206213
// (undocumented)
@@ -242,6 +249,7 @@ export namespace ApolloClient {
242249
documentTransform?: DocumentTransform;
243250
// (undocumented)
244251
enhancedClientAwareness?: ClientAwarenessLink.EnhancedClientAwarenessOptions;
252+
experiments?: ApolloClient.Experiment[];
245253
// Warning: (ae-forgotten-export) The symbol "Incremental" needs to be exported by the entry point index.d.ts
246254
incrementalHandler?: Incremental.Handler<any>;
247255
link: ApolloLink;
@@ -2711,8 +2719,8 @@ interface WriteContext extends ReadMergeModifyContext {
27112719
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
27122720
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
27132721
// src/cache/inmemory/types.ts:134:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
2714-
// src/core/ApolloClient.ts:159:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2715-
// src/core/ApolloClient.ts:353:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
2722+
// src/core/ApolloClient.ts:168:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2723+
// src/core/ApolloClient.ts:362:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
27162724
// src/core/ObservableQuery.ts:368:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
27172725
// src/core/QueryManager.ts:180:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
27182726
// src/local-state/LocalState.ts:147:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts

.changeset/olive-queens-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Create mechanism to add experimental features to Apollo Client

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44574,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39359,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33705,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27700
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44542,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39461,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33696,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27707
66
}

src/core/ApolloClient.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ export declare namespace ApolloClient {
132132
* queries.
133133
*/
134134
incrementalHandler?: Incremental.Handler<any>;
135+
136+
/**
137+
* @experimental
138+
* Allows passing in "experiments", experimental features that might one day
139+
* become part of Apollo Client's core functionality.
140+
* Keep in mind that these features might change the core of Apollo Client.
141+
* Do not pass in experiments that are not provided by Apollo.
142+
*/
143+
experiments?: ApolloClient.Experiment[];
135144
}
136145

137146
interface DevtoolsOptions {
@@ -610,6 +619,11 @@ export declare namespace ApolloClient {
610619
variables?: TVariables;
611620
}
612621
}
622+
623+
export interface Experiment {
624+
(this: ApolloClient, options: ApolloClient.Options): void;
625+
v: 1;
626+
}
613627
}
614628

615629
/**
@@ -708,6 +722,7 @@ export class ApolloClient {
708722
dataMasking,
709723
link,
710724
incrementalHandler = new NotImplementedHandler(),
725+
experiments = [],
711726
} = options;
712727

713728
this.link = link;
@@ -759,6 +774,8 @@ export class ApolloClient {
759774
}
760775

761776
if (this.devtoolsConfig.enabled) this.connectToDevTools();
777+
778+
experiments.forEach((experiment) => experiment.call(this, options));
762779
}
763780

764781
private connectToDevTools() {

0 commit comments

Comments
 (0)