@apollo/client-integration-nextjs
Version:
<div align="center"> <img src="https://raw.githubusercontent.com/apollographql/apollo-client-integrations/main/banner.jpg" width="500" alt="Apollo Client + Next.js App Router" /> </div>
1 lines • 7.3 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.shared.ts","../src/bundleInfo.ts","../src/ApolloNextAppProvider.ts","../src/index.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACLA,IAAM,SAAS;AAAA,EACpB,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AACT;;;ADGA;AAAA,EACE,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,OACZ;AA0CA,IAAM,eAAN,cAA2B,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrD,OAAgB,OAAO;AACzB;AASO,IAAM,gBAAN,cAA4B,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvD,OAAgB,OAAO;AACzB;;;AE3EA,SAAS,kBAAkB;AAC3B,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AACnC,SAAS,iCAAiC;AA4CnC,IAAM,wBAAsC;AAAA,EACjD,yBAAyB;AAAA,IACvB,gBAAgB;AACd,YAAM,aAAa,WAAW,yBAAyB;AACvD,UAAI,CAAC,YAAY;AACf,YAAI,MAAqC;AAEvC,iBAAO,MAAM;AAAA,UAAC;AAAA,QAChB;AACA,cAAM,IAAI;AAAA,UACR;AAAA,QAEF;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AACA,sBAAsB,OAAO;;;AC/D7B,SAAS,sCAAsC;AAaxC,IAAM,8BAA8B","sourcesContent":["export {\n SSRMultipartLink,\n DebounceMultipartResponsesLink,\n RemoveMultipartDirectivesLink,\n type TransportedQueryRef,\n} from \"@apollo/client-react-streaming\";\nimport { bundle } from \"./bundleInfo.js\";\nimport {\n ApolloClient as UpstreamApolloClient,\n InMemoryCache as UpstreamInMemoryCache,\n} from \"@apollo/client-react-streaming\";\n\n/** @public */\nexport declare namespace ApolloClient {\n /** @public */\n export interface Options extends UpstreamApolloClient.Options {}\n /*\n We can currently not re-export these types from the upstream ApolloClient implementation because the build \n tooling doesn't support that:\n > DTS Build error\n > Error: namespace child (hoisting) not supported yet\n\n We could re-export them by defining them as new types that reference the originals, but that would require us\n to keep generics in sync and would either erase the docblocks or require us to duplicate them \n (and they would go out of sync).\n If you need any of the other types, please use the `ApolloClient` namespace exported from `@apollo/client` directly.\n */\n // export import DefaultOptions = UpstreamApolloClient.DefaultOptions;\n // export import DevtoolsOptions = UpstreamApolloClient.DevtoolsOptions;\n // export import MutateOptions = UpstreamApolloClient.MutateOptions;\n // export import MutateResult = UpstreamApolloClient.MutateResult;\n // export import QueryOptions = UpstreamApolloClient.QueryOptions;\n // export import QueryResult = UpstreamApolloClient.QueryResult;\n // export import RefetchQueriesOptions = UpstreamApolloClient.RefetchQueriesOptions;\n // export import RefetchQueriesResult = UpstreamApolloClient.RefetchQueriesResult;\n // export import SubscribeOptions = UpstreamApolloClient.SubscribeOptions;\n // export import SubscribeResult = UpstreamApolloClient.SubscribeResult;\n // export import WatchFragmentOptions = UpstreamApolloClient.WatchFragmentOptions;\n // export import WatchFragmentResult = UpstreamApolloClient.WatchFragmentResult;\n // export import WatchQueryOptions = UpstreamApolloClient.WatchQueryOptions;\n // export import ReadQueryOptions = UpstreamApolloClient.ReadQueryOptions;\n // export import WriteQueryOptions = UpstreamApolloClient.WriteQueryOptions;\n // export import WriteFragmentOptions = UpstreamApolloClient.WriteFragmentOptions;\n}\n\n/**\n * A version of `ApolloClient` to be used with streaming SSR or in React Server Components.\n *\n * For more documentation, please see {@link https://www.apollographql.com/docs/react/api/core/ApolloClient | the Apollo Client API documentation}.\n *\n * @public\n */\nexport class ApolloClient extends UpstreamApolloClient {\n /**\n * Information about the current package and it's export names, for use in error messages.\n *\n * @internal\n */\n static readonly info = bundle;\n}\n\n/**\n * A version of `InMemoryCache` to be used with streaming SSR.\n *\n * For more documentation, please see {@link https://www.apollographql.com/docs/react/api/cache/InMemoryCache | the Apollo Client API documentation}.\n *\n * @public\n */\nexport class InMemoryCache extends UpstreamInMemoryCache {\n /**\n * Information about the current package and it's export names, for use in error messages.\n *\n * @internal\n */\n static readonly info = bundle;\n}\n","export const bundle = {\n pkg: \"@apollo/client-integration-nextjs\",\n client: \"ApolloClient\",\n cache: \"InMemoryCache\",\n};\n","import { useContext } from \"react\";\nimport { buildManualDataTransport } from \"@apollo/client-react-streaming/manual-transport\";\nimport { WrapApolloProvider } from \"@apollo/client-react-streaming\";\nimport { ServerInsertedHTMLContext } from \"next/navigation.js\";\nimport { bundle } from \"./bundleInfo.js\";\n\n/**\n * > This export is only available in React Client Components\n *\n * A version of `ApolloProvider` to be used with the Next.js App Router.\n *\n * As opposed to the normal `ApolloProvider`, this version does not require a `client` prop,\n * but requires a `makeClient` prop instead.\n *\n * Use this component together with `ApolloClient` and `InMemoryCache`\n * from the `\"@apollo/client-integration-nextjs\"` package\n * to make an ApolloClient instance available to your Client Component hooks in the\n * Next.js App Router.\n *\n * @example\n * `app/ApolloWrapper.jsx`\n * ```tsx\n * import { HttpLink } from \"@apollo/client\";\n * import { ApolloNextAppProvider, ApolloClient, InMemoryCache } from \"@apollo/client-integration-nextjs\";\n *\n * function makeClient() {\n * const httpLink = new HttpLink({\n * uri: \"https://example.com/api/graphql\",\n * });\n *\n * return new ApolloClient({\n * cache: new InMemoryCache(),\n * link: httpLink,\n * });\n * }\n *\n * export function ApolloWrapper({ children }: React.PropsWithChildren) {\n * return (\n * <ApolloNextAppProvider makeClient={makeClient}>\n * {children}\n * </ApolloNextAppProvider>\n * );\n * }\n * ```\n *\n * @public\n */\nexport const ApolloNextAppProvider = /*#__PURE__*/ WrapApolloProvider(\n buildManualDataTransport({\n useInsertHtml() {\n const insertHtml = useContext(ServerInsertedHTMLContext);\n if (!insertHtml) {\n if (process.env.REACT_ENV === \"browser\") {\n //Allow using the browser build of ApolloNextAppProvider outside of Next.js, e.g. for tests.\n return () => {};\n }\n throw new Error(\n \"The SSR build of ApolloNextAppProvider cannot be used outside of the Next App Router!\\n\" +\n 'If you encounter this in a test, make sure that your tests are using the browser build by adding the \"browser\" import condition to your test setup.'\n );\n }\n return insertHtml;\n },\n })\n);\nApolloNextAppProvider.info = bundle;\n","export * from \"./index.shared.js\";\nexport { ApolloNextAppProvider } from \"./ApolloNextAppProvider.js\";\nimport { resetManualSSRApolloSingletons } from \"@apollo/client-react-streaming/manual-transport\";\n/**\n * > This export is only available in React Client Components\n *\n * Resets the singleton instances created for the Apollo SSR data transport and caches.\n *\n * To be used in testing only, like\n * ```ts\n * afterEach(resetApolloClientSingletons);\n * ```\n *\n * @public\n */\nexport const resetApolloClientSingletons = resetManualSSRApolloSingletons;\n"]}