{"version":3,"file":"createQueryPreloader.js","sourceRoot":"","sources":["../../../src/react/query-preloader/createQueryPreloader.ts"],"names":[],"mappings":";AAeA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAsI5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAyB;IAEzB,OAAO,SAAS,YAAY,CAI1B,KAA0D,EAC1D,OACmD;;QADnD,wBAAA,EAAA,UACgC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAEnD,IAAM,QAAQ,GAAG,IAAI,sBAAsB,CACzC,MAAM,CAAC,UAAU,CAAC,sBACb,OAAO,KACV,KAAK,OAAA,GACyB,CAAC,EACjC;YACE,oBAAoB,EAClB,MAAA,MAAA,MAAM,CAAC,cAAc,CAAC,KAAK,0CAAE,QAAQ,0CAAE,oBAAoB;SAC9D,CACF,CAAC;QAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport type {\n DeepPartial,\n OnlyRequiredProperties,\n} from \"../../utilities/index.js\";\nimport { InternalQueryReference, wrapQueryRef } from \"../internal/index.js\";\nimport type { QueryReference } from \"../internal/index.js\";\nimport type { NoInfer } from \"../index.js\";\n\ntype VariablesOption =\n [TVariables] extends [never] ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: Record;\n }\n : {} extends OnlyRequiredProperties ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: TVariables;\n }\n : {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables: TVariables;\n };\n\nexport type PreloadQueryFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport type PreloadQueryOptions<\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults?: boolean;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: PreloadQueryFetchPolicy;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n} & VariablesOption;\n\ntype PreloadQueryOptionsArg<\n TVariables extends OperationVariables,\n TOptions = unknown,\n> = [TVariables] extends [never] ?\n [options?: PreloadQueryOptions & TOptions]\n: {} extends OnlyRequiredProperties ?\n [\n options?: PreloadQueryOptions> &\n Omit,\n ]\n: [\n options: PreloadQueryOptions> &\n Omit,\n ];\n\n/**\n * A function that will begin loading a query when called. It's result can be\n * read by {@link useReadQuery} which will suspend until the query is loaded.\n * This is useful when you want to start loading a query as early as possible\n * outside of a React component.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * const queryRef = preloadQuery(query, { variables, ...otherOptions });\n *\n * function App() {\n * return (\n * Loading}>\n * \n * \n * );\n * }\n *\n * function MyQuery() {\n * const { data } = useReadQuery(queryRef);\n *\n * // do something with `data`\n * }\n * ```\n */\nexport interface PreloadQueryFunction {\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit,\n >(\n query: DocumentNode | TypedDocumentNode,\n ...[options]: PreloadQueryOptionsArg, TOptions>\n ): QueryReference<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial\n : TData,\n TVariables\n >;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n (\n query: DocumentNode | TypedDocumentNode,\n options: PreloadQueryOptions> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): QueryReference | undefined, TVariables>;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n (\n query: DocumentNode | TypedDocumentNode,\n options: PreloadQueryOptions> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n ): QueryReference;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n (\n query: DocumentNode | TypedDocumentNode,\n options: PreloadQueryOptions> & {\n returnPartialData: true;\n }\n ): QueryReference, TVariables>;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n (\n query: DocumentNode | TypedDocumentNode,\n ...[options]: PreloadQueryOptionsArg>\n ): QueryReference;\n}\n\n/**\n * A higher order function that returns a `preloadQuery` function which\n * can be used to begin loading a query with the given `client`. This is useful\n * when you want to start loading a query as early as possible outside of a\n * React component.\n *\n * > Refer to the [Suspense - Initiating queries outside React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react) section for a more in-depth overview.\n *\n * @param client - The `ApolloClient` instance that will be used to load queries\n * from the returned `preloadQuery` function.\n * @returns The `preloadQuery` function.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * ```\n * @since 3.9.0\n * @alpha\n */\nexport function createQueryPreloader(\n client: ApolloClient\n): PreloadQueryFunction {\n return function preloadQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode,\n options: PreloadQueryOptions> &\n VariablesOption = Object.create(null)\n ): QueryReference {\n const queryRef = new InternalQueryReference(\n client.watchQuery({\n ...options,\n query,\n } as WatchQueryOptions),\n {\n autoDisposeTimeoutMs:\n client.defaultOptions.react?.suspense?.autoDisposeTimeoutMs,\n }\n );\n\n return wrapQueryRef(queryRef);\n };\n}\n"]}