diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 35789a5844..92b34976cf 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -103,6 +103,10 @@ export class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; @@ -144,12 +148,14 @@ export class ApolloClient implements DataProxy { export interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -593,6 +599,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) export type DiffQueryAgainstStoreOptions = ReadQueryOptions & { returnPartialData?: boolean; diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 6fd83bb10f..916035b05c 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -114,6 +114,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -171,12 +175,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -680,6 +686,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_components.api.md b/.api-reports/api-report-react_components.api.md index 350691ae93..90af57d6d2 100644 --- a/.api-reports/api-report-react_components.api.md +++ b/.api-reports/api-report-react_components.api.md @@ -114,6 +114,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -172,12 +176,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -623,6 +629,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_context.api.md b/.api-reports/api-report-react_context.api.md index 41aed0f90c..f2ec9bb082 100644 --- a/.api-reports/api-report-react_context.api.md +++ b/.api-reports/api-report-react_context.api.md @@ -113,6 +113,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -171,12 +175,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -618,6 +624,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_hoc.api.md b/.api-reports/api-report-react_hoc.api.md index 18f094dde4..f82219194f 100644 --- a/.api-reports/api-report-react_hoc.api.md +++ b/.api-reports/api-report-react_hoc.api.md @@ -113,6 +113,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -171,12 +175,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -616,6 +622,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_hooks.api.md b/.api-reports/api-report-react_hooks.api.md index 861d5c8919..094ea9d31a 100644 --- a/.api-reports/api-report-react_hooks.api.md +++ b/.api-reports/api-report-react_hooks.api.md @@ -112,6 +112,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -170,12 +174,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -646,6 +652,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_internal.api.md b/.api-reports/api-report-react_internal.api.md index 77a4d29c2f..81bffbb745 100644 --- a/.api-reports/api-report-react_internal.api.md +++ b/.api-reports/api-report-react_internal.api.md @@ -112,6 +112,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -170,12 +174,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -631,6 +637,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index ea788b305b..ca7a9f6f20 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -113,6 +113,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -171,12 +175,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -587,6 +593,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-testing.api.md b/.api-reports/api-report-testing.api.md index 01ba05ec8b..ffcefbd2d4 100644 --- a/.api-reports/api-report-testing.api.md +++ b/.api-reports/api-report-testing.api.md @@ -113,6 +113,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -171,12 +175,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -588,6 +594,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index 545e30231c..b065971038 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -112,6 +112,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts @@ -170,12 +174,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -587,6 +593,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) class DocumentTransform { // Warning: (ae-forgotten-export) The symbol "TransformFn" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 84e1668f11..7b26126fdc 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -126,6 +126,10 @@ class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; @@ -183,12 +187,14 @@ class ApolloClient implements DataProxy { interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -779,6 +785,12 @@ const _deleteModifier: unique symbol; // @public @deprecated (undocumented) export const DEV: boolean; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) export type DirectiveInfo = { [fieldName: string]: { diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 181d29f827..a56145500e 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -105,6 +105,10 @@ export class ApolloClient implements DataProxy { get defaultContext(): Partial; // (undocumented) defaultOptions: DefaultOptions; + // Warning: (ae-forgotten-export) The symbol "DevtoolsOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + readonly devtoolsConfig: DevtoolsOptions; // (undocumented) disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; @@ -146,12 +150,14 @@ export class ApolloClient implements DataProxy { export interface ApolloClientOptions { assumeImmutableResults?: boolean; cache: ApolloCache; + // @deprecated connectToDevTools?: boolean; // (undocumented) credentials?: string; // (undocumented) defaultContext?: Partial; defaultOptions?: DefaultOptions; + devtools?: DevtoolsOptions; // (undocumented) documentTransform?: DocumentTransform; // (undocumented) @@ -694,6 +700,12 @@ interface DeleteModifier { // @public (undocumented) const _deleteModifier: unique symbol; +// @public (undocumented) +interface DevtoolsOptions { + enabled?: boolean; + name?: string; +} + // @public (undocumented) export type DiffQueryAgainstStoreOptions = ReadQueryOptions & { returnPartialData?: boolean; diff --git a/.changeset/pink-ants-remember.md b/.changeset/pink-ants-remember.md new file mode 100644 index 0000000000..b5d5506d5b --- /dev/null +++ b/.changeset/pink-ants-remember.md @@ -0,0 +1,16 @@ +--- +"@apollo/client": minor +--- + +Add the ability to specify a name for the client instance for use with Apollo Client Devtools. This is useful when instantiating multiple clients to identify the client instance more easily. This deprecates the `connectToDevtools` option in favor of a new `devtools` configuration. + +```ts +new ApolloClient({ + devtools: { + enabled: true, + name: "Test Client", + }, +}); +``` + +This option is backwards-compatible with `connectToDevtools` and will be used in the absense of a `devtools` option. diff --git a/.size-limits.json b/.size-limits.json index e7e76549d6..c81dd92070 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 40066, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32903 + "dist/apollo-client.min.cjs": 40110, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32941 } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 05e713d520..307ea715e8 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -41,6 +41,22 @@ export interface DefaultOptions { mutate?: Partial>; } +export interface DevtoolsOptions { + /** + * If `true`, the [Apollo Client Devtools](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) browser extension can connect to this `ApolloClient` instance. + * + * The default value is `false` in production and `true` in development if there is a `window` object. + */ + enabled?: boolean; + + /** + * Optional name for this `ApolloClient` instance in the devtools. This is + * useful when you instantiate multiple clients and want to be able to + * identify them by name. + */ + name?: string; +} + let hasSuggestedDevtools = false; export interface ApolloClientOptions { @@ -85,6 +101,7 @@ export interface ApolloClientOptions { * If `true`, the [Apollo Client Devtools](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) browser extension can connect to Apollo Client. * * The default value is `false` in production and `true` in development (if there is a `window` object). + * @deprecated Please use the `devtools.enabled` option. */ connectToDevTools?: boolean; /** @@ -120,6 +137,13 @@ export interface ApolloClientOptions { */ version?: string; documentTransform?: DocumentTransform; + + /** + * Configuration used by the [Apollo Client Devtools extension](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) for this client. + * + * @since 3.11.0 + */ + devtools?: DevtoolsOptions; } // Though mergeOptions now resides in @apollo/client/utilities, it was @@ -148,6 +172,7 @@ export class ApolloClient implements DataProxy { public queryDeduplication: boolean; public defaultOptions: DefaultOptions; public readonly typeDefs: ApolloClientOptions["typeDefs"]; + public readonly devtoolsConfig: DevtoolsOptions; private queryManager: QueryManager; private devToolsHookCb?: Function; @@ -201,9 +226,7 @@ export class ApolloClient implements DataProxy { // Expose the client instance as window.__APOLLO_CLIENT__ and call // onBroadcast in queryManager.broadcastQueries to enable browser // devtools, but disable them by default in production. - connectToDevTools = typeof window === "object" && - !(window as any).__APOLLO_CLIENT__ && - __DEV__, + connectToDevTools, queryDeduplication = true, defaultOptions, defaultContext, @@ -213,6 +236,7 @@ export class ApolloClient implements DataProxy { fragmentMatcher, name: clientAwarenessName, version: clientAwarenessVersion, + devtools, } = options; let { link } = options; @@ -228,6 +252,17 @@ export class ApolloClient implements DataProxy { this.queryDeduplication = queryDeduplication; this.defaultOptions = defaultOptions || Object.create(null); this.typeDefs = typeDefs; + this.devtoolsConfig = { + ...devtools, + enabled: devtools?.enabled || connectToDevTools, + }; + + if (this.devtoolsConfig.enabled === undefined) { + this.devtoolsConfig.enabled = + typeof window === "object" && + (window as any).__APOLLO_CLIENT__ && + __DEV__; + } if (ssrForceFetchDelay) { setTimeout( @@ -283,7 +318,7 @@ export class ApolloClient implements DataProxy { : void 0, }); - if (connectToDevTools) this.connectToDevTools(); + if (this.devtoolsConfig.enabled) this.connectToDevTools(); } private connectToDevTools() {