@apollo/client-react-streaming
Advanced tools
Comparing version 0.0.0-commit-312f655 to 0.0.0-commit-4fc1615
@@ -6,5 +6,45 @@ import * as _apollo_client_index_js from '@apollo/client/index.js'; | ||
/** | ||
* > This export is only available in React Server Components | ||
* | ||
* Ensures that during RSC for an ongoing request, you can always | ||
* access the same instance of ApolloClient, while always returning | ||
* a new instance of different requests. | ||
* | ||
* @example | ||
* ```ts | ||
* export const { getClient } = registerApolloClient(() => { | ||
* return new ApolloClient({ | ||
* cache: new InMemoryCache(), | ||
* link: new HttpLink({ | ||
* uri: "http://example.com/api/graphql", | ||
* }), | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare function registerApolloClient(makeClient: () => Promise<ApolloClient$1<any>>): { | ||
getClient: () => Promise<ApolloClient$1<any>>; | ||
}; | ||
/** | ||
* Ensures that during RSC for an ongoing request, you can always | ||
* access the same instance of ApolloClient, while always returning | ||
* a new instance of different requests. | ||
* | ||
* @example | ||
* ```ts | ||
* export const { getClient } = registerApolloClient(() => { | ||
* return new ApolloClient({ | ||
* cache: new InMemoryCache(), | ||
* link: new HttpLink({ | ||
* uri: "http://example.com/api/graphql", | ||
* }), | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare function registerApolloClient(makeClient: () => ApolloClient$1<any>): { | ||
@@ -23,2 +63,23 @@ getClient: () => ApolloClient$1<any>; | ||
} | ||
/** | ||
* | ||
* This link can be used to "debounce" the initial response of a multipart request. Any incremental data received during the `cutoffDelay` time will be merged into the initial response. | ||
* | ||
* After `cutoffDelay`, the link will return the initial response, even if there is still incremental data pending, and close the network connection. | ||
* | ||
* If `cutoffDelay` is `0`, the link will immediately return data as soon as it is received, without waiting for incremental data, and immediately close the network connection. | ||
* | ||
* @example | ||
* ```ts | ||
* new AccumulateMultipartResponsesLink({ | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class AccumulateMultipartResponsesLink extends ApolloLink { | ||
@@ -44,11 +105,10 @@ private maxDelay; | ||
/** | ||
* This link is used to strip directives from the query before it is sent to the server. | ||
* This link will (if called with `stripDefer: true`) strip all `@defer` fragments from your query. | ||
* | ||
* This is used to prevent the server from doing additional work in SSR scenarios where multipart responses cannot be handled anyways. | ||
* This stripping behaviour can be configured per-directive. | ||
* It be overridden by adding a label to the directive. | ||
* In the case this link is configured to strip a directive, but the directive has a label starting with "SsrDontStrip", the directive will not be stripped. | ||
* In the case this link is configured to not strip a directive, but the directive has a label starting with "SsrStrip", the directive will be stripped. | ||
* | ||
* You can exclude certain fragments from this behavior by giving them a label starting with `"SsrDontStrip"`. | ||
* The "starting with" is important, because labels have to be unique per operation. So if you have multiple directives where you want to override the default stipping behaviour, | ||
* you can do this by annotating them like | ||
* ```gql | ||
* ```graphql | ||
* query myQuery { | ||
@@ -65,2 +125,20 @@ * fastField | ||
* | ||
* You can also use the link with `stripDefer: false` and mark certain fragments to be stripped by giving them a label starting with `"SsrStrip"`. | ||
* | ||
* @example | ||
* ```ts | ||
* new RemoveMultipartDirectivesLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -95,2 +173,30 @@ declare class RemoveMultipartDirectivesLink extends ApolloLink { | ||
} | ||
/** | ||
* A convenient combination of `RemoveMultipartDirectivesLink` and `AccumulateMultipartResponsesLink`. | ||
* | ||
* @example | ||
* ```ts | ||
* new SSRMultipartLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* // | ||
* // Defaults to `0`. | ||
* // | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class SSRMultipartLink extends ApolloLink { | ||
@@ -101,9 +207,7 @@ constructor(config?: SSRMultipartLinkConfig); | ||
/** | ||
* We just subclass `InMemoryCache` here so that `WrappedApolloClient` | ||
* can detect if it was initialized with an `InMemoryCache` instance that | ||
* was also exported from this package. | ||
* Right now, we don't have extra logic here, but we might have so again | ||
* in the future. | ||
* So we want to enforce this import path from the start to prevent future | ||
* subtle bugs if people update the package and don't read the patch notes. | ||
* A version of `InMemoryCache` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/cache/InMemoryCache | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
@@ -123,3 +227,25 @@ declare class InMemoryCache extends InMemoryCache$1 { | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* If you create a custom data transport, you need to wrap the child tree in a | ||
* `DataTransportContext.Provider` and provide the `DataTransportAbstraction` to it. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
declare const DataTransportContext: React.Context<DataTransportAbstraction | null>; | ||
/** | ||
* Interface to be implemented by a custom data transport component, | ||
* for usage with `WrapApolloProvider`. | ||
* | ||
* This component needs to provide a `DataTransportContext` to it's children. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
type DataTransportProviderImplementation<ExtraProps = {}> = React.FC<{ | ||
@@ -145,2 +271,10 @@ /** will be present in the Browser */ | ||
}; | ||
/** | ||
* Events that will be emitted by a wrapped ApolloClient instance during | ||
* SSR on `DataTransportProviderImplementation.registerDispatchRequestStarted`, | ||
* to be transported to the browser and replayed there using | ||
* `DataTransportProviderImplementation.onQueryEvent`. | ||
* | ||
* @public | ||
*/ | ||
type QueryEvent = { | ||
@@ -168,5 +302,14 @@ type: "started"; | ||
declare class ApolloClientBase<TCacheShape> extends ApolloClient$1<TCacheShape> { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
protected info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
} | ||
declare class ApolloClientSSRImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
watchQueryQueue: { | ||
@@ -193,2 +336,3 @@ push: (value: { | ||
declare class ApolloClientBrowserImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
private simulatedStreamingQueries; | ||
@@ -211,8 +355,26 @@ private transportedQueryOptions; | ||
} | ||
type ApolloClient<TCacheShape> = ApolloClient$1<TCacheShape> & Partial<ApolloClientBrowserImpl<TCacheShape>> & Partial<ApolloClientSSRImpl<TCacheShape>>; | ||
declare const ApolloClient: { | ||
new <TCacheShape>(options: ApolloClientOptions<TCacheShape>): ApolloClient<TCacheShape>; | ||
}; | ||
declare const ApolloClient_base: typeof ApolloClientBase; | ||
/** | ||
* A version of `ApolloClient` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/core/ApolloClient | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
declare class ApolloClient<TCacheShape> extends ApolloClient_base<TCacheShape> implements Partial<ApolloClientBrowserImpl<TCacheShape>>, Partial<ApolloClientSSRImpl<TCacheShape>> { | ||
/** @internal */ | ||
onQueryStarted?: ApolloClientBrowserImpl<TCacheShape>["onQueryStarted"]; | ||
/** @internal */ | ||
onQueryProgress?: ApolloClientBrowserImpl<TCacheShape>["onQueryProgress"]; | ||
/** @internal */ | ||
rerunSimulatedQueries?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQueries"]; | ||
/** @internal */ | ||
rerunSimulatedQuery?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQuery"]; | ||
/** @internal */ | ||
watchQueryQueue?: ApolloClientSSRImpl<TCacheShape>["watchQueryQueue"]; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Resets the singleton instances created for the Apollo SSR data transport and caches. | ||
@@ -224,2 +386,4 @@ * | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -236,11 +400,33 @@ declare function resetApolloSingletons(): void; | ||
/** | ||
* > This is only available in React Client Components | ||
* | ||
* A version of `ApolloProvider` particularly suited for React's streaming SSR. | ||
* | ||
* @public | ||
*/ | ||
interface WrappedApolloProvider<ExtraProps> { | ||
({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>): React.JSX.Element; | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Creates an ApolloProvider for streaming SSR. | ||
* @param TransportProvider The transport provider to be used. | ||
* | ||
* @param TransportProvider - The transport provider to be used. | ||
* This could e.g. be a `ManualDataTransport` created by `buildManualDataTransport`, | ||
* or a fully custom implementation of `DataTransportProviderImplementation`. | ||
* @public | ||
*/ | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): ({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>) => React.JSX.Element; | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): WrappedApolloProvider<ExtraProps>; | ||
declare const enableSSRWaitForUseQuery: (client: ApolloClient<any>) => void; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, enableSSRWaitForUseQuery, registerApolloClient, resetApolloSingletons }; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, type WrappedApolloProvider, registerApolloClient, resetApolloSingletons }; |
import * as _apollo_client_index_js from '@apollo/client/index.js'; | ||
import { ApolloLink, Operation, NextLink, FetchResult, InMemoryCache as InMemoryCache$1, Observable as Observable$1, WatchQueryOptions, ApolloClient as ApolloClient$1, ApolloClientOptions, OperationVariables } from '@apollo/client/index.js'; | ||
import { ApolloLink, Operation, NextLink, FetchResult, InMemoryCache as InMemoryCache$1, Observable as Observable$1, WatchQueryOptions, ApolloClientOptions, OperationVariables, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { Observable } from '@apollo/client/utilities/index.js'; | ||
@@ -15,2 +15,23 @@ import React from 'react'; | ||
} | ||
/** | ||
* | ||
* This link can be used to "debounce" the initial response of a multipart request. Any incremental data received during the `cutoffDelay` time will be merged into the initial response. | ||
* | ||
* After `cutoffDelay`, the link will return the initial response, even if there is still incremental data pending, and close the network connection. | ||
* | ||
* If `cutoffDelay` is `0`, the link will immediately return data as soon as it is received, without waiting for incremental data, and immediately close the network connection. | ||
* | ||
* @example | ||
* ```ts | ||
* new AccumulateMultipartResponsesLink({ | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class AccumulateMultipartResponsesLink extends ApolloLink { | ||
@@ -36,11 +57,10 @@ private maxDelay; | ||
/** | ||
* This link is used to strip directives from the query before it is sent to the server. | ||
* This link will (if called with `stripDefer: true`) strip all `@defer` fragments from your query. | ||
* | ||
* This is used to prevent the server from doing additional work in SSR scenarios where multipart responses cannot be handled anyways. | ||
* This stripping behaviour can be configured per-directive. | ||
* It be overridden by adding a label to the directive. | ||
* In the case this link is configured to strip a directive, but the directive has a label starting with "SsrDontStrip", the directive will not be stripped. | ||
* In the case this link is configured to not strip a directive, but the directive has a label starting with "SsrStrip", the directive will be stripped. | ||
* | ||
* You can exclude certain fragments from this behavior by giving them a label starting with `"SsrDontStrip"`. | ||
* The "starting with" is important, because labels have to be unique per operation. So if you have multiple directives where you want to override the default stipping behaviour, | ||
* you can do this by annotating them like | ||
* ```gql | ||
* ```graphql | ||
* query myQuery { | ||
@@ -57,2 +77,20 @@ * fastField | ||
* | ||
* You can also use the link with `stripDefer: false` and mark certain fragments to be stripped by giving them a label starting with `"SsrStrip"`. | ||
* | ||
* @example | ||
* ```ts | ||
* new RemoveMultipartDirectivesLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -87,2 +125,30 @@ declare class RemoveMultipartDirectivesLink extends ApolloLink { | ||
} | ||
/** | ||
* A convenient combination of `RemoveMultipartDirectivesLink` and `AccumulateMultipartResponsesLink`. | ||
* | ||
* @example | ||
* ```ts | ||
* new SSRMultipartLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* // | ||
* // Defaults to `0`. | ||
* // | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class SSRMultipartLink extends ApolloLink { | ||
@@ -93,9 +159,7 @@ constructor(config?: SSRMultipartLinkConfig); | ||
/** | ||
* We just subclass `InMemoryCache` here so that `WrappedApolloClient` | ||
* can detect if it was initialized with an `InMemoryCache` instance that | ||
* was also exported from this package. | ||
* Right now, we don't have extra logic here, but we might have so again | ||
* in the future. | ||
* So we want to enforce this import path from the start to prevent future | ||
* subtle bugs if people update the package and don't read the patch notes. | ||
* A version of `InMemoryCache` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/cache/InMemoryCache | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
@@ -115,3 +179,25 @@ declare class InMemoryCache extends InMemoryCache$1 { | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* If you create a custom data transport, you need to wrap the child tree in a | ||
* `DataTransportContext.Provider` and provide the `DataTransportAbstraction` to it. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
declare const DataTransportContext: React.Context<DataTransportAbstraction | null>; | ||
/** | ||
* Interface to be implemented by a custom data transport component, | ||
* for usage with `WrapApolloProvider`. | ||
* | ||
* This component needs to provide a `DataTransportContext` to it's children. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
type DataTransportProviderImplementation<ExtraProps = {}> = React.FC<{ | ||
@@ -137,2 +223,10 @@ /** will be present in the Browser */ | ||
}; | ||
/** | ||
* Events that will be emitted by a wrapped ApolloClient instance during | ||
* SSR on `DataTransportProviderImplementation.registerDispatchRequestStarted`, | ||
* to be transported to the browser and replayed there using | ||
* `DataTransportProviderImplementation.onQueryEvent`. | ||
* | ||
* @public | ||
*/ | ||
type QueryEvent = { | ||
@@ -160,5 +254,14 @@ type: "started"; | ||
declare class ApolloClientBase<TCacheShape> extends ApolloClient$1<TCacheShape> { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
protected info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
} | ||
declare class ApolloClientSSRImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
watchQueryQueue: { | ||
@@ -185,2 +288,3 @@ push: (value: { | ||
declare class ApolloClientBrowserImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
private simulatedStreamingQueries; | ||
@@ -203,8 +307,26 @@ private transportedQueryOptions; | ||
} | ||
type ApolloClient<TCacheShape> = ApolloClient$1<TCacheShape> & Partial<ApolloClientBrowserImpl<TCacheShape>> & Partial<ApolloClientSSRImpl<TCacheShape>>; | ||
declare const ApolloClient: { | ||
new <TCacheShape>(options: ApolloClientOptions<TCacheShape>): ApolloClient<TCacheShape>; | ||
}; | ||
declare const ApolloClient_base: typeof ApolloClientBase; | ||
/** | ||
* A version of `ApolloClient` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/core/ApolloClient | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
declare class ApolloClient<TCacheShape> extends ApolloClient_base<TCacheShape> implements Partial<ApolloClientBrowserImpl<TCacheShape>>, Partial<ApolloClientSSRImpl<TCacheShape>> { | ||
/** @internal */ | ||
onQueryStarted?: ApolloClientBrowserImpl<TCacheShape>["onQueryStarted"]; | ||
/** @internal */ | ||
onQueryProgress?: ApolloClientBrowserImpl<TCacheShape>["onQueryProgress"]; | ||
/** @internal */ | ||
rerunSimulatedQueries?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQueries"]; | ||
/** @internal */ | ||
rerunSimulatedQuery?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQuery"]; | ||
/** @internal */ | ||
watchQueryQueue?: ApolloClientSSRImpl<TCacheShape>["watchQueryQueue"]; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Resets the singleton instances created for the Apollo SSR data transport and caches. | ||
@@ -216,2 +338,4 @@ * | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -228,11 +352,33 @@ declare function resetApolloSingletons(): void; | ||
/** | ||
* > This is only available in React Client Components | ||
* | ||
* A version of `ApolloProvider` particularly suited for React's streaming SSR. | ||
* | ||
* @public | ||
*/ | ||
interface WrappedApolloProvider<ExtraProps> { | ||
({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>): React.JSX.Element; | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Creates an ApolloProvider for streaming SSR. | ||
* @param TransportProvider The transport provider to be used. | ||
* | ||
* @param TransportProvider - The transport provider to be used. | ||
* This could e.g. be a `ManualDataTransport` created by `buildManualDataTransport`, | ||
* or a fully custom implementation of `DataTransportProviderImplementation`. | ||
* @public | ||
*/ | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): ({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>) => React.JSX.Element; | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): WrappedApolloProvider<ExtraProps>; | ||
declare const enableSSRWaitForUseQuery: (client: ApolloClient<any>) => void; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, enableSSRWaitForUseQuery, resetApolloSingletons }; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, type WrappedApolloProvider, resetApolloSingletons }; |
@@ -1,2 +0,2 @@ | ||
import { ApolloLink, InMemoryCache as InMemoryCache$1, Observable as Observable$1, ApolloProvider, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { ApolloLink, InMemoryCache as InMemoryCache$1, ApolloProvider, Observable as Observable$1, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { hasDirectives, Observable, removeDirectivesFromDocument, mergeIncrementalData, print } from '@apollo/client/utilities/index.js'; | ||
@@ -161,2 +161,4 @@ import { canonicalStringify } from '@apollo/client/cache/index.js'; | ||
} | ||
// src/DataTransportAbstraction/hooks.ts | ||
var hookWrappers = { | ||
@@ -189,11 +191,20 @@ useFragment(orig_useFragment) { | ||
} | ||
var enableSSRWaitForUseQuery = () => { | ||
// src/bundleInfo.ts | ||
var bundle = { | ||
pkg: "@apollo/client-react-streaming", | ||
client: "ApolloClient", | ||
cache: "InMemoryCache" | ||
}; | ||
// src/DataTransportAbstraction/WrappedApolloClient.tsx | ||
function getQueryManager2(client) { | ||
function getQueryManager(client) { | ||
return client["queryManager"]; | ||
} | ||
var wrappers2 = Symbol.for("apollo.hook.wrappers"); | ||
var wrappers = Symbol.for("apollo.hook.wrappers"); | ||
var ApolloClientBase = class extends ApolloClient$1 { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info = bundle; | ||
constructor(options) { | ||
@@ -203,9 +214,12 @@ super(options); | ||
throw new Error( | ||
"When using Apollo Client streaming SSR, you must use the `InMemoryCache` variant provided by the streaming package." | ||
`When using \`InMemoryCache\` in streaming SSR, you must use the \`${this.info.cache}\` export provided by \`"${this.info.pkg}"\`.` | ||
); | ||
} | ||
getQueryManager2(this)[wrappers2] = hookWrappers; | ||
} | ||
}; | ||
var ApolloClientBrowserImpl = class extends ApolloClientBase { | ||
constructor(options) { | ||
super(options); | ||
getQueryManager(this)[wrappers] = hookWrappers; | ||
} | ||
simulatedStreamingQueries = /* @__PURE__ */ new Map(); | ||
@@ -217,3 +231,3 @@ transportedQueryOptions = /* @__PURE__ */ new Map(); | ||
); | ||
const queryManager = getQueryManager2(this); | ||
const queryManager = getQueryManager(this); | ||
const { serverQuery } = queryManager.getDocumentInfo(transformedDocument); | ||
@@ -236,3 +250,3 @@ if (!serverQuery) { | ||
const printedServerQuery = print(query); | ||
const queryManager = getQueryManager2(this); | ||
const queryManager = getQueryManager(this); | ||
if (!queryManager["inFlightLinkObservables"].peek(printedServerQuery, varJson)?.observable) { | ||
@@ -325,3 +339,3 @@ let simulatedStreamingQuery, fetchCancelFn; | ||
rerunSimulatedQuery = (queryInfo) => { | ||
const queryManager = getQueryManager2(this); | ||
const queryManager = getQueryManager(this); | ||
const queryId = queryManager.generateQueryId(); | ||
@@ -337,3 +351,5 @@ queryManager.fetchQuery(queryId, { | ||
}; | ||
var ApolloClient = ApolloClientBrowserImpl ; | ||
var ApolloClientImplementation = ApolloClientBrowserImpl ; | ||
var ApolloClient = class extends ApolloClientImplementation { | ||
}; | ||
@@ -350,3 +366,3 @@ // src/DataTransportAbstraction/symbols.ts | ||
function WrapApolloProvider(TransportProvider) { | ||
const WrappedApolloProvider = ({ | ||
const WrappedApolloProvider3 = ({ | ||
makeClient, | ||
@@ -362,3 +378,3 @@ children, | ||
throw new Error( | ||
"When using Apollo Client streaming SSR, you must use the `ApolloClient` variant provided by the streaming package." | ||
`When using \`ApolloClient\` in streaming SSR, you must use the \`${WrappedApolloProvider3.info.client}\` export provided by \`"${WrappedApolloProvider3.info.pkg}"\`.` | ||
); | ||
@@ -377,7 +393,8 @@ } | ||
}; | ||
return WrappedApolloProvider; | ||
WrappedApolloProvider3.info = bundle; | ||
return WrappedApolloProvider3; | ||
} | ||
export { ApolloClient, DataTransportContext, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, enableSSRWaitForUseQuery, resetApolloSingletons }; | ||
export { ApolloClient, DataTransportContext, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, resetApolloSingletons }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -5,5 +5,45 @@ import * as _apollo_client_index_js from '@apollo/client/index.js'; | ||
/** | ||
* > This export is only available in React Server Components | ||
* | ||
* Ensures that during RSC for an ongoing request, you can always | ||
* access the same instance of ApolloClient, while always returning | ||
* a new instance of different requests. | ||
* | ||
* @example | ||
* ```ts | ||
* export const { getClient } = registerApolloClient(() => { | ||
* return new ApolloClient({ | ||
* cache: new InMemoryCache(), | ||
* link: new HttpLink({ | ||
* uri: "http://example.com/api/graphql", | ||
* }), | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare function registerApolloClient(makeClient: () => Promise<ApolloClient$1<any>>): { | ||
getClient: () => Promise<ApolloClient$1<any>>; | ||
}; | ||
/** | ||
* Ensures that during RSC for an ongoing request, you can always | ||
* access the same instance of ApolloClient, while always returning | ||
* a new instance of different requests. | ||
* | ||
* @example | ||
* ```ts | ||
* export const { getClient } = registerApolloClient(() => { | ||
* return new ApolloClient({ | ||
* cache: new InMemoryCache(), | ||
* link: new HttpLink({ | ||
* uri: "http://example.com/api/graphql", | ||
* }), | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare function registerApolloClient(makeClient: () => ApolloClient$1<any>): { | ||
@@ -22,2 +62,23 @@ getClient: () => ApolloClient$1<any>; | ||
} | ||
/** | ||
* | ||
* This link can be used to "debounce" the initial response of a multipart request. Any incremental data received during the `cutoffDelay` time will be merged into the initial response. | ||
* | ||
* After `cutoffDelay`, the link will return the initial response, even if there is still incremental data pending, and close the network connection. | ||
* | ||
* If `cutoffDelay` is `0`, the link will immediately return data as soon as it is received, without waiting for incremental data, and immediately close the network connection. | ||
* | ||
* @example | ||
* ```ts | ||
* new AccumulateMultipartResponsesLink({ | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class AccumulateMultipartResponsesLink extends ApolloLink { | ||
@@ -43,11 +104,10 @@ private maxDelay; | ||
/** | ||
* This link is used to strip directives from the query before it is sent to the server. | ||
* This link will (if called with `stripDefer: true`) strip all `@defer` fragments from your query. | ||
* | ||
* This is used to prevent the server from doing additional work in SSR scenarios where multipart responses cannot be handled anyways. | ||
* This stripping behaviour can be configured per-directive. | ||
* It be overridden by adding a label to the directive. | ||
* In the case this link is configured to strip a directive, but the directive has a label starting with "SsrDontStrip", the directive will not be stripped. | ||
* In the case this link is configured to not strip a directive, but the directive has a label starting with "SsrStrip", the directive will be stripped. | ||
* | ||
* You can exclude certain fragments from this behavior by giving them a label starting with `"SsrDontStrip"`. | ||
* The "starting with" is important, because labels have to be unique per operation. So if you have multiple directives where you want to override the default stipping behaviour, | ||
* you can do this by annotating them like | ||
* ```gql | ||
* ```graphql | ||
* query myQuery { | ||
@@ -64,2 +124,20 @@ * fastField | ||
* | ||
* You can also use the link with `stripDefer: false` and mark certain fragments to be stripped by giving them a label starting with `"SsrStrip"`. | ||
* | ||
* @example | ||
* ```ts | ||
* new RemoveMultipartDirectivesLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -94,2 +172,30 @@ declare class RemoveMultipartDirectivesLink extends ApolloLink { | ||
} | ||
/** | ||
* A convenient combination of `RemoveMultipartDirectivesLink` and `AccumulateMultipartResponsesLink`. | ||
* | ||
* @example | ||
* ```ts | ||
* new SSRMultipartLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* // | ||
* // Defaults to `0`. | ||
* // | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class SSRMultipartLink extends ApolloLink { | ||
@@ -100,9 +206,7 @@ constructor(config?: SSRMultipartLinkConfig); | ||
/** | ||
* We just subclass `InMemoryCache` here so that `WrappedApolloClient` | ||
* can detect if it was initialized with an `InMemoryCache` instance that | ||
* was also exported from this package. | ||
* Right now, we don't have extra logic here, but we might have so again | ||
* in the future. | ||
* So we want to enforce this import path from the start to prevent future | ||
* subtle bugs if people update the package and don't read the patch notes. | ||
* A version of `InMemoryCache` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/cache/InMemoryCache | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
@@ -115,2 +219,10 @@ declare class InMemoryCache extends InMemoryCache$1 { | ||
}; | ||
/** | ||
* Events that will be emitted by a wrapped ApolloClient instance during | ||
* SSR on `DataTransportProviderImplementation.registerDispatchRequestStarted`, | ||
* to be transported to the browser and replayed there using | ||
* `DataTransportProviderImplementation.onQueryEvent`. | ||
* | ||
* @public | ||
*/ | ||
type QueryEvent = { | ||
@@ -138,5 +250,14 @@ type: "started"; | ||
declare class ApolloClientBase<TCacheShape> extends ApolloClient$1<TCacheShape> { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
protected info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
} | ||
declare class ApolloClientSSRImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
watchQueryQueue: { | ||
@@ -163,2 +284,3 @@ push: (value: { | ||
declare class ApolloClientBrowserImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
private simulatedStreamingQueries; | ||
@@ -181,6 +303,22 @@ private transportedQueryOptions; | ||
} | ||
type ApolloClient<TCacheShape> = ApolloClient$1<TCacheShape> & Partial<ApolloClientBrowserImpl<TCacheShape>> & Partial<ApolloClientSSRImpl<TCacheShape>>; | ||
declare const ApolloClient: { | ||
new <TCacheShape>(options: ApolloClientOptions<TCacheShape>): ApolloClient<TCacheShape>; | ||
}; | ||
declare const ApolloClient_base: typeof ApolloClientBase; | ||
/** | ||
* A version of `ApolloClient` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/core/ApolloClient | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
declare class ApolloClient<TCacheShape> extends ApolloClient_base<TCacheShape> implements Partial<ApolloClientBrowserImpl<TCacheShape>>, Partial<ApolloClientSSRImpl<TCacheShape>> { | ||
/** @internal */ | ||
onQueryStarted?: ApolloClientBrowserImpl<TCacheShape>["onQueryStarted"]; | ||
/** @internal */ | ||
onQueryProgress?: ApolloClientBrowserImpl<TCacheShape>["onQueryProgress"]; | ||
/** @internal */ | ||
rerunSimulatedQueries?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQueries"]; | ||
/** @internal */ | ||
rerunSimulatedQuery?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQuery"]; | ||
/** @internal */ | ||
watchQueryQueue?: ApolloClientSSRImpl<TCacheShape>["watchQueryQueue"]; | ||
} | ||
@@ -187,0 +325,0 @@ declare const ApolloClientSingleton: unique symbol; |
@@ -148,6 +148,29 @@ import { cache } from 'react'; | ||
}; | ||
var ApolloClient = ApolloClient$1; | ||
// src/bundleInfo.ts | ||
var bundle = { | ||
pkg: "@apollo/client-react-streaming", | ||
client: "ApolloClient", | ||
cache: "InMemoryCache" | ||
}; | ||
var ApolloClientBase = class extends ApolloClient$1 { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info = bundle; | ||
constructor(options) { | ||
super(options); | ||
if (!(this.cache instanceof InMemoryCache)) { | ||
throw new Error( | ||
`When using \`InMemoryCache\` in streaming SSR, you must use the \`${this.info.cache}\` export provided by \`"${this.info.pkg}"\`.` | ||
); | ||
} | ||
} | ||
}; | ||
var ApolloClientImplementation = ApolloClientBase; | ||
var ApolloClient = class extends ApolloClientImplementation { | ||
}; | ||
export { ApolloClient, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, RemoveMultipartDirectivesLink, SSRMultipartLink, registerApolloClient }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.rsc.js.map |
import * as _apollo_client_index_js from '@apollo/client/index.js'; | ||
import { ApolloLink, Operation, NextLink, FetchResult, InMemoryCache as InMemoryCache$1, Observable as Observable$1, WatchQueryOptions, ApolloClient as ApolloClient$1, ApolloClientOptions, OperationVariables } from '@apollo/client/index.js'; | ||
import { ApolloLink, Operation, NextLink, FetchResult, InMemoryCache as InMemoryCache$1, Observable as Observable$1, WatchQueryOptions, ApolloClientOptions, OperationVariables, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { Observable } from '@apollo/client/utilities/index.js'; | ||
@@ -15,2 +15,23 @@ import React from 'react'; | ||
} | ||
/** | ||
* | ||
* This link can be used to "debounce" the initial response of a multipart request. Any incremental data received during the `cutoffDelay` time will be merged into the initial response. | ||
* | ||
* After `cutoffDelay`, the link will return the initial response, even if there is still incremental data pending, and close the network connection. | ||
* | ||
* If `cutoffDelay` is `0`, the link will immediately return data as soon as it is received, without waiting for incremental data, and immediately close the network connection. | ||
* | ||
* @example | ||
* ```ts | ||
* new AccumulateMultipartResponsesLink({ | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class AccumulateMultipartResponsesLink extends ApolloLink { | ||
@@ -36,11 +57,10 @@ private maxDelay; | ||
/** | ||
* This link is used to strip directives from the query before it is sent to the server. | ||
* This link will (if called with `stripDefer: true`) strip all `@defer` fragments from your query. | ||
* | ||
* This is used to prevent the server from doing additional work in SSR scenarios where multipart responses cannot be handled anyways. | ||
* This stripping behaviour can be configured per-directive. | ||
* It be overridden by adding a label to the directive. | ||
* In the case this link is configured to strip a directive, but the directive has a label starting with "SsrDontStrip", the directive will not be stripped. | ||
* In the case this link is configured to not strip a directive, but the directive has a label starting with "SsrStrip", the directive will be stripped. | ||
* | ||
* You can exclude certain fragments from this behavior by giving them a label starting with `"SsrDontStrip"`. | ||
* The "starting with" is important, because labels have to be unique per operation. So if you have multiple directives where you want to override the default stipping behaviour, | ||
* you can do this by annotating them like | ||
* ```gql | ||
* ```graphql | ||
* query myQuery { | ||
@@ -57,2 +77,20 @@ * fastField | ||
* | ||
* You can also use the link with `stripDefer: false` and mark certain fragments to be stripped by giving them a label starting with `"SsrStrip"`. | ||
* | ||
* @example | ||
* ```ts | ||
* new RemoveMultipartDirectivesLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -87,2 +125,30 @@ declare class RemoveMultipartDirectivesLink extends ApolloLink { | ||
} | ||
/** | ||
* A convenient combination of `RemoveMultipartDirectivesLink` and `AccumulateMultipartResponsesLink`. | ||
* | ||
* @example | ||
* ```ts | ||
* new SSRMultipartLink({ | ||
* // Whether to strip fragments with `@defer` directives | ||
* // from queries before sending them to the server. | ||
* // | ||
* // Defaults to `true`. | ||
* // | ||
* // Can be overwritten by adding a label starting | ||
* // with either `"SsrDontStrip"` or `"SsrStrip"` to the | ||
* // directive. | ||
* stripDefer: true, | ||
* // The maximum delay in milliseconds | ||
* // from receiving the first response | ||
* // until the accumulated data will be flushed | ||
* // and the connection will be closed. | ||
* // | ||
* // Defaults to `0`. | ||
* // | ||
* cutoffDelay: 100, | ||
* }); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare class SSRMultipartLink extends ApolloLink { | ||
@@ -93,9 +159,7 @@ constructor(config?: SSRMultipartLinkConfig); | ||
/** | ||
* We just subclass `InMemoryCache` here so that `WrappedApolloClient` | ||
* can detect if it was initialized with an `InMemoryCache` instance that | ||
* was also exported from this package. | ||
* Right now, we don't have extra logic here, but we might have so again | ||
* in the future. | ||
* So we want to enforce this import path from the start to prevent future | ||
* subtle bugs if people update the package and don't read the patch notes. | ||
* A version of `InMemoryCache` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/cache/InMemoryCache | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
@@ -115,3 +179,25 @@ declare class InMemoryCache extends InMemoryCache$1 { | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* If you create a custom data transport, you need to wrap the child tree in a | ||
* `DataTransportContext.Provider` and provide the `DataTransportAbstraction` to it. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
declare const DataTransportContext: React.Context<DataTransportAbstraction | null>; | ||
/** | ||
* Interface to be implemented by a custom data transport component, | ||
* for usage with `WrapApolloProvider`. | ||
* | ||
* This component needs to provide a `DataTransportContext` to it's children. | ||
* | ||
* See for example | ||
* https://github.com/apollographql/apollo-client-nextjs/blob/37feeaa9aea69b90a974eb9cd0fbd636b62d841a/integration-test/experimental-react/src/WrappedApolloProvider.tsx | ||
* | ||
* @public | ||
*/ | ||
type DataTransportProviderImplementation<ExtraProps = {}> = React.FC<{ | ||
@@ -137,2 +223,10 @@ /** will be present in the Browser */ | ||
}; | ||
/** | ||
* Events that will be emitted by a wrapped ApolloClient instance during | ||
* SSR on `DataTransportProviderImplementation.registerDispatchRequestStarted`, | ||
* to be transported to the browser and replayed there using | ||
* `DataTransportProviderImplementation.onQueryEvent`. | ||
* | ||
* @public | ||
*/ | ||
type QueryEvent = { | ||
@@ -160,5 +254,14 @@ type: "started"; | ||
declare class ApolloClientBase<TCacheShape> extends ApolloClient$1<TCacheShape> { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
protected info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
} | ||
declare class ApolloClientSSRImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
watchQueryQueue: { | ||
@@ -185,2 +288,3 @@ push: (value: { | ||
declare class ApolloClientBrowserImpl<TCacheShape> extends ApolloClientBase<TCacheShape> { | ||
constructor(options: ApolloClientOptions<TCacheShape>); | ||
private simulatedStreamingQueries; | ||
@@ -203,8 +307,26 @@ private transportedQueryOptions; | ||
} | ||
type ApolloClient<TCacheShape> = ApolloClient$1<TCacheShape> & Partial<ApolloClientBrowserImpl<TCacheShape>> & Partial<ApolloClientSSRImpl<TCacheShape>>; | ||
declare const ApolloClient: { | ||
new <TCacheShape>(options: ApolloClientOptions<TCacheShape>): ApolloClient<TCacheShape>; | ||
}; | ||
declare const ApolloClient_base: typeof ApolloClientBase; | ||
/** | ||
* A version of `ApolloClient` to be used with streaming SSR. | ||
* | ||
* For more documentation, please see {@link https://www.apollographql.com/docs/react/api/core/ApolloClient | the Apollo Client API documentation}. | ||
* | ||
* @public | ||
*/ | ||
declare class ApolloClient<TCacheShape> extends ApolloClient_base<TCacheShape> implements Partial<ApolloClientBrowserImpl<TCacheShape>>, Partial<ApolloClientSSRImpl<TCacheShape>> { | ||
/** @internal */ | ||
onQueryStarted?: ApolloClientBrowserImpl<TCacheShape>["onQueryStarted"]; | ||
/** @internal */ | ||
onQueryProgress?: ApolloClientBrowserImpl<TCacheShape>["onQueryProgress"]; | ||
/** @internal */ | ||
rerunSimulatedQueries?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQueries"]; | ||
/** @internal */ | ||
rerunSimulatedQuery?: ApolloClientBrowserImpl<TCacheShape>["rerunSimulatedQuery"]; | ||
/** @internal */ | ||
watchQueryQueue?: ApolloClientSSRImpl<TCacheShape>["watchQueryQueue"]; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Resets the singleton instances created for the Apollo SSR data transport and caches. | ||
@@ -216,2 +338,4 @@ * | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -228,11 +352,33 @@ declare function resetApolloSingletons(): void; | ||
/** | ||
* > This is only available in React Client Components | ||
* | ||
* A version of `ApolloProvider` particularly suited for React's streaming SSR. | ||
* | ||
* @public | ||
*/ | ||
interface WrappedApolloProvider<ExtraProps> { | ||
({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>): React.JSX.Element; | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info: { | ||
pkg: string; | ||
client: string; | ||
cache: string; | ||
}; | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Creates an ApolloProvider for streaming SSR. | ||
* @param TransportProvider The transport provider to be used. | ||
* | ||
* @param TransportProvider - The transport provider to be used. | ||
* This could e.g. be a `ManualDataTransport` created by `buildManualDataTransport`, | ||
* or a fully custom implementation of `DataTransportProviderImplementation`. | ||
* @public | ||
*/ | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): ({ makeClient, children, ...extraProps }: React.PropsWithChildren<{ | ||
makeClient: () => ApolloClient<any>; | ||
} & ExtraProps>) => React.JSX.Element; | ||
declare function WrapApolloProvider<ExtraProps>(TransportProvider: DataTransportProviderImplementation<ExtraProps>): WrappedApolloProvider<ExtraProps>; | ||
declare const enableSSRWaitForUseQuery: (client: ApolloClient<any>) => void; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, enableSSRWaitForUseQuery, resetApolloSingletons }; | ||
export { ApolloClient, DataTransportContext, type DataTransportProviderImplementation, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, type QueryEvent, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, type WrappedApolloProvider, resetApolloSingletons }; |
@@ -1,6 +0,4 @@ | ||
import { ApolloLink, InMemoryCache as InMemoryCache$1, useApolloClient, Observable as Observable$1, ApolloProvider, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { ApolloLink, InMemoryCache as InMemoryCache$1, ApolloProvider, Observable as Observable$1, ApolloClient as ApolloClient$1 } from '@apollo/client/index.js'; | ||
import { hasDirectives, Observable, removeDirectivesFromDocument, mergeIncrementalData } from '@apollo/client/utilities/index.js'; | ||
import { canonicalStringify } from '@apollo/client/cache/index.js'; | ||
import React, { createContext, use, useRef, useState, useEffect, useContext } from 'react'; | ||
import { getSuspenseCache } from '@apollo/client/react/internal/index.js'; | ||
import React, { createContext, useRef, useState, useEffect, useContext } from 'react'; | ||
@@ -180,2 +178,4 @@ // src/AccumulateMultipartResponsesLink.ts | ||
} | ||
// src/DataTransportAbstraction/hooks.ts | ||
var hookWrappers = { | ||
@@ -208,31 +208,10 @@ useFragment(orig_useFragment) { | ||
} | ||
var enableSSRWaitForUseQuery = (client) => { | ||
getQueryManager(client)[wrappers].useQuery = (orig_useQuery) => wrap( | ||
function useQuery(query, options) { | ||
const client2 = useApolloClient(); | ||
const result = client2.cache.read({ | ||
query, | ||
variables: options?.variables, | ||
returnPartialData: options?.returnPartialData, | ||
optimistic: false | ||
}); | ||
if (!result) { | ||
const queryRef = getSuspenseCache(client2).getQueryRef( | ||
[query, canonicalStringify(options?.variables), "useQuery"], | ||
() => client2.watchQuery({ | ||
query, | ||
...options | ||
}) | ||
); | ||
use(queryRef.promise); | ||
} | ||
return orig_useQuery(query, { | ||
...options, | ||
fetchPolicy: "cache-only" | ||
}); | ||
}, | ||
["data", "loading", "networkStatus", "called"] | ||
); | ||
} ; | ||
// src/bundleInfo.ts | ||
var bundle = { | ||
pkg: "@apollo/client-react-streaming", | ||
client: "ApolloClient", | ||
cache: "InMemoryCache" | ||
}; | ||
// src/DataTransportAbstraction/WrappedApolloClient.tsx | ||
@@ -244,2 +223,6 @@ function getQueryManager(client) { | ||
var ApolloClientBase = class extends ApolloClient$1 { | ||
/** | ||
* Information about the current package and it's export names, for use in error messages. | ||
*/ | ||
info = bundle; | ||
constructor(options) { | ||
@@ -249,9 +232,12 @@ super(options); | ||
throw new Error( | ||
"When using Apollo Client streaming SSR, you must use the `InMemoryCache` variant provided by the streaming package." | ||
`When using \`InMemoryCache\` in streaming SSR, you must use the \`${this.info.cache}\` export provided by \`"${this.info.pkg}"\`.` | ||
); | ||
} | ||
getQueryManager(this)[wrappers] = hookWrappers; | ||
} | ||
}; | ||
var ApolloClientSSRImpl = class extends ApolloClientBase { | ||
constructor(options) { | ||
super(options); | ||
getQueryManager(this)[wrappers] = hookWrappers; | ||
} | ||
watchQueryQueue = createBackpressuredCallback(); | ||
@@ -303,3 +289,5 @@ watchQuery(options) { | ||
}; | ||
var ApolloClient = ApolloClientSSRImpl ; | ||
var ApolloClientImplementation = ApolloClientSSRImpl ; | ||
var ApolloClient = class extends ApolloClientImplementation { | ||
}; | ||
@@ -316,3 +304,3 @@ // src/DataTransportAbstraction/symbols.ts | ||
function WrapApolloProvider(TransportProvider) { | ||
const WrappedApolloProvider = ({ | ||
const WrappedApolloProvider3 = ({ | ||
makeClient, | ||
@@ -330,3 +318,3 @@ children, | ||
throw new Error( | ||
"When using Apollo Client streaming SSR, you must use the `ApolloClient` variant provided by the streaming package." | ||
`When using \`ApolloClient\` in streaming SSR, you must use the \`${WrappedApolloProvider3.info.client}\` export provided by \`"${WrappedApolloProvider3.info.pkg}"\`.` | ||
); | ||
@@ -345,7 +333,8 @@ } | ||
}; | ||
return WrappedApolloProvider; | ||
WrappedApolloProvider3.info = bundle; | ||
return WrappedApolloProvider3; | ||
} | ||
export { ApolloClient, DataTransportContext, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, enableSSRWaitForUseQuery, resetApolloSingletons }; | ||
export { ApolloClient, DataTransportContext, AccumulateMultipartResponsesLink as DebounceMultipartResponsesLink, InMemoryCache, RemoveMultipartDirectivesLink, SSRMultipartLink, WrapApolloProvider, resetApolloSingletons }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.ssr.js.map |
import React from 'react'; | ||
import { DataTransportProviderImplementation } from '@apollo/client-react-streaming'; | ||
/** | ||
* @public | ||
*/ | ||
interface HydrationContextOptions { | ||
/** | ||
* Props that will be passed down to `script` tags that will be used to transport | ||
* data to the browser. | ||
* Can e.g. be used to add a `nonce`. | ||
*/ | ||
extraScriptProps?: ScriptProps; | ||
@@ -19,5 +27,56 @@ } | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Creates a "manual" Data Transport, to be used with `WrapApolloProvider`. | ||
* | ||
* @remarks | ||
* | ||
* ### Drawbacks | ||
* | ||
* While this Data Transport enables streaming SSR, it has some conceptual drawbacks: | ||
* | ||
* - It does not have a way of keeping your connection open if your application already finished, but there are still ongoing queries that might need to be awaited transported over. | ||
* - This can happen if a component renders `useBackgroundQuery`, but does not read the `queryRef` with `useReadQuery` | ||
* - These "cut off" queries will be restarted in the Browser once the browser's `load` event happens | ||
* - If the `useInsertHtml` doesn't immediately flush data to the browser, the browser might already attain "newer" data through queries triggered by user interaction. | ||
* - This delayed behaviour is the case with the Next.js `ServerInsertedHTMLContext` and in the example Vite implementation. | ||
* - In this, case, older data from the server might overwrite newer data in the browser. | ||
* - This is minimized by simulating ongoing queries in the browser once the information of a started query is transported over. | ||
* If the browser would try to trigger the exact same query, query deduplication would make the browser wait for the server query to resolve instead. | ||
* - For more timing-related details, see https://github.com/apollographql/apollo-client-nextjs/pull/9 | ||
* | ||
* To fully work around these drawbacks, React needs to add "data injection into the stream" to it's public API, which is not the case today. | ||
* We provide an [example with a patched React version](https://github.com/apollographql/apollo-client-nextjs/blob/main/integration-test/experimental-react) to showcase how that could look. | ||
* | ||
* @example | ||
* For usage examples, see the implementation of the `@apollo/experimental-nextjs-app-support` | ||
* [`ApolloNextAppProvider`](https://github.com/apollographql/apollo-client-nextjs/blob/c0715a05cf8ca29a3cbb9ce294cdcbc5ce251b2e/packages/experimental-nextjs-app-support/src/ApolloNextAppProvider.ts) | ||
* | ||
* ```tsx | ||
* export const ApolloNextAppProvider = WrapApolloProvider( | ||
* buildManualDataTransport({ | ||
* useInsertHtml() { | ||
* const insertHtml = useContext(ServerInsertedHTMLContext); | ||
* if (!insertHtml) { | ||
* throw new Error( | ||
* "ApolloNextAppProvider cannot be used outside of the Next App Router!" | ||
* ); | ||
* } | ||
* return insertHtml; | ||
* }, | ||
* }) | ||
* ); | ||
* ``` | ||
* | ||
* @example | ||
* Another usage example is our integration example with Vite and streaming SSR, which you can find at https://github.com/apollographql/apollo-client-nextjs/tree/main/integration-test/vite-streaming | ||
* | ||
* @public | ||
*/ | ||
declare const buildManualDataTransport: (args: BuildArgs) => DataTransportProviderImplementation<HydrationContextOptions>; | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Resets the singleton instances created for the Apollo SSR data transport and caches. | ||
@@ -29,2 +88,4 @@ * | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -31,0 +92,0 @@ declare function resetManualSSRApolloSingletons(): void; |
import React from 'react'; | ||
import { DataTransportProviderImplementation } from '@apollo/client-react-streaming'; | ||
/** | ||
* @public | ||
*/ | ||
interface HydrationContextOptions { | ||
/** | ||
* Props that will be passed down to `script` tags that will be used to transport | ||
* data to the browser. | ||
* Can e.g. be used to add a `nonce`. | ||
*/ | ||
extraScriptProps?: ScriptProps; | ||
@@ -19,5 +27,56 @@ } | ||
} | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Creates a "manual" Data Transport, to be used with `WrapApolloProvider`. | ||
* | ||
* @remarks | ||
* | ||
* ### Drawbacks | ||
* | ||
* While this Data Transport enables streaming SSR, it has some conceptual drawbacks: | ||
* | ||
* - It does not have a way of keeping your connection open if your application already finished, but there are still ongoing queries that might need to be awaited transported over. | ||
* - This can happen if a component renders `useBackgroundQuery`, but does not read the `queryRef` with `useReadQuery` | ||
* - These "cut off" queries will be restarted in the Browser once the browser's `load` event happens | ||
* - If the `useInsertHtml` doesn't immediately flush data to the browser, the browser might already attain "newer" data through queries triggered by user interaction. | ||
* - This delayed behaviour is the case with the Next.js `ServerInsertedHTMLContext` and in the example Vite implementation. | ||
* - In this, case, older data from the server might overwrite newer data in the browser. | ||
* - This is minimized by simulating ongoing queries in the browser once the information of a started query is transported over. | ||
* If the browser would try to trigger the exact same query, query deduplication would make the browser wait for the server query to resolve instead. | ||
* - For more timing-related details, see https://github.com/apollographql/apollo-client-nextjs/pull/9 | ||
* | ||
* To fully work around these drawbacks, React needs to add "data injection into the stream" to it's public API, which is not the case today. | ||
* We provide an [example with a patched React version](https://github.com/apollographql/apollo-client-nextjs/blob/main/integration-test/experimental-react) to showcase how that could look. | ||
* | ||
* @example | ||
* For usage examples, see the implementation of the `@apollo/experimental-nextjs-app-support` | ||
* [`ApolloNextAppProvider`](https://github.com/apollographql/apollo-client-nextjs/blob/c0715a05cf8ca29a3cbb9ce294cdcbc5ce251b2e/packages/experimental-nextjs-app-support/src/ApolloNextAppProvider.ts) | ||
* | ||
* ```tsx | ||
* export const ApolloNextAppProvider = WrapApolloProvider( | ||
* buildManualDataTransport({ | ||
* useInsertHtml() { | ||
* const insertHtml = useContext(ServerInsertedHTMLContext); | ||
* if (!insertHtml) { | ||
* throw new Error( | ||
* "ApolloNextAppProvider cannot be used outside of the Next App Router!" | ||
* ); | ||
* } | ||
* return insertHtml; | ||
* }, | ||
* }) | ||
* ); | ||
* ``` | ||
* | ||
* @example | ||
* Another usage example is our integration example with Vite and streaming SSR, which you can find at https://github.com/apollographql/apollo-client-nextjs/tree/main/integration-test/vite-streaming | ||
* | ||
* @public | ||
*/ | ||
declare const buildManualDataTransport: (args: BuildArgs) => DataTransportProviderImplementation<HydrationContextOptions>; | ||
/** | ||
* > This export is only available in React Client Components | ||
* | ||
* Resets the singleton instances created for the Apollo SSR data transport and caches. | ||
@@ -29,2 +88,4 @@ * | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
@@ -31,0 +92,0 @@ declare function resetManualSSRApolloSingletons(): void; |
{ | ||
"name": "@apollo/client-react-streaming", | ||
"version": "0.0.0-commit-312f655", | ||
"version": "0.0.0-commit-4fc1615", | ||
"repository": { | ||
@@ -30,2 +30,16 @@ "url": "git+https://github.com/apollographql/apollo-client-nextjs" | ||
} | ||
}, | ||
"#bundled/manual-transport": { | ||
"require": { | ||
"types": "./dist/manual-transport.ssr.d.cts", | ||
"react-server": "./dist/empty.cjs", | ||
"browser": "./dist/manual-transport.browser.cjs", | ||
"node": "./dist/manual-transport.ssr.cjs" | ||
}, | ||
"import": { | ||
"types": "./dist/manual-transport.ssr.d.ts", | ||
"react-server": "./dist/empty.js", | ||
"browser": "./dist/manual-transport.browser.js", | ||
"node": "./dist/manual-transport.ssr.js" | ||
} | ||
} | ||
@@ -97,4 +111,5 @@ }, | ||
"devDependencies": { | ||
"@apollo/client": "3.9.1", | ||
"@apollo/client": "^3.9.6", | ||
"@arethetypeswrong/cli": "0.13.6", | ||
"@microsoft/api-extractor": "^7.42.3", | ||
"@testing-library/react": "^14.2.1", | ||
@@ -117,2 +132,3 @@ "@total-typescript/shoehorn": "0.1.1", | ||
"react": "18.3.0-canary-60a927d04-20240113", | ||
"react-error-boundary": "^4.0.13", | ||
"rimraf": "5.0.5", | ||
@@ -119,0 +135,0 @@ "superjson": "1.13.3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
499873
41
3892
0
14
28