@apollo/client 3.9.0-alpha.5 → 3.9.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/dirty-tigers-matter.md +13 -0
- package/.changeset/mighty-coats-check.md +47 -0
- package/.changeset/pre.json +9 -1
- package/.changeset/rare-snakes-melt.md +24 -0
- package/.changeset/swift-zoos-collect.md +19 -0
- package/.changeset/thick-tips-cry.md +9 -0
- package/.changeset/tough-timers-begin.md +8 -0
- package/.changeset/unlucky-rats-decide.md +5 -0
- package/.changeset/wet-forks-rhyme.md +5 -0
- package/CHANGELOG.md +118 -4
- package/apollo-client.cjs +329 -82
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +78 -6
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +78 -6
- package/cache/core/cache.d.ts +9 -0
- package/cache/core/cache.js +11 -2
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +7 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +12 -0
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +4 -0
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +19 -3
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +9 -0
- package/cache/inmemory/inMemoryCache.js +8 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/readFromStore.js +7 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +18 -0
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +9 -0
- package/core/ApolloClient.js +4 -0
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -0
- package/core/ObservableQuery.js +7 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -0
- package/core/QueryInfo.js +4 -0
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -1
- package/core/QueryManager.js +15 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +99 -12
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +99 -12
- package/core/watchQueryOptions.d.ts +20 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/core/ApolloLink.d.ts +15 -0
- package/link/core/ApolloLink.js +8 -4
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +8 -4
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +8 -4
- package/link/persisted-queries/index.d.ts +11 -1
- package/link/persisted-queries/index.js +28 -3
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +26 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +26 -3
- package/link/remove-typename/remove-typename.cjs +18 -2
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +18 -2
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
- package/link/remove-typename/removeTypenameFromVariables.js +19 -3
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/package.json +21 -21
- package/react/cache/QueryReference.d.ts +11 -5
- package/react/cache/QueryReference.js +91 -55
- package/react/cache/QueryReference.js.map +1 -1
- package/react/hooks/hooks.cjs +112 -52
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +112 -52
- package/react/hooks/index.d.ts +2 -0
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +12 -9
- package/react/hooks/useBackgroundQuery.js +1 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +1 -1
- package/react/hooks/useLoadableQuery.js +1 -1
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +35 -0
- package/react/hooks/useQueryRefHandlers.js +48 -0
- package/react/hooks/useQueryRefHandlers.js.map +1 -0
- package/react/hooks/useReadQuery.js +8 -2
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/index.d.ts +2 -0
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/react/parser/index.js +6 -3
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +11 -3
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +11 -3
- package/react/query-preloader/createQueryPreloader.d.ts +253 -0
- package/react/query-preloader/createQueryPreloader.js +29 -0
- package/react/query-preloader/createQueryPreloader.js.map +1 -0
- package/react/react.cjs +248 -1
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +248 -1
- package/react/types/types.d.ts +6 -0
- package/react/types/types.js.map +1 -1
- package/testing/internal/index.d.ts +4 -0
- package/testing/internal/index.js +2 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +12 -0
- package/testing/internal/renderHelpers.js +22 -0
- package/testing/internal/renderHelpers.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +41 -0
- package/testing/internal/scenarios/index.js +46 -0
- package/testing/internal/scenarios/index.js.map +1 -0
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toBeDisposed.d.ts +3 -0
- package/testing/matchers/toBeDisposed.js +26 -0
- package/testing/matchers/toBeDisposed.js.map +1 -0
- package/utilities/caching/caches.d.ts +34 -0
- package/utilities/caching/caches.js +64 -0
- package/utilities/caching/caches.js.map +1 -0
- package/utilities/caching/getMemoryInternals.d.ts +76 -0
- package/utilities/caching/getMemoryInternals.js +112 -0
- package/utilities/caching/getMemoryInternals.js.map +1 -0
- package/utilities/caching/index.d.ts +4 -0
- package/utilities/caching/index.js +3 -0
- package/utilities/caching/index.js.map +1 -0
- package/utilities/caching/sizes.d.ts +261 -0
- package/utilities/caching/sizes.js +27 -0
- package/utilities/caching/sizes.js.map +1 -0
- package/utilities/common/canUse.js +1 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.js +8 -2
- package/utilities/common/canonicalStringify.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +14 -1
- package/utilities/graphql/DocumentTransform.js +9 -5
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/print.js +6 -2
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/index.d.ts +2 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +57 -9
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +57 -9
- package/version.js +1 -1
package/react/types/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/react/types/types.ts"],"names":[],"mappings":"","sourcesContent":["import type * as ReactTypes from \"react\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nimport type {\n Observable,\n ObservableSubscription,\n} from \"../../utilities/index.js\";\nimport type { FetchResult } from \"../../link/core/index.js\";\nimport type { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n FetchPolicy,\n MutationOptions,\n NetworkStatus,\n ObservableQuery,\n OperationVariables,\n InternalRefetchQueriesInclude,\n WatchQueryOptions,\n WatchQueryFetchPolicy,\n ErrorPolicy,\n RefetchWritePolicy,\n} from \"../../core/index.js\";\n\n/* QueryReference type */\n\nexport type { QueryReference } from \"../cache/QueryReference.js\";\n\n/* Common types */\n\nexport type { DefaultContext as Context } from \"../../core/index.js\";\n\nexport type CommonOptions<TOptions> = TOptions & {\n client?: ApolloClient<object>;\n};\n\n/* Query types */\n\nexport interface BaseQueryOptions<\n TVariables extends OperationVariables = OperationVariables,\n> extends Omit<WatchQueryOptions<TVariables>, \"query\"> {\n ssr?: boolean;\n client?: ApolloClient<any>;\n context?: DefaultContext;\n}\n\nexport interface QueryFunctionOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseQueryOptions<TVariables> {\n skip?: boolean;\n onCompleted?: (data: TData) => void;\n onError?: (error: ApolloError) => void;\n\n // Default WatchQueryOptions for this useQuery, providing initial values for\n // unspecified options, superseding client.defaultOptions.watchQuery (option\n // by option, not whole), but never overriding options previously passed to\n // useQuery (or options added/modified later by other means).\n // TODO What about about default values that are expensive to evaluate?\n defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;\n}\n\nexport type ObservableQueryFields<\n TData,\n TVariables extends OperationVariables,\n> = Pick<\n ObservableQuery<TData, TVariables>,\n | \"startPolling\"\n | \"stopPolling\"\n | \"subscribeToMore\"\n | \"updateQuery\"\n | \"refetch\"\n | \"reobserve\"\n | \"variables\"\n | \"fetchMore\"\n>;\n\nexport interface QueryResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends ObservableQueryFields<TData, TVariables> {\n client: ApolloClient<any>;\n observable: ObservableQuery<TData, TVariables>;\n data: TData | undefined;\n previousData?: TData;\n error?: ApolloError;\n loading: boolean;\n networkStatus: NetworkStatus;\n called: boolean;\n}\n\nexport interface QueryDataOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends QueryFunctionOptions<TData, TVariables> {\n children?: (result: QueryResult<TData, TVariables>) => ReactTypes.ReactNode;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport interface QueryHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends QueryFunctionOptions<TData, TVariables> {}\n\nexport interface LazyQueryHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends Omit<QueryHookOptions<TData, TVariables>, \"skip\"> {}\n\nexport interface LazyQueryHookExecOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends LazyQueryHookOptions<TData, TVariables> {\n query?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport type SuspenseQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface SuspenseQueryHookOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> extends Pick<\n QueryHookOptions<TData, TVariables>,\n | \"client\"\n | \"variables\"\n | \"errorPolicy\"\n | \"context\"\n | \"canonizeResults\"\n | \"returnPartialData\"\n | \"refetchWritePolicy\"\n > {\n fetchPolicy?: SuspenseQueryHookFetchPolicy;\n queryKey?: string | number | any[];\n\n /**\n * If `true`, the query is not executed. The default value is `false`.\n *\n * @deprecated We recommend using `skipToken` in place of the `skip` option as\n * it is more type-safe.\n *\n * @example Recommended usage of `skipToken`:\n * ```ts\n * import { skipToken, useSuspenseQuery } from '@apollo/client';\n *\n * const { data } = useSuspenseQuery(query, id ? { variables: { id } } : skipToken);\n * ```\n */\n skip?: boolean;\n}\n\nexport type BackgroundQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface BackgroundQueryHookOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> extends Pick<\n QueryHookOptions<TData, TVariables>,\n | \"client\"\n | \"variables\"\n | \"errorPolicy\"\n | \"context\"\n | \"canonizeResults\"\n | \"returnPartialData\"\n | \"refetchWritePolicy\"\n > {\n fetchPolicy?: BackgroundQueryHookFetchPolicy;\n queryKey?: string | number | any[];\n\n /**\n * If `true`, the query is not executed. The default value is `false`.\n *\n * @deprecated We recommend using `skipToken` in place of the `skip` option as\n * it is more type-safe.\n *\n * @example Recommended usage of `skipToken`:\n * ```ts\n * import { skipToken, useBackgroundQuery } from '@apollo/client';\n *\n * const [queryRef] = useBackgroundQuery(query, id ? { variables: { id } } : skipToken);\n * ```\n */\n skip?: boolean;\n}\n\nexport type LoadableQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface LoadableQueryHookOptions {\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n /**\n * The instance of {@link ApolloClient} to use to execute the query.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n */\n client?: ApolloClient<any>;\n /**\n * Context to be passed to link execution chain\n */\n context?: DefaultContext;\n /**\n * Specifies the {@link ErrorPolicy} to be used for this query\n */\n errorPolicy?: ErrorPolicy;\n /**\n *\n * Specifies how the query interacts with the Apollo Client cache during\n * execution (for example, whether it checks the cache for results before\n * sending a request to the server).\n *\n * For details, see {@link https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy | Setting a fetch policy}.\n *\n * The default value is `cache-first`.\n */\n fetchPolicy?: LoadableQueryHookFetchPolicy;\n /**\n * A unique identifier for the query. Each item in the array must be a stable\n * identifier to prevent infinite fetches.\n *\n * This is useful when using the same query and variables combination in more\n * than one component, otherwise the components may clobber each other. This\n * can also be used to force the query to re-evaluate fresh.\n */\n queryKey?: string | number | any[];\n /**\n * Specifies whether a {@link NetworkStatus.refetch} operation should merge\n * incoming field data with existing data, or overwrite the existing data.\n * Overwriting is probably preferable, but merging is currently the default\n * behavior, for backwards compatibility with Apollo Client 3.x.\n */\n refetchWritePolicy?: RefetchWritePolicy;\n /**\n * Allow returning incomplete data from the cache when a larger query cannot\n * be fully satisfied by the cache, instead of returning nothing.\n */\n returnPartialData?: boolean;\n}\n\n/**\n * @deprecated TODO Delete this unused interface.\n */\nexport interface QueryLazyOptions<TVariables> {\n variables?: TVariables;\n context?: DefaultContext;\n}\n\n/**\n * @deprecated TODO Delete this unused type alias.\n */\nexport type LazyQueryResult<\n TData,\n TVariables extends OperationVariables,\n> = QueryResult<TData, TVariables>;\n\n/**\n * @deprecated TODO Delete this unused type alias.\n */\nexport type QueryTuple<\n TData,\n TVariables extends OperationVariables,\n> = LazyQueryResultTuple<TData, TVariables>;\n\nexport type LazyQueryExecFunction<\n TData,\n TVariables extends OperationVariables,\n> = (\n options?: Partial<LazyQueryHookExecOptions<TData, TVariables>>\n) => Promise<QueryResult<TData, TVariables>>;\n\nexport type LazyQueryResultTuple<\n TData,\n TVariables extends OperationVariables,\n> = [LazyQueryExecFunction<TData, TVariables>, QueryResult<TData, TVariables>];\n\n/* Mutation types */\n\nexport type RefetchQueriesFunction = (\n ...args: any[]\n) => InternalRefetchQueriesInclude;\n\nexport interface BaseMutationOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends Omit<\n MutationOptions<TData, TVariables, TContext, TCache>,\n \"mutation\"\n > {\n client?: ApolloClient<object>;\n notifyOnNetworkStatusChange?: boolean;\n onCompleted?: (data: TData, clientOptions?: BaseMutationOptions) => void;\n onError?: (error: ApolloError, clientOptions?: BaseMutationOptions) => void;\n ignoreResults?: boolean;\n}\n\nexport interface MutationFunctionOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {\n mutation?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport interface MutationResult<TData = any> {\n data?: TData | null;\n error?: ApolloError;\n loading: boolean;\n called: boolean;\n client: ApolloClient<object>;\n reset(): void;\n}\n\nexport declare type MutationFunction<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> = (\n options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>\n) => Promise<FetchResult<TData>>;\n\nexport interface MutationHookOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {}\n\nexport interface MutationDataOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport type MutationTuple<\n TData,\n TVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> = [\n (\n options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>\n // TODO This FetchResult<TData> seems strange here, as opposed to an\n // ApolloQueryResult<TData>\n ) => Promise<FetchResult<TData>>,\n MutationResult<TData>,\n];\n\n/* Subscription types */\n\nexport interface OnDataOptions<TData = any> {\n client: ApolloClient<object>;\n data: SubscriptionResult<TData>;\n}\n\nexport interface OnSubscriptionDataOptions<TData = any> {\n client: ApolloClient<object>;\n subscriptionData: SubscriptionResult<TData>;\n}\n\nexport interface BaseSubscriptionOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> {\n variables?: TVariables;\n fetchPolicy?: FetchPolicy;\n shouldResubscribe?:\n | boolean\n | ((options: BaseSubscriptionOptions<TData, TVariables>) => boolean);\n client?: ApolloClient<object>;\n skip?: boolean;\n context?: DefaultContext;\n onComplete?: () => void;\n onData?: (options: OnDataOptions<TData>) => any;\n /**\n * @deprecated Use onData instead\n */\n onSubscriptionData?: (options: OnSubscriptionDataOptions<TData>) => any;\n onError?: (error: ApolloError) => void;\n /**\n * @deprecated Use onComplete instead\n */\n onSubscriptionComplete?: () => void;\n}\n\nexport interface SubscriptionResult<TData = any, TVariables = any> {\n loading: boolean;\n data?: TData;\n error?: ApolloError;\n // This was added by the legacy useSubscription type, and is tested in unit\n // tests, but probably shouldn’t be added to the result.\n variables?: TVariables;\n}\n\nexport interface SubscriptionHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseSubscriptionOptions<TData, TVariables> {}\n\nexport interface SubscriptionDataOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseSubscriptionOptions<TData, TVariables> {\n subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;\n children?: null | ((result: SubscriptionResult<TData>) => JSX.Element | null);\n}\n\nexport interface SubscriptionCurrentObservable {\n query?: Observable<any>;\n subscription?: ObservableSubscription;\n}\n\n/**\nHelper type that allows using a type in a way that cannot be \"widened\" by inference on the value it is used on.\n\nThis type was first suggested [in this Github discussion](https://github.com/microsoft/TypeScript/issues/14829#issuecomment-504042546).\n\nExample usage:\n```ts\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> = Object.create(null),\n)\n```\nIn this case, `TData` and `TVariables` should be inferred from `query`, but never widened from something in `options`.\n\nSo, in this code example:\n```ts\ndeclare const typedNode: TypedDocumentNode<{ foo: string}, { bar: number }>\nconst { variables } = useQuery(typedNode, { variables: { bar: 4, nonExistingVariable: \"string\" } });\n```\nWithout the use of `NoInfer`, `variables` would now be of the type `{ bar: number, nonExistingVariable: \"string\" }`.\nWith `NoInfer`, it will instead give an error on `nonExistingVariable`.\n */\nexport type NoInfer<T> = [T][T extends any ? 0 : never];\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/react/types/types.ts"],"names":[],"mappings":"","sourcesContent":["import type * as ReactTypes from \"react\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nimport type {\n Observable,\n ObservableSubscription,\n} from \"../../utilities/index.js\";\nimport type { FetchResult } from \"../../link/core/index.js\";\nimport type { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n FetchPolicy,\n MutationOptions,\n NetworkStatus,\n ObservableQuery,\n OperationVariables,\n InternalRefetchQueriesInclude,\n WatchQueryOptions,\n WatchQueryFetchPolicy,\n ErrorPolicy,\n RefetchWritePolicy,\n} from \"../../core/index.js\";\n\n/* QueryReference type */\n\nexport type { QueryReference } from \"../cache/QueryReference.js\";\n\n/* Common types */\n\nexport type { DefaultContext as Context } from \"../../core/index.js\";\n\nexport type CommonOptions<TOptions> = TOptions & {\n client?: ApolloClient<object>;\n};\n\n/* Query types */\n\nexport interface BaseQueryOptions<\n TVariables extends OperationVariables = OperationVariables,\n> extends Omit<WatchQueryOptions<TVariables>, \"query\"> {\n ssr?: boolean;\n client?: ApolloClient<any>;\n context?: DefaultContext;\n}\n\nexport interface QueryFunctionOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseQueryOptions<TVariables> {\n skip?: boolean;\n onCompleted?: (data: TData) => void;\n onError?: (error: ApolloError) => void;\n\n // Default WatchQueryOptions for this useQuery, providing initial values for\n // unspecified options, superseding client.defaultOptions.watchQuery (option\n // by option, not whole), but never overriding options previously passed to\n // useQuery (or options added/modified later by other means).\n // TODO What about about default values that are expensive to evaluate?\n defaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>;\n}\n\nexport type ObservableQueryFields<\n TData,\n TVariables extends OperationVariables,\n> = Pick<\n ObservableQuery<TData, TVariables>,\n | \"startPolling\"\n | \"stopPolling\"\n | \"subscribeToMore\"\n | \"updateQuery\"\n | \"refetch\"\n | \"reobserve\"\n | \"variables\"\n | \"fetchMore\"\n>;\n\nexport interface QueryResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends ObservableQueryFields<TData, TVariables> {\n client: ApolloClient<any>;\n observable: ObservableQuery<TData, TVariables>;\n data: TData | undefined;\n previousData?: TData;\n error?: ApolloError;\n loading: boolean;\n networkStatus: NetworkStatus;\n called: boolean;\n}\n\nexport interface QueryDataOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends QueryFunctionOptions<TData, TVariables> {\n children?: (result: QueryResult<TData, TVariables>) => ReactTypes.ReactNode;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport interface QueryHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends QueryFunctionOptions<TData, TVariables> {}\n\nexport interface LazyQueryHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends Omit<QueryHookOptions<TData, TVariables>, \"skip\"> {}\n\nexport interface LazyQueryHookExecOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends LazyQueryHookOptions<TData, TVariables> {\n query?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport type SuspenseQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface SuspenseQueryHookOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> extends Pick<\n QueryHookOptions<TData, TVariables>,\n | \"client\"\n | \"variables\"\n | \"errorPolicy\"\n | \"context\"\n | \"canonizeResults\"\n | \"returnPartialData\"\n | \"refetchWritePolicy\"\n > {\n fetchPolicy?: SuspenseQueryHookFetchPolicy;\n queryKey?: string | number | any[];\n\n /**\n * If `true`, the query is not executed. The default value is `false`.\n *\n * @deprecated We recommend using `skipToken` in place of the `skip` option as\n * it is more type-safe.\n *\n * @example Recommended usage of `skipToken`:\n * ```ts\n * import { skipToken, useSuspenseQuery } from '@apollo/client';\n *\n * const { data } = useSuspenseQuery(query, id ? { variables: { id } } : skipToken);\n * ```\n */\n skip?: boolean;\n}\n\nexport type BackgroundQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface BackgroundQueryHookOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> extends Pick<\n QueryHookOptions<TData, TVariables>,\n | \"client\"\n | \"variables\"\n | \"errorPolicy\"\n | \"context\"\n | \"canonizeResults\"\n | \"returnPartialData\"\n | \"refetchWritePolicy\"\n > {\n fetchPolicy?: BackgroundQueryHookFetchPolicy;\n queryKey?: string | number | any[];\n\n /**\n * If `true`, the query is not executed. The default value is `false`.\n *\n * @deprecated We recommend using `skipToken` in place of the `skip` option as\n * it is more type-safe.\n *\n * @example Recommended usage of `skipToken`:\n * ```ts\n * import { skipToken, useBackgroundQuery } from '@apollo/client';\n *\n * const [queryRef] = useBackgroundQuery(query, id ? { variables: { id } } : skipToken);\n * ```\n */\n skip?: boolean;\n}\n\nexport type LoadableQueryHookFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport interface LoadableQueryHookOptions {\n /**\n * @deprecated\n * Using `canonizeResults` can result in memory leaks so we generally do not\n * recommend using this option anymore.\n * A future version of Apollo Client will contain a similar feature without\n * the risk of memory leaks.\n *\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n /**\n * The instance of {@link ApolloClient} to use to execute the query.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n */\n client?: ApolloClient<any>;\n /**\n * Context to be passed to link execution chain\n */\n context?: DefaultContext;\n /**\n * Specifies the {@link ErrorPolicy} to be used for this query\n */\n errorPolicy?: ErrorPolicy;\n /**\n *\n * Specifies how the query interacts with the Apollo Client cache during\n * execution (for example, whether it checks the cache for results before\n * sending a request to the server).\n *\n * For details, see {@link https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy | Setting a fetch policy}.\n *\n * The default value is `cache-first`.\n */\n fetchPolicy?: LoadableQueryHookFetchPolicy;\n /**\n * A unique identifier for the query. Each item in the array must be a stable\n * identifier to prevent infinite fetches.\n *\n * This is useful when using the same query and variables combination in more\n * than one component, otherwise the components may clobber each other. This\n * can also be used to force the query to re-evaluate fresh.\n */\n queryKey?: string | number | any[];\n /**\n * Specifies whether a {@link NetworkStatus.refetch} operation should merge\n * incoming field data with existing data, or overwrite the existing data.\n * Overwriting is probably preferable, but merging is currently the default\n * behavior, for backwards compatibility with Apollo Client 3.x.\n */\n refetchWritePolicy?: RefetchWritePolicy;\n /**\n * Allow returning incomplete data from the cache when a larger query cannot\n * be fully satisfied by the cache, instead of returning nothing.\n */\n returnPartialData?: boolean;\n}\n\n/**\n * @deprecated TODO Delete this unused interface.\n */\nexport interface QueryLazyOptions<TVariables> {\n variables?: TVariables;\n context?: DefaultContext;\n}\n\n/**\n * @deprecated TODO Delete this unused type alias.\n */\nexport type LazyQueryResult<\n TData,\n TVariables extends OperationVariables,\n> = QueryResult<TData, TVariables>;\n\n/**\n * @deprecated TODO Delete this unused type alias.\n */\nexport type QueryTuple<\n TData,\n TVariables extends OperationVariables,\n> = LazyQueryResultTuple<TData, TVariables>;\n\nexport type LazyQueryExecFunction<\n TData,\n TVariables extends OperationVariables,\n> = (\n options?: Partial<LazyQueryHookExecOptions<TData, TVariables>>\n) => Promise<QueryResult<TData, TVariables>>;\n\nexport type LazyQueryResultTuple<\n TData,\n TVariables extends OperationVariables,\n> = [LazyQueryExecFunction<TData, TVariables>, QueryResult<TData, TVariables>];\n\n/* Mutation types */\n\nexport type RefetchQueriesFunction = (\n ...args: any[]\n) => InternalRefetchQueriesInclude;\n\nexport interface BaseMutationOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends Omit<\n MutationOptions<TData, TVariables, TContext, TCache>,\n \"mutation\"\n > {\n client?: ApolloClient<object>;\n notifyOnNetworkStatusChange?: boolean;\n onCompleted?: (data: TData, clientOptions?: BaseMutationOptions) => void;\n onError?: (error: ApolloError, clientOptions?: BaseMutationOptions) => void;\n ignoreResults?: boolean;\n}\n\nexport interface MutationFunctionOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {\n mutation?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport interface MutationResult<TData = any> {\n data?: TData | null;\n error?: ApolloError;\n loading: boolean;\n called: boolean;\n client: ApolloClient<object>;\n reset(): void;\n}\n\nexport declare type MutationFunction<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> = (\n options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>\n) => Promise<FetchResult<TData>>;\n\nexport interface MutationHookOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {}\n\nexport interface MutationDataOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport type MutationTuple<\n TData,\n TVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> = [\n (\n options?: MutationFunctionOptions<TData, TVariables, TContext, TCache>\n // TODO This FetchResult<TData> seems strange here, as opposed to an\n // ApolloQueryResult<TData>\n ) => Promise<FetchResult<TData>>,\n MutationResult<TData>,\n];\n\n/* Subscription types */\n\nexport interface OnDataOptions<TData = any> {\n client: ApolloClient<object>;\n data: SubscriptionResult<TData>;\n}\n\nexport interface OnSubscriptionDataOptions<TData = any> {\n client: ApolloClient<object>;\n subscriptionData: SubscriptionResult<TData>;\n}\n\nexport interface BaseSubscriptionOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> {\n variables?: TVariables;\n fetchPolicy?: FetchPolicy;\n shouldResubscribe?:\n | boolean\n | ((options: BaseSubscriptionOptions<TData, TVariables>) => boolean);\n client?: ApolloClient<object>;\n skip?: boolean;\n context?: DefaultContext;\n onComplete?: () => void;\n onData?: (options: OnDataOptions<TData>) => any;\n /**\n * @deprecated Use onData instead\n */\n onSubscriptionData?: (options: OnSubscriptionDataOptions<TData>) => any;\n onError?: (error: ApolloError) => void;\n /**\n * @deprecated Use onComplete instead\n */\n onSubscriptionComplete?: () => void;\n}\n\nexport interface SubscriptionResult<TData = any, TVariables = any> {\n loading: boolean;\n data?: TData;\n error?: ApolloError;\n // This was added by the legacy useSubscription type, and is tested in unit\n // tests, but probably shouldn’t be added to the result.\n variables?: TVariables;\n}\n\nexport interface SubscriptionHookOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseSubscriptionOptions<TData, TVariables> {}\n\nexport interface SubscriptionDataOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseSubscriptionOptions<TData, TVariables> {\n subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;\n children?: null | ((result: SubscriptionResult<TData>) => JSX.Element | null);\n}\n\nexport interface SubscriptionCurrentObservable {\n query?: Observable<any>;\n subscription?: ObservableSubscription;\n}\n\n/**\nHelper type that allows using a type in a way that cannot be \"widened\" by inference on the value it is used on.\n\nThis type was first suggested [in this Github discussion](https://github.com/microsoft/TypeScript/issues/14829#issuecomment-504042546).\n\nExample usage:\n```ts\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> = Object.create(null),\n)\n```\nIn this case, `TData` and `TVariables` should be inferred from `query`, but never widened from something in `options`.\n\nSo, in this code example:\n```ts\ndeclare const typedNode: TypedDocumentNode<{ foo: string}, { bar: number }>\nconst { variables } = useQuery(typedNode, { variables: { bar: 4, nonExistingVariable: \"string\" } });\n```\nWithout the use of `NoInfer`, `variables` would now be of the type `{ bar: number, nonExistingVariable: \"string\" }`.\nWith `NoInfer`, it will instead give an error on `nonExistingVariable`.\n */\nexport type NoInfer<T> = [T][T extends any ? 0 : never];\n"]}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from "./profile/index.js";
|
|
2
2
|
export * from "./disposables/index.js";
|
|
3
3
|
export { ObservableStream } from "./ObservableStream.js";
|
|
4
|
+
export type { SimpleCaseData, PaginatedCaseData, PaginatedCaseVariables, VariablesCaseData, VariablesCaseVariables, } from "./scenarios/index.js";
|
|
5
|
+
export { setupSimpleCase, setupVariablesCase, setupPaginatedCase, } from "./scenarios/index.js";
|
|
6
|
+
export type { RenderWithClientOptions, RenderWithMocksOptions, } from "./renderHelpers.js";
|
|
7
|
+
export { renderWithClient, renderWithMocks } from "./renderHelpers.js";
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from "./profile/index.js";
|
|
2
2
|
export * from "./disposables/index.js";
|
|
3
3
|
export { ObservableStream } from "./ObservableStream.js";
|
|
4
|
+
export { setupSimpleCase, setupVariablesCase, setupPaginatedCase, } from "./scenarios/index.js";
|
|
5
|
+
export { renderWithClient, renderWithMocks } from "./renderHelpers.js";
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export * from \"./profile/index.js\";\nexport * from \"./disposables/index.js\";\nexport { ObservableStream } from \"./ObservableStream.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export * from \"./profile/index.js\";\nexport * from \"./disposables/index.js\";\nexport { ObservableStream } from \"./ObservableStream.js\";\n\nexport type {\n SimpleCaseData,\n PaginatedCaseData,\n PaginatedCaseVariables,\n VariablesCaseData,\n VariablesCaseVariables,\n} from \"./scenarios/index.js\";\nexport {\n setupSimpleCase,\n setupVariablesCase,\n setupPaginatedCase,\n} from \"./scenarios/index.js\";\n\nexport type {\n RenderWithClientOptions,\n RenderWithMocksOptions,\n} from \"./renderHelpers.js\";\nexport { renderWithClient, renderWithMocks } from \"./renderHelpers.js\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Queries, RenderOptions, queries } from "@testing-library/react";
|
|
3
|
+
import type { ApolloClient } from "../../core/index.js";
|
|
4
|
+
import type { MockedProviderProps } from "../react/MockedProvider.js";
|
|
5
|
+
export interface RenderWithClientOptions<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container> extends RenderOptions<Q, Container, BaseElement> {
|
|
6
|
+
client: ApolloClient<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare function renderWithClient<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container>(ui: ReactElement, { client, wrapper: Wrapper, ...renderOptions }: RenderWithClientOptions<Q, Container, BaseElement>): import("@testing-library/react").RenderResult<Q, Container, BaseElement>;
|
|
9
|
+
export interface RenderWithMocksOptions<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container> extends RenderOptions<Q, Container, BaseElement>, MockedProviderProps<any> {
|
|
10
|
+
}
|
|
11
|
+
export declare function renderWithMocks<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container>(ui: ReactElement, { wrapper: Wrapper, ...renderOptions }: RenderWithMocksOptions<Q, Container, BaseElement>): import("@testing-library/react").RenderResult<Q, Container, BaseElement>;
|
|
12
|
+
//# sourceMappingURL=renderHelpers.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { ApolloProvider } from "../../react/index.js";
|
|
5
|
+
import { MockedProvider } from "../react/MockedProvider.js";
|
|
6
|
+
export function renderWithClient(ui, _a) {
|
|
7
|
+
var client = _a.client, _b = _a.wrapper, Wrapper = _b === void 0 ? React.Fragment : _b, renderOptions = __rest(_a, ["client", "wrapper"]);
|
|
8
|
+
return render(ui, __assign(__assign({}, renderOptions), { wrapper: function (_a) {
|
|
9
|
+
var children = _a.children;
|
|
10
|
+
return (React.createElement(ApolloProvider, { client: client },
|
|
11
|
+
React.createElement(Wrapper, null, children)));
|
|
12
|
+
} }));
|
|
13
|
+
}
|
|
14
|
+
export function renderWithMocks(ui, _a) {
|
|
15
|
+
var _b = _a.wrapper, Wrapper = _b === void 0 ? React.Fragment : _b, renderOptions = __rest(_a, ["wrapper"]);
|
|
16
|
+
return render(ui, __assign(__assign({}, renderOptions), { wrapper: function (_a) {
|
|
17
|
+
var children = _a.children;
|
|
18
|
+
return (React.createElement(MockedProvider, __assign({}, renderOptions),
|
|
19
|
+
React.createElement(Wrapper, null, children)));
|
|
20
|
+
} }));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=renderHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderHelpers.js","sourceRoot":"","sources":["../../../src/testing/internal/renderHelpers.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAU5D,MAAM,UAAU,gBAAgB,CAK9B,EAAgB,EAChB,EAIqD;IAHnD,IAAA,MAAM,YAAA,EACN,eAAiC,EAAxB,OAAO,mBAAG,KAAK,CAAC,QAAQ,KAAA,EAC9B,aAAa,cAHlB,qBAIC,CADiB;IAGlB,OAAO,MAAM,CAAC,EAAE,wBACX,aAAa,KAChB,OAAO,EAAE,UAAC,EAAY;gBAAV,QAAQ,cAAA;YAClB,OAAO,CACL,oBAAC,cAAc,IAAC,MAAM,EAAE,MAAM;gBAC5B,oBAAC,OAAO,QAAE,QAAQ,CAAW,CACd,CAClB,CAAC;QACJ,CAAC,IACD,CAAC;AACL,CAAC;AASD,MAAM,UAAU,eAAe,CAK7B,EAAgB,EAChB,EAGoD;IAFlD,IAAA,eAAiC,EAAxB,OAAO,mBAAG,KAAK,CAAC,QAAQ,KAAA,EAC9B,aAAa,cAFlB,WAGC,CADiB;IAGlB,OAAO,MAAM,CAAC,EAAE,wBACX,aAAa,KAChB,OAAO,EAAE,UAAC,EAAY;gBAAV,QAAQ,cAAA;YAClB,OAAO,CACL,oBAAC,cAAc,eAAK,aAAa;gBAC/B,oBAAC,OAAO,QAAE,QAAQ,CAAW,CACd,CAClB,CAAC;QACJ,CAAC,IACD,CAAC;AACL,CAAC","sourcesContent":["import * as React from \"react\";\nimport type { ReactElement } from \"react\";\nimport { render } from \"@testing-library/react\";\nimport type { Queries, RenderOptions, queries } from \"@testing-library/react\";\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { ApolloProvider } from \"../../react/index.js\";\nimport type { MockedProviderProps } from \"../react/MockedProvider.js\";\nimport { MockedProvider } from \"../react/MockedProvider.js\";\n\nexport interface RenderWithClientOptions<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n> extends RenderOptions<Q, Container, BaseElement> {\n client: ApolloClient<any>;\n}\n\nexport function renderWithClient<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n>(\n ui: ReactElement,\n {\n client,\n wrapper: Wrapper = React.Fragment,\n ...renderOptions\n }: RenderWithClientOptions<Q, Container, BaseElement>\n) {\n return render(ui, {\n ...renderOptions,\n wrapper: ({ children }) => {\n return (\n <ApolloProvider client={client}>\n <Wrapper>{children}</Wrapper>\n </ApolloProvider>\n );\n },\n });\n}\n\nexport interface RenderWithMocksOptions<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n> extends RenderOptions<Q, Container, BaseElement>,\n MockedProviderProps<any> {}\n\nexport function renderWithMocks<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n>(\n ui: ReactElement,\n {\n wrapper: Wrapper = React.Fragment,\n ...renderOptions\n }: RenderWithMocksOptions<Q, Container, BaseElement>\n) {\n return render(ui, {\n ...renderOptions,\n wrapper: ({ children }) => {\n return (\n <MockedProvider {...renderOptions}>\n <Wrapper>{children}</Wrapper>\n </MockedProvider>\n );\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApolloLink } from "../../../core/index.js";
|
|
2
|
+
import type { TypedDocumentNode } from "../../../core/index.js";
|
|
3
|
+
import type { MockedResponse } from "../../core/index.js";
|
|
4
|
+
export interface SimpleCaseData {
|
|
5
|
+
greeting: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function setupSimpleCase(): {
|
|
8
|
+
query: TypedDocumentNode<SimpleCaseData, Record<string, never>>;
|
|
9
|
+
mocks: MockedResponse<SimpleCaseData, Record<string, any>>[];
|
|
10
|
+
};
|
|
11
|
+
export interface VariablesCaseData {
|
|
12
|
+
character: {
|
|
13
|
+
__typename: "Character";
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface VariablesCaseVariables {
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function setupVariablesCase(): {
|
|
22
|
+
mocks: MockedResponse<VariablesCaseData, Record<string, any>>[];
|
|
23
|
+
query: TypedDocumentNode<VariablesCaseData, VariablesCaseVariables>;
|
|
24
|
+
};
|
|
25
|
+
interface Letter {
|
|
26
|
+
letter: string;
|
|
27
|
+
position: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PaginatedCaseData {
|
|
30
|
+
letters: Letter[];
|
|
31
|
+
}
|
|
32
|
+
export interface PaginatedCaseVariables {
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function setupPaginatedCase(): {
|
|
37
|
+
query: TypedDocumentNode<PaginatedCaseData, PaginatedCaseVariables>;
|
|
38
|
+
link: ApolloLink;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { __makeTemplateObject, __spreadArray } from "tslib";
|
|
2
|
+
import { ApolloLink, Observable, gql } from "../../../core/index.js";
|
|
3
|
+
export function setupSimpleCase() {
|
|
4
|
+
var query = gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query GreetingQuery {\n greeting\n }\n "], ["\n query GreetingQuery {\n greeting\n }\n "])));
|
|
5
|
+
var mocks = [
|
|
6
|
+
{
|
|
7
|
+
request: { query: query },
|
|
8
|
+
result: { data: { greeting: "Hello" } },
|
|
9
|
+
delay: 10,
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
return { query: query, mocks: mocks };
|
|
13
|
+
}
|
|
14
|
+
export function setupVariablesCase() {
|
|
15
|
+
var query = gql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n name\n }\n }\n "], ["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n name\n }\n }\n "])));
|
|
16
|
+
var CHARACTERS = ["Spider-Man", "Black Widow", "Iron Man", "Hulk"];
|
|
17
|
+
var mocks = __spreadArray([], CHARACTERS, true).map(function (name, index) { return ({
|
|
18
|
+
request: { query: query, variables: { id: String(index + 1) } },
|
|
19
|
+
result: {
|
|
20
|
+
data: {
|
|
21
|
+
character: { __typename: "Character", id: String(index + 1), name: name },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
delay: 20,
|
|
25
|
+
}); });
|
|
26
|
+
return { mocks: mocks, query: query };
|
|
27
|
+
}
|
|
28
|
+
export function setupPaginatedCase() {
|
|
29
|
+
var query = gql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n query letters($limit: Int, $offset: Int) {\n letters(limit: $limit) {\n letter\n position\n }\n }\n "], ["\n query letters($limit: Int, $offset: Int) {\n letters(limit: $limit) {\n letter\n position\n }\n }\n "])));
|
|
30
|
+
var data = "ABCDEFGHIJKLMNOPQRSTUV"
|
|
31
|
+
.split("")
|
|
32
|
+
.map(function (letter, index) { return ({ letter: letter, position: index + 1 }); });
|
|
33
|
+
var link = new ApolloLink(function (operation) {
|
|
34
|
+
var _a = operation.variables, _b = _a.offset, offset = _b === void 0 ? 0 : _b, _c = _a.limit, limit = _c === void 0 ? 2 : _c;
|
|
35
|
+
var letters = data.slice(offset, offset + limit);
|
|
36
|
+
return new Observable(function (observer) {
|
|
37
|
+
setTimeout(function () {
|
|
38
|
+
observer.next({ data: { letters: letters } });
|
|
39
|
+
observer.complete();
|
|
40
|
+
}, 10);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return { query: query, link: link };
|
|
44
|
+
}
|
|
45
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/internal/scenarios/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAQrE,MAAM,UAAU,eAAe;IAC7B,IAAM,KAAK,GAA6D,GAAG,2HAAA,wDAI1E,IAAA,CAAC;IAEF,IAAM,KAAK,GAAqC;QAC9C;YACE,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE;YAClB,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;YACvC,KAAK,EAAE,EAAE;SACV;KACF,CAAC;IAEF,OAAO,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,CAAC;AAC1B,CAAC;AAcD,MAAM,UAAU,kBAAkB;IAChC,IAAM,KAAK,GACT,GAAG,mMAAA,gIAOF,IAAA,CAAC;IACJ,IAAM,UAAU,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAErE,IAAM,KAAK,GAAwC,kBAAI,UAAU,QAAE,GAAG,CACpE,UAAC,IAAI,EAAE,KAAK,IAAK,OAAA,CAAC;QAChB,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,EAAE;QACxD,MAAM,EAAE;YACN,IAAI,EAAE;gBACJ,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,MAAA,EAAE;aACpE;SACF;QACD,KAAK,EAAE,EAAE;KACV,CAAC,EARe,CAQf,CACH,CAAC;IAEF,OAAO,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,CAAC;AAC1B,CAAC;AAgBD,MAAM,UAAU,kBAAkB;IAChC,IAAM,KAAK,GACT,GAAG,yNAAA,sJAOF,IAAA,CAAC;IAEJ,IAAM,IAAI,GAAG,wBAAwB;SAClC,KAAK,CAAC,EAAE,CAAC;SACT,GAAG,CAAC,UAAC,MAAM,EAAE,KAAK,IAAK,OAAA,CAAC,EAAE,MAAM,QAAA,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,EAAjC,CAAiC,CAAC,CAAC;IAE7D,IAAM,IAAI,GAAG,IAAI,UAAU,CAAC,UAAC,SAAS;QAC9B,IAAA,KAA4B,SAAS,CAAC,SAAS,EAA7C,cAAU,EAAV,MAAM,mBAAG,CAAC,KAAA,EAAE,aAAS,EAAT,KAAK,mBAAG,CAAC,KAAwB,CAAC;QACtD,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;QAEnD,OAAO,IAAI,UAAU,CAAC,UAAC,QAAQ;YAC7B,UAAU,CAAC;gBACT,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,SAAA,EAAE,EAAE,CAAC,CAAC;gBACrC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACtB,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { ApolloLink, Observable, gql } from \"../../../core/index.js\";\nimport type { TypedDocumentNode } from \"../../../core/index.js\";\nimport type { MockedResponse } from \"../../core/index.js\";\n\nexport interface SimpleCaseData {\n greeting: string;\n}\n\nexport function setupSimpleCase() {\n const query: TypedDocumentNode<SimpleCaseData, Record<string, never>> = gql`\n query GreetingQuery {\n greeting\n }\n `;\n\n const mocks: MockedResponse<SimpleCaseData>[] = [\n {\n request: { query },\n result: { data: { greeting: \"Hello\" } },\n delay: 10,\n },\n ];\n\n return { query, mocks };\n}\n\nexport interface VariablesCaseData {\n character: {\n __typename: \"Character\";\n id: string;\n name: string;\n };\n}\n\nexport interface VariablesCaseVariables {\n id: string;\n}\n\nexport function setupVariablesCase() {\n const query: TypedDocumentNode<VariablesCaseData, VariablesCaseVariables> =\n gql`\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n name\n }\n }\n `;\n const CHARACTERS = [\"Spider-Man\", \"Black Widow\", \"Iron Man\", \"Hulk\"];\n\n const mocks: MockedResponse<VariablesCaseData>[] = [...CHARACTERS].map(\n (name, index) => ({\n request: { query, variables: { id: String(index + 1) } },\n result: {\n data: {\n character: { __typename: \"Character\", id: String(index + 1), name },\n },\n },\n delay: 20,\n })\n );\n\n return { mocks, query };\n}\n\ninterface Letter {\n letter: string;\n position: number;\n}\n\nexport interface PaginatedCaseData {\n letters: Letter[];\n}\n\nexport interface PaginatedCaseVariables {\n limit?: number;\n offset?: number;\n}\n\nexport function setupPaginatedCase() {\n const query: TypedDocumentNode<PaginatedCaseData, PaginatedCaseVariables> =\n gql`\n query letters($limit: Int, $offset: Int) {\n letters(limit: $limit) {\n letter\n position\n }\n }\n `;\n\n const data = \"ABCDEFGHIJKLMNOPQRSTUV\"\n .split(\"\")\n .map((letter, index) => ({ letter, position: index + 1 }));\n\n const link = new ApolloLink((operation) => {\n const { offset = 0, limit = 2 } = operation.variables;\n const letters = data.slice(offset, offset + limit);\n\n return new Observable((observer) => {\n setTimeout(() => {\n observer.next({ data: { letters } });\n observer.complete();\n }, 10);\n });\n });\n\n return { query, link };\n}\n"]}
|
|
@@ -3,7 +3,9 @@ import { toMatchDocument } from "./toMatchDocument.js";
|
|
|
3
3
|
import { toHaveSuspenseCacheEntryUsing } from "./toHaveSuspenseCacheEntryUsing.js";
|
|
4
4
|
import { toRerender, toRenderExactlyTimes } from "./ProfiledComponent.js";
|
|
5
5
|
import { toBeGarbageCollected } from "./toBeGarbageCollected.js";
|
|
6
|
+
import { toBeDisposed } from "./toBeDisposed.js";
|
|
6
7
|
expect.extend({
|
|
8
|
+
toBeDisposed: toBeDisposed,
|
|
7
9
|
toHaveSuspenseCacheEntryUsing: toHaveSuspenseCacheEntryUsing,
|
|
8
10
|
toMatchDocument: toMatchDocument,
|
|
9
11
|
toRerender: toRerender,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,CAAC;IACZ,YAAY,cAAA;IACZ,6BAA6B,+BAAA;IAC7B,eAAe,iBAAA;IACf,UAAU,YAAA;IACV,oBAAoB,sBAAA;IACpB,oBAAoB,sBAAA;CACrB,CAAC,CAAC","sourcesContent":["import { expect } from \"@jest/globals\";\nimport { toMatchDocument } from \"./toMatchDocument.js\";\nimport { toHaveSuspenseCacheEntryUsing } from \"./toHaveSuspenseCacheEntryUsing.js\";\nimport { toRerender, toRenderExactlyTimes } from \"./ProfiledComponent.js\";\nimport { toBeGarbageCollected } from \"./toBeGarbageCollected.js\";\nimport { toBeDisposed } from \"./toBeDisposed.js\";\n\nexpect.extend({\n toBeDisposed,\n toHaveSuspenseCacheEntryUsing,\n toMatchDocument,\n toRerender,\n toRenderExactlyTimes,\n toBeGarbageCollected,\n});\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { InternalQueryReference, unwrapQueryRef, } from "../../react/cache/QueryReference.js";
|
|
2
|
+
function isQueryRef(queryRef) {
|
|
3
|
+
try {
|
|
4
|
+
return unwrapQueryRef(queryRef) instanceof InternalQueryReference;
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export var toBeDisposed = function (queryRef) {
|
|
11
|
+
var _this = this;
|
|
12
|
+
var hint = this.utils.matcherHint("toBeDisposed", "queryRef", "", {
|
|
13
|
+
isNot: this.isNot,
|
|
14
|
+
});
|
|
15
|
+
if (!isQueryRef(queryRef)) {
|
|
16
|
+
throw new Error("\n".concat(hint, "\n\nmust be called with a valid QueryReference"));
|
|
17
|
+
}
|
|
18
|
+
var pass = unwrapQueryRef(queryRef).disposed;
|
|
19
|
+
return {
|
|
20
|
+
pass: pass,
|
|
21
|
+
message: function () {
|
|
22
|
+
return "".concat(hint, "\n\nExpected queryRef ").concat(_this.isNot ? "not " : "", "to be disposed, but it was").concat(_this.isNot ? "" : " not", ".");
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=toBeDisposed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeDisposed.js","sourceRoot":"","sources":["../../../src/testing/matchers/toBeDisposed.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAE7C,SAAS,UAAU,CAAC,QAAiB;IACnC,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,QAAe,CAAC,YAAY,sBAAsB,CAAC;IAC3E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,IAAM,YAAY,GAAwB,UAAU,QAAQ;IAAlB,iBAmBhD;IAlBC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE;QAClE,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;IAEH,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,YAAK,IAAI,mDAAgD,CAAC,CAAC;IAC7E,CAAC;IAED,IAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;IAE/C,OAAO;QACL,IAAI,MAAA;QACJ,OAAO,EAAE;YACP,OAAO,UAAG,IAAI,mCACZ,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,uCACG,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,MAAG,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport type { QueryReference } from \"../../react/cache/QueryReference.js\";\nimport {\n InternalQueryReference,\n unwrapQueryRef,\n} from \"../../react/cache/QueryReference.js\";\n\nfunction isQueryRef(queryRef: unknown): queryRef is QueryReference {\n try {\n return unwrapQueryRef(queryRef as any) instanceof InternalQueryReference;\n } catch (e) {\n return false;\n }\n}\n\nexport const toBeDisposed: MatcherFunction<[]> = function (queryRef) {\n const hint = this.utils.matcherHint(\"toBeDisposed\", \"queryRef\", \"\", {\n isNot: this.isNot,\n });\n\n if (!isQueryRef(queryRef)) {\n throw new Error(`\\n${hint}\\n\\nmust be called with a valid QueryReference`);\n }\n\n const pass = unwrapQueryRef(queryRef).disposed;\n\n return {\n pass,\n message: () => {\n return `${hint}\\n\\nExpected queryRef ${\n this.isNot ? \"not \" : \"\"\n }to be disposed, but it was${this.isNot ? \"\" : \" not\"}.`;\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { WeakCache, StrongCache } from "@wry/caches";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* A version of WeakCache that will auto-schedule a cleanup of the cache when
|
|
5
|
+
* a new item is added.
|
|
6
|
+
* Throttled to once per 100ms.
|
|
7
|
+
*
|
|
8
|
+
* @privateRemarks
|
|
9
|
+
* Should be used throughout the rest of the codebase instead of WeakCache,
|
|
10
|
+
* with the notable exception of usage in `wrap` from `optimism` - that one
|
|
11
|
+
* already handles cleanup and should remain a `WeakCache`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const AutoCleanedWeakCache: typeof WeakCache;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export type AutoCleanedWeakCache<K extends object, V> = WeakCache<K, V>;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
* A version of StrongCache that will auto-schedule a cleanup of the cache when
|
|
21
|
+
* a new item is added.
|
|
22
|
+
* Throttled to once per 100ms.
|
|
23
|
+
*
|
|
24
|
+
* @privateRemarks
|
|
25
|
+
* Should be used throughout the rest of the codebase instead of StrongCache,
|
|
26
|
+
* with the notable exception of usage in `wrap` from `optimism` - that one
|
|
27
|
+
* already handles cleanup and should remain a `StrongCache`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const AutoCleanedStrongCache: typeof StrongCache;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export type AutoCleanedStrongCache<K, V> = StrongCache<K, V>;
|
|
34
|
+
//# sourceMappingURL=caches.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { WeakCache, StrongCache } from "@wry/caches";
|
|
2
|
+
var scheduledCleanup = new WeakSet();
|
|
3
|
+
function schedule(cache) {
|
|
4
|
+
if (!scheduledCleanup.has(cache)) {
|
|
5
|
+
scheduledCleanup.add(cache);
|
|
6
|
+
setTimeout(function () {
|
|
7
|
+
cache.clean();
|
|
8
|
+
scheduledCleanup.delete(cache);
|
|
9
|
+
}, 100);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
* A version of WeakCache that will auto-schedule a cleanup of the cache when
|
|
15
|
+
* a new item is added.
|
|
16
|
+
* Throttled to once per 100ms.
|
|
17
|
+
*
|
|
18
|
+
* @privateRemarks
|
|
19
|
+
* Should be used throughout the rest of the codebase instead of WeakCache,
|
|
20
|
+
* with the notable exception of usage in `wrap` from `optimism` - that one
|
|
21
|
+
* already handles cleanup and should remain a `WeakCache`.
|
|
22
|
+
*/
|
|
23
|
+
export var AutoCleanedWeakCache = function (max, dispose) {
|
|
24
|
+
/*
|
|
25
|
+
Some builds of `WeakCache` are function prototypes, some are classes.
|
|
26
|
+
This library still builds with an ES5 target, so we can't extend the
|
|
27
|
+
real classes.
|
|
28
|
+
Instead, we have to use this workaround until we switch to a newer build
|
|
29
|
+
target.
|
|
30
|
+
*/
|
|
31
|
+
var cache = new WeakCache(max, dispose);
|
|
32
|
+
cache.set = function (key, value) {
|
|
33
|
+
schedule(this);
|
|
34
|
+
return WeakCache.prototype.set.call(this, key, value);
|
|
35
|
+
};
|
|
36
|
+
return cache;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
* A version of StrongCache that will auto-schedule a cleanup of the cache when
|
|
41
|
+
* a new item is added.
|
|
42
|
+
* Throttled to once per 100ms.
|
|
43
|
+
*
|
|
44
|
+
* @privateRemarks
|
|
45
|
+
* Should be used throughout the rest of the codebase instead of StrongCache,
|
|
46
|
+
* with the notable exception of usage in `wrap` from `optimism` - that one
|
|
47
|
+
* already handles cleanup and should remain a `StrongCache`.
|
|
48
|
+
*/
|
|
49
|
+
export var AutoCleanedStrongCache = function (max, dispose) {
|
|
50
|
+
/*
|
|
51
|
+
Some builds of `StrongCache` are function prototypes, some are classes.
|
|
52
|
+
This library still builds with an ES5 target, so we can't extend the
|
|
53
|
+
real classes.
|
|
54
|
+
Instead, we have to use this workaround until we switch to a newer build
|
|
55
|
+
target.
|
|
56
|
+
*/
|
|
57
|
+
var cache = new StrongCache(max, dispose);
|
|
58
|
+
cache.set = function (key, value) {
|
|
59
|
+
schedule(this);
|
|
60
|
+
return StrongCache.prototype.set.call(this, key, value);
|
|
61
|
+
};
|
|
62
|
+
return cache;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=caches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caches.js","sourceRoot":"","sources":["../../../src/utilities/caching/caches.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAErD,IAAM,gBAAgB,GAAG,IAAI,OAAO,EAAyB,CAAC;AAC9D,SAAS,QAAQ,CAAC,KAA4B;IAC5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,UAAU,CAAC;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AACD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAClC,GAAwB,EACxB,OAAsD;IAEtD;;;;;;MAME;IACF,IAAM,KAAK,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1C,KAAK,CAAC,GAAG,GAAG,UAAU,GAAQ,EAAE,KAAU;QACxC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAA4B,CAAC;AAM7B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,sBAAsB,GAAG,UACpC,GAAwB,EACxB,OAAsD;IAEtD;;;;;;MAME;IACF,IAAM,KAAK,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,KAAK,CAAC,GAAG,GAAG,UAAU,GAAQ,EAAE,KAAU;QACxC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAA8B,CAAC","sourcesContent":["import type { CommonCache } from \"@wry/caches\";\nimport { WeakCache, StrongCache } from \"@wry/caches\";\n\nconst scheduledCleanup = new WeakSet<CommonCache<any, any>>();\nfunction schedule(cache: CommonCache<any, any>) {\n if (!scheduledCleanup.has(cache)) {\n scheduledCleanup.add(cache);\n setTimeout(() => {\n cache.clean();\n scheduledCleanup.delete(cache);\n }, 100);\n }\n}\n/**\n * @internal\n * A version of WeakCache that will auto-schedule a cleanup of the cache when\n * a new item is added.\n * Throttled to once per 100ms.\n *\n * @privateRemarks\n * Should be used throughout the rest of the codebase instead of WeakCache,\n * with the notable exception of usage in `wrap` from `optimism` - that one\n * already handles cleanup and should remain a `WeakCache`.\n */\nexport const AutoCleanedWeakCache = function (\n max?: number | undefined,\n dispose?: ((value: any, key: any) => void) | undefined\n) {\n /*\n Some builds of `WeakCache` are function prototypes, some are classes.\n This library still builds with an ES5 target, so we can't extend the\n real classes.\n Instead, we have to use this workaround until we switch to a newer build\n target.\n */\n const cache = new WeakCache(max, dispose);\n cache.set = function (key: any, value: any) {\n schedule(this);\n return WeakCache.prototype.set.call(this, key, value);\n };\n return cache;\n} as any as typeof WeakCache;\n/**\n * @internal\n */\nexport type AutoCleanedWeakCache<K extends object, V> = WeakCache<K, V>;\n\n/**\n * @internal\n * A version of StrongCache that will auto-schedule a cleanup of the cache when\n * a new item is added.\n * Throttled to once per 100ms.\n *\n * @privateRemarks\n * Should be used throughout the rest of the codebase instead of StrongCache,\n * with the notable exception of usage in `wrap` from `optimism` - that one\n * already handles cleanup and should remain a `StrongCache`.\n */\nexport const AutoCleanedStrongCache = function (\n max?: number | undefined,\n dispose?: ((value: any, key: any) => void) | undefined\n) {\n /*\n Some builds of `StrongCache` are function prototypes, some are classes.\n This library still builds with an ES5 target, so we can't extend the\n real classes.\n Instead, we have to use this workaround until we switch to a newer build\n target.\n */\n const cache = new StrongCache(max, dispose);\n cache.set = function (key: any, value: any) {\n schedule(this);\n return StrongCache.prototype.set.call(this, key, value);\n };\n return cache;\n} as any as typeof StrongCache;\n/**\n * @internal\n */\nexport type AutoCleanedStrongCache<K, V> = StrongCache<K, V>;\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
declare const globalCaches: {
|
|
2
|
+
print?: () => number;
|
|
3
|
+
parser?: () => number;
|
|
4
|
+
canonicalStringify?: () => number;
|
|
5
|
+
};
|
|
6
|
+
export declare function registerGlobalCache(name: keyof typeof globalCaches, getSize: () => number): void;
|
|
7
|
+
/**
|
|
8
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const getApolloClientMemoryInternals: (() => {
|
|
12
|
+
limits: {
|
|
13
|
+
[k: string]: number;
|
|
14
|
+
};
|
|
15
|
+
sizes: {
|
|
16
|
+
cache?: {
|
|
17
|
+
fragmentQueryDocuments: number | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
addTypenameDocumentTransform?: {
|
|
20
|
+
cache: number;
|
|
21
|
+
}[] | undefined;
|
|
22
|
+
inMemoryCache?: {
|
|
23
|
+
executeSelectionSet: number | undefined;
|
|
24
|
+
executeSubSelectedArray: number | undefined;
|
|
25
|
+
maybeBroadcastWatch: number | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
fragmentRegistry?: {
|
|
28
|
+
findFragmentSpreads: number | undefined;
|
|
29
|
+
lookup: number | undefined;
|
|
30
|
+
transform: number | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
print: number | undefined;
|
|
33
|
+
parser: number | undefined;
|
|
34
|
+
canonicalStringify: number | undefined;
|
|
35
|
+
links: unknown[];
|
|
36
|
+
queryManager: {
|
|
37
|
+
getDocumentInfo: number;
|
|
38
|
+
documentTransforms: {
|
|
39
|
+
cache: number;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}) | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const getInMemoryCacheMemoryInternals: (() => {
|
|
49
|
+
addTypenameDocumentTransform: {
|
|
50
|
+
cache: number;
|
|
51
|
+
}[];
|
|
52
|
+
inMemoryCache: {
|
|
53
|
+
executeSelectionSet: number | undefined;
|
|
54
|
+
executeSubSelectedArray: number | undefined;
|
|
55
|
+
maybeBroadcastWatch: number | undefined;
|
|
56
|
+
};
|
|
57
|
+
fragmentRegistry: {
|
|
58
|
+
findFragmentSpreads: number | undefined;
|
|
59
|
+
lookup: number | undefined;
|
|
60
|
+
transform: number | undefined;
|
|
61
|
+
};
|
|
62
|
+
cache: {
|
|
63
|
+
fragmentQueryDocuments: number | undefined;
|
|
64
|
+
};
|
|
65
|
+
}) | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare const getApolloCacheMemoryInternals: (() => {
|
|
71
|
+
cache: {
|
|
72
|
+
fragmentQueryDocuments: number | undefined;
|
|
73
|
+
};
|
|
74
|
+
}) | undefined;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=getMemoryInternals.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { __assign, __spreadArray } from "tslib";
|
|
2
|
+
import { cacheSizes } from "./sizes.js";
|
|
3
|
+
var globalCaches = {};
|
|
4
|
+
export function registerGlobalCache(name, getSize) {
|
|
5
|
+
globalCaches[name] = getSize;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?
|
|
12
|
+
_getApolloClientMemoryInternals
|
|
13
|
+
: undefined;
|
|
14
|
+
/**
|
|
15
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export var getInMemoryCacheMemoryInternals = globalThis.__DEV__ !== false ?
|
|
19
|
+
_getInMemoryCacheMemoryInternals
|
|
20
|
+
: undefined;
|
|
21
|
+
/**
|
|
22
|
+
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export var getApolloCacheMemoryInternals = globalThis.__DEV__ !== false ?
|
|
26
|
+
_getApolloCacheMemoryInternals
|
|
27
|
+
: undefined;
|
|
28
|
+
function getCurrentCacheSizes() {
|
|
29
|
+
// `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here
|
|
30
|
+
var defaults = {
|
|
31
|
+
parser: 1000 /* defaultCacheSizes["parser"] */,
|
|
32
|
+
canonicalStringify: 1000 /* defaultCacheSizes["canonicalStringify"] */,
|
|
33
|
+
print: 2000 /* defaultCacheSizes["print"] */,
|
|
34
|
+
"documentTransform.cache": 2000 /* defaultCacheSizes["documentTransform.cache"] */,
|
|
35
|
+
"queryManager.getDocumentInfo": 2000 /* defaultCacheSizes["queryManager.getDocumentInfo"] */,
|
|
36
|
+
"PersistedQueryLink.persistedQueryHashes": 2000 /* defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"] */,
|
|
37
|
+
"fragmentRegistry.transform": 2000 /* defaultCacheSizes["fragmentRegistry.transform"] */,
|
|
38
|
+
"fragmentRegistry.lookup": 1000 /* defaultCacheSizes["fragmentRegistry.lookup"] */,
|
|
39
|
+
"fragmentRegistry.findFragmentSpreads": 4000 /* defaultCacheSizes["fragmentRegistry.findFragmentSpreads"] */,
|
|
40
|
+
"cache.fragmentQueryDocuments": 1000 /* defaultCacheSizes["cache.fragmentQueryDocuments"] */,
|
|
41
|
+
"removeTypenameFromVariables.getVariableDefinitions": 2000 /* defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"] */,
|
|
42
|
+
"inMemoryCache.maybeBroadcastWatch": 5000 /* defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"] */,
|
|
43
|
+
"inMemoryCache.executeSelectionSet": 10000 /* defaultCacheSizes["inMemoryCache.executeSelectionSet"] */,
|
|
44
|
+
"inMemoryCache.executeSubSelectedArray": 5000 /* defaultCacheSizes["inMemoryCache.executeSubSelectedArray"] */,
|
|
45
|
+
};
|
|
46
|
+
return Object.fromEntries(Object.entries(defaults).map(function (_a) {
|
|
47
|
+
var k = _a[0], v = _a[1];
|
|
48
|
+
return [
|
|
49
|
+
k,
|
|
50
|
+
cacheSizes[k] || v,
|
|
51
|
+
];
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
function _getApolloClientMemoryInternals() {
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
56
|
+
if (!(globalThis.__DEV__ !== false))
|
|
57
|
+
throw new Error("only supported in development mode");
|
|
58
|
+
return {
|
|
59
|
+
limits: getCurrentCacheSizes(),
|
|
60
|
+
sizes: __assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {
|
|
61
|
+
getDocumentInfo: this["queryManager"]["transformCache"].size,
|
|
62
|
+
documentTransforms: transformInfo(this["queryManager"].documentTransform),
|
|
63
|
+
} }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function _getApolloCacheMemoryInternals() {
|
|
67
|
+
return {
|
|
68
|
+
cache: {
|
|
69
|
+
fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function _getInMemoryCacheMemoryInternals() {
|
|
74
|
+
var fragments = this.config.fragments;
|
|
75
|
+
return __assign(__assign({}, _getApolloCacheMemoryInternals.apply(this)), { addTypenameDocumentTransform: transformInfo(this["addTypenameTransform"]), inMemoryCache: {
|
|
76
|
+
executeSelectionSet: getWrapperInformation(this["storeReader"]["executeSelectionSet"]),
|
|
77
|
+
executeSubSelectedArray: getWrapperInformation(this["storeReader"]["executeSubSelectedArray"]),
|
|
78
|
+
maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]),
|
|
79
|
+
}, fragmentRegistry: {
|
|
80
|
+
findFragmentSpreads: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.findFragmentSpreads),
|
|
81
|
+
lookup: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.lookup),
|
|
82
|
+
transform: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.transform),
|
|
83
|
+
} });
|
|
84
|
+
}
|
|
85
|
+
function isWrapper(f) {
|
|
86
|
+
return !!f && "dirtyKey" in f;
|
|
87
|
+
}
|
|
88
|
+
function getWrapperInformation(f) {
|
|
89
|
+
return isWrapper(f) ? f.size : undefined;
|
|
90
|
+
}
|
|
91
|
+
function isDefined(value) {
|
|
92
|
+
return value != null;
|
|
93
|
+
}
|
|
94
|
+
function transformInfo(transform) {
|
|
95
|
+
return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });
|
|
96
|
+
}
|
|
97
|
+
function recurseTransformInfo(transform) {
|
|
98
|
+
return transform ?
|
|
99
|
+
__spreadArray(__spreadArray([
|
|
100
|
+
getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform["performWork"])
|
|
101
|
+
], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["left"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["right"]), true).filter(isDefined)
|
|
102
|
+
: [];
|
|
103
|
+
}
|
|
104
|
+
function linkInfo(link) {
|
|
105
|
+
var _a;
|
|
106
|
+
return link ?
|
|
107
|
+
__spreadArray(__spreadArray([
|
|
108
|
+
(_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)
|
|
109
|
+
], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)
|
|
110
|
+
: [];
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=getMemoryInternals.js.map
|