Initial Sample.
This commit is contained in:
430
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.d.ts
generated
vendored
Normal file
430
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.d.ts
generated
vendored
Normal file
@@ -0,0 +1,430 @@
|
||||
import type { ExecutionResult, DocumentNode } from "graphql";
|
||||
import type { FetchResult, GraphQLRequest } from "../link/core/index.js";
|
||||
import { ApolloLink } from "../link/core/index.js";
|
||||
import type { ApolloCache, DataProxy, Reference } from "../cache/index.js";
|
||||
import type { DocumentTransform, Observable } from "../utilities/index.js";
|
||||
import type { UriFunction } from "../link/http/index.js";
|
||||
import type { ObservableQuery } from "./ObservableQuery.js";
|
||||
import type { ApolloQueryResult, DefaultContext, OperationVariables, Resolvers, RefetchQueriesOptions, RefetchQueriesResult, RefetchQueriesInclude } from "./types.js";
|
||||
import type { QueryOptions, WatchQueryOptions, MutationOptions, SubscriptionOptions } from "./watchQueryOptions.js";
|
||||
import type { FragmentMatcher } from "./LocalState.js";
|
||||
export interface DefaultOptions {
|
||||
watchQuery?: Partial<WatchQueryOptions<any, any>>;
|
||||
query?: Partial<QueryOptions<any, any>>;
|
||||
mutate?: Partial<MutationOptions<any, any, any>>;
|
||||
}
|
||||
export interface ApolloClientOptions<TCacheShape> {
|
||||
/**
|
||||
* The URI of the GraphQL endpoint that Apollo Client will communicate with.
|
||||
*
|
||||
* One of `uri` or `link` is **required**. If you provide both, `link` takes precedence.
|
||||
*/
|
||||
uri?: string | UriFunction;
|
||||
credentials?: string;
|
||||
/**
|
||||
* An object representing headers to include in every HTTP request, such as `{Authorization: 'Bearer 1234'}`
|
||||
*
|
||||
* This value will be ignored when using the `link` option.
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
/**
|
||||
* You can provide an {@link ApolloLink} instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/).
|
||||
*
|
||||
* One of `uri` or `link` is **required**. If you provide both, `link` takes precedence.
|
||||
*/
|
||||
link?: ApolloLink;
|
||||
/**
|
||||
* The cache that Apollo Client should use to store query results locally. The recommended cache is `InMemoryCache`, which is provided by the `@apollo/client` package.
|
||||
*
|
||||
* For more information, see [Configuring the cache](https://www.apollographql.com/docs/react/caching/cache-configuration/).
|
||||
*/
|
||||
cache: ApolloCache<TCacheShape>;
|
||||
/**
|
||||
* The time interval (in milliseconds) before Apollo Client force-fetches queries after a server-side render.
|
||||
*
|
||||
* @defaultValue `0` (no delay)
|
||||
*/
|
||||
ssrForceFetchDelay?: number;
|
||||
/**
|
||||
* When using Apollo Client for [server-side rendering](https://www.apollographql.com/docs/react/performance/server-side-rendering/), set this to `true` so that the [`getDataFromTree` function](../react/ssr/#getdatafromtree) can work effectively.
|
||||
*
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
ssrMode?: boolean;
|
||||
/**
|
||||
* If `true`, the [Apollo Client Devtools](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) browser extension can connect to Apollo Client.
|
||||
*
|
||||
* The default value is `false` in production and `true` in development (if there is a `window` object).
|
||||
*/
|
||||
connectToDevTools?: boolean;
|
||||
/**
|
||||
* If `false`, Apollo Client sends every created query to the server, even if a _completely_ identical query (identical in terms of query string, variable values, and operationName) is already in flight.
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
queryDeduplication?: boolean;
|
||||
/**
|
||||
* Provide this object to set application-wide default values for options you can provide to the `watchQuery`, `query`, and `mutate` functions. See below for an example object.
|
||||
*
|
||||
* See this [example object](https://www.apollographql.com/docs/react/api/core/ApolloClient#example-defaultoptions-object).
|
||||
*/
|
||||
defaultOptions?: DefaultOptions;
|
||||
defaultContext?: Partial<DefaultContext>;
|
||||
/**
|
||||
* If `true`, Apollo Client will assume results read from the cache are never mutated by application code, which enables substantial performance optimizations.
|
||||
*
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
assumeImmutableResults?: boolean;
|
||||
resolvers?: Resolvers | Resolvers[];
|
||||
typeDefs?: string | string[] | DocumentNode | DocumentNode[];
|
||||
fragmentMatcher?: FragmentMatcher;
|
||||
/**
|
||||
* A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
||||
*
|
||||
* This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.
|
||||
*/
|
||||
version?: string;
|
||||
documentTransform?: DocumentTransform;
|
||||
}
|
||||
import { mergeOptions } from "../utilities/index.js";
|
||||
import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js";
|
||||
export { mergeOptions };
|
||||
/**
|
||||
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
|
||||
* and mutations) to a GraphQL spec-compliant server over an {@link ApolloLink} instance,
|
||||
* receive results from the server and cache the results in a store. It also delivers updates
|
||||
* to GraphQL queries through {@link Observable} instances.
|
||||
*/
|
||||
export declare class ApolloClient<TCacheShape> implements DataProxy {
|
||||
link: ApolloLink;
|
||||
cache: ApolloCache<TCacheShape>;
|
||||
disableNetworkFetches: boolean;
|
||||
version: string;
|
||||
queryDeduplication: boolean;
|
||||
defaultOptions: DefaultOptions;
|
||||
readonly typeDefs: ApolloClientOptions<TCacheShape>["typeDefs"];
|
||||
private queryManager;
|
||||
private devToolsHookCb?;
|
||||
private resetStoreCallbacks;
|
||||
private clearStoreCallbacks;
|
||||
private localState;
|
||||
/**
|
||||
* Constructs an instance of {@link ApolloClient}.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* import { ApolloClient, InMemoryCache } from '@apollo/client';
|
||||
*
|
||||
* const cache = new InMemoryCache();
|
||||
*
|
||||
* const client = new ApolloClient({
|
||||
* // Provide required constructor fields
|
||||
* cache: cache,
|
||||
* uri: 'http://localhost:4000/',
|
||||
*
|
||||
* // Provide some optional constructor fields
|
||||
* name: 'react-web-client',
|
||||
* version: '1.3',
|
||||
* queryDeduplication: false,
|
||||
* defaultOptions: {
|
||||
* watchQuery: {
|
||||
* fetchPolicy: 'cache-and-network',
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
constructor(options: ApolloClientOptions<TCacheShape>);
|
||||
private connectToDevTools;
|
||||
/**
|
||||
* The `DocumentTransform` used to modify GraphQL documents before a request
|
||||
* is made. If a custom `DocumentTransform` is not provided, this will be the
|
||||
* default document transform.
|
||||
*/
|
||||
get documentTransform(): DocumentTransform;
|
||||
/**
|
||||
* Call this method to terminate any active client processes, making it safe
|
||||
* to dispose of this `ApolloClient` instance.
|
||||
*/
|
||||
stop(): void;
|
||||
/**
|
||||
* This watches the cache store of the query according to the options specified and
|
||||
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
|
||||
* receive updated results through a GraphQL observer when the cache store changes.
|
||||
*
|
||||
* Note that this method is not an implementation of GraphQL subscriptions. Rather,
|
||||
* it uses Apollo's store in order to reactively deliver updates to your query results.
|
||||
*
|
||||
* For example, suppose you call watchQuery on a GraphQL query that fetches a person's
|
||||
* first and last name and this person has a particular object identifier, provided by
|
||||
* dataIdFromObject. Later, a different query fetches that same person's
|
||||
* first and last name and the first name has now changed. Then, any observers associated
|
||||
* with the results of the first query will be updated with a new result object.
|
||||
*
|
||||
* Note that if the cache does not change, the subscriber will *not* be notified.
|
||||
*
|
||||
* See [here](https://medium.com/apollo-stack/the-concepts-of-graphql-bc68bd819be3#.3mb0cbcmc) for
|
||||
* a description of store reactivity.
|
||||
*/
|
||||
watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
|
||||
/**
|
||||
* This resolves a single query according to the options specified and
|
||||
* returns a `Promise` which is either resolved with the resulting data
|
||||
* or rejected with an error.
|
||||
*
|
||||
* @param options - An object of type {@link QueryOptions} that allows us to
|
||||
* describe how this query should be treated e.g. whether it should hit the
|
||||
* server at all or just resolve from the cache, etc.
|
||||
*/
|
||||
query<T = any, TVariables extends OperationVariables = OperationVariables>(options: QueryOptions<TVariables, T>): Promise<ApolloQueryResult<T>>;
|
||||
/**
|
||||
* This resolves a single mutation according to the options specified and returns a
|
||||
* Promise which is either resolved with the resulting data or rejected with an
|
||||
* error. In some cases both `data` and `errors` might be undefined, for example
|
||||
* when `errorPolicy` is set to `'ignore'`.
|
||||
*
|
||||
* It takes options as an object with the following keys and values:
|
||||
*/
|
||||
mutate<TData = any, TVariables extends OperationVariables = OperationVariables, TContext extends Record<string, any> = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(options: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
|
||||
/**
|
||||
* This subscribes to a graphql subscription according to the options specified and returns an
|
||||
* {@link Observable} which either emits received data or an error.
|
||||
*/
|
||||
subscribe<T = any, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TVariables, T>): Observable<FetchResult<T>>;
|
||||
/**
|
||||
* Tries to read some data from the store in the shape of the provided
|
||||
* GraphQL query without making a network request. This method will start at
|
||||
* the root query. To start at a specific id returned by `dataIdFromObject`
|
||||
* use `readFragment`.
|
||||
*
|
||||
* @param optimistic - Set to `true` to allow `readQuery` to return
|
||||
* optimistic results. Is `false` by default.
|
||||
*/
|
||||
readQuery<T = any, TVariables = OperationVariables>(options: DataProxy.Query<TVariables, T>, optimistic?: boolean): T | null;
|
||||
/**
|
||||
* Tries to read some data from the store in the shape of the provided
|
||||
* GraphQL fragment without making a network request. This method will read a
|
||||
* GraphQL fragment from any arbitrary id that is currently cached, unlike
|
||||
* `readQuery` which will only read from the root query.
|
||||
*
|
||||
* You must pass in a GraphQL document with a single fragment or a document
|
||||
* with multiple fragments that represent what you are reading. If you pass
|
||||
* in a document with multiple fragments then you must also specify a
|
||||
* `fragmentName`.
|
||||
*
|
||||
* @param optimistic - Set to `true` to allow `readFragment` to return
|
||||
* optimistic results. Is `false` by default.
|
||||
*/
|
||||
readFragment<T = any, TVariables = OperationVariables>(options: DataProxy.Fragment<TVariables, T>, optimistic?: boolean): T | null;
|
||||
/**
|
||||
* Writes some data in the shape of the provided GraphQL query directly to
|
||||
* the store. This method will start at the root query. To start at a
|
||||
* specific id returned by `dataIdFromObject` then use `writeFragment`.
|
||||
*/
|
||||
writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): Reference | undefined;
|
||||
/**
|
||||
* Writes some data in the shape of the provided GraphQL fragment directly to
|
||||
* the store. This method will write to a GraphQL fragment from any arbitrary
|
||||
* id that is currently cached, unlike `writeQuery` which will only write
|
||||
* from the root query.
|
||||
*
|
||||
* You must pass in a GraphQL document with a single fragment or a document
|
||||
* with multiple fragments that represent what you are writing. If you pass
|
||||
* in a document with multiple fragments then you must also specify a
|
||||
* `fragmentName`.
|
||||
*/
|
||||
writeFragment<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
||||
__actionHookForDevTools(cb: () => any): void;
|
||||
__requestRaw(payload: GraphQLRequest): Observable<ExecutionResult>;
|
||||
/**
|
||||
* Resets your entire store by clearing out your cache and then re-executing
|
||||
* all of your active queries. This makes it so that you may guarantee that
|
||||
* there is no data left in your store from a time before you called this
|
||||
* method.
|
||||
*
|
||||
* `resetStore()` is useful when your user just logged out. You’ve removed the
|
||||
* user session, and you now want to make sure that any references to data you
|
||||
* might have fetched while the user session was active is gone.
|
||||
*
|
||||
* It is important to remember that `resetStore()` *will* refetch any active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
*/
|
||||
resetStore(): Promise<ApolloQueryResult<any>[] | null>;
|
||||
/**
|
||||
* Remove all data from the store. Unlike `resetStore`, `clearStore` will
|
||||
* not refetch any active queries.
|
||||
*/
|
||||
clearStore(): Promise<any[]>;
|
||||
/**
|
||||
* Allows callbacks to be registered that are executed when the store is
|
||||
* reset. `onResetStore` returns an unsubscribe function that can be used
|
||||
* to remove registered callbacks.
|
||||
*/
|
||||
onResetStore(cb: () => Promise<any>): () => void;
|
||||
/**
|
||||
* Allows callbacks to be registered that are executed when the store is
|
||||
* cleared. `onClearStore` returns an unsubscribe function that can be used
|
||||
* to remove registered callbacks.
|
||||
*/
|
||||
onClearStore(cb: () => Promise<any>): () => void;
|
||||
/**
|
||||
* Refetches all of your active queries.
|
||||
*
|
||||
* `reFetchObservableQueries()` is useful if you want to bring the client back to proper state in case of a network outage
|
||||
*
|
||||
* It is important to remember that `reFetchObservableQueries()` *will* refetch any active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
* Takes optional parameter `includeStandby` which will include queries in standby-mode when refetching.
|
||||
*/
|
||||
reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]>;
|
||||
/**
|
||||
* Refetches specified active queries. Similar to "reFetchObservableQueries()" but with a specific list of queries.
|
||||
*
|
||||
* `refetchQueries()` is useful for use cases to imperatively refresh a selection of queries.
|
||||
*
|
||||
* It is important to remember that `refetchQueries()` *will* refetch specified active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
*/
|
||||
refetchQueries<TCache extends ApolloCache<any> = ApolloCache<TCacheShape>, TResult = Promise<ApolloQueryResult<any>>>(options: RefetchQueriesOptions<TCache, TResult>): RefetchQueriesResult<TResult>;
|
||||
/**
|
||||
* Get all currently active `ObservableQuery` objects, in a `Map` keyed by
|
||||
* query ID strings.
|
||||
*
|
||||
* An "active" query is one that has observers and a `fetchPolicy` other than
|
||||
* "standby" or "cache-only".
|
||||
*
|
||||
* You can include all `ObservableQuery` objects (including the inactive ones)
|
||||
* by passing "all" instead of "active", or you can include just a subset of
|
||||
* active queries by passing an array of query names or DocumentNode objects.
|
||||
*/
|
||||
getObservableQueries(include?: RefetchQueriesInclude): Map<string, ObservableQuery<any>>;
|
||||
/**
|
||||
* Exposes the cache's complete state, in a serializable format for later restoration.
|
||||
*/
|
||||
extract(optimistic?: boolean): TCacheShape;
|
||||
/**
|
||||
* Replaces existing state in the cache (if any) with the values expressed by
|
||||
* `serializedState`.
|
||||
*
|
||||
* Called when hydrating a cache (server side rendering, or offline storage),
|
||||
* and also (potentially) during hot reloads.
|
||||
*/
|
||||
restore(serializedState: TCacheShape): ApolloCache<TCacheShape>;
|
||||
/**
|
||||
* Add additional local resolvers.
|
||||
*/
|
||||
addResolvers(resolvers: Resolvers | Resolvers[]): void;
|
||||
/**
|
||||
* Set (override existing) local resolvers.
|
||||
*/
|
||||
setResolvers(resolvers: Resolvers | Resolvers[]): void;
|
||||
/**
|
||||
* Get all registered local resolvers.
|
||||
*/
|
||||
getResolvers(): Resolvers;
|
||||
/**
|
||||
* Set a custom local state fragment matcher.
|
||||
*/
|
||||
setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): void;
|
||||
/**
|
||||
* Define a new ApolloLink (or link chain) that Apollo Client will use.
|
||||
*/
|
||||
setLink(newLink: ApolloLink): void;
|
||||
get defaultContext(): Partial<DefaultContext>;
|
||||
/**
|
||||
* @experimental
|
||||
* This is not a stable API - it is used in development builds to expose
|
||||
* information to the DevTools.
|
||||
* Use at your own risk!
|
||||
* For more details, see [Memory Management](https://www.apollographql.com/docs/react/caching/memory-management/#measuring-cache-usage)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* console.log(client.getMemoryInternals())
|
||||
* ```
|
||||
* Logs output in the following JSON format:
|
||||
* @example
|
||||
* ```json
|
||||
*{
|
||||
* limits: {
|
||||
* parser: 1000,
|
||||
* canonicalStringify: 1000,
|
||||
* print: 2000,
|
||||
* 'documentTransform.cache': 2000,
|
||||
* 'queryManager.getDocumentInfo': 2000,
|
||||
* 'PersistedQueryLink.persistedQueryHashes': 2000,
|
||||
* 'fragmentRegistry.transform': 2000,
|
||||
* 'fragmentRegistry.lookup': 1000,
|
||||
* 'fragmentRegistry.findFragmentSpreads': 4000,
|
||||
* 'cache.fragmentQueryDocuments': 1000,
|
||||
* 'removeTypenameFromVariables.getVariableDefinitions': 2000,
|
||||
* 'inMemoryCache.maybeBroadcastWatch': 5000,
|
||||
* 'inMemoryCache.executeSelectionSet': 10000,
|
||||
* 'inMemoryCache.executeSubSelectedArray': 5000
|
||||
* },
|
||||
* sizes: {
|
||||
* parser: 26,
|
||||
* canonicalStringify: 4,
|
||||
* print: 14,
|
||||
* addTypenameDocumentTransform: [
|
||||
* {
|
||||
* cache: 14,
|
||||
* },
|
||||
* ],
|
||||
* queryManager: {
|
||||
* getDocumentInfo: 14,
|
||||
* documentTransforms: [
|
||||
* {
|
||||
* cache: 14,
|
||||
* },
|
||||
* {
|
||||
* cache: 14,
|
||||
* },
|
||||
* ],
|
||||
* },
|
||||
* fragmentRegistry: {
|
||||
* findFragmentSpreads: 34,
|
||||
* lookup: 20,
|
||||
* transform: 14,
|
||||
* },
|
||||
* cache: {
|
||||
* fragmentQueryDocuments: 22,
|
||||
* },
|
||||
* inMemoryCache: {
|
||||
* executeSelectionSet: 4345,
|
||||
* executeSubSelectedArray: 1206,
|
||||
* maybeBroadcastWatch: 32,
|
||||
* },
|
||||
* links: [
|
||||
* {
|
||||
* PersistedQueryLink: {
|
||||
* persistedQueryHashes: 14,
|
||||
* },
|
||||
* },
|
||||
* {
|
||||
* removeTypenameFromVariables: {
|
||||
* getVariableDefinitions: 14,
|
||||
* },
|
||||
* },
|
||||
* ],
|
||||
* },
|
||||
* }
|
||||
*```
|
||||
*/
|
||||
getMemoryInternals?: typeof getApolloClientMemoryInternals;
|
||||
}
|
||||
//# sourceMappingURL=ApolloClient.d.ts.map
|
||||
508
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.js
generated
vendored
Normal file
508
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.js
generated
vendored
Normal file
@@ -0,0 +1,508 @@
|
||||
import { __assign } from "tslib";
|
||||
import { invariant, newInvariantError } from "../utilities/globals/index.js";
|
||||
import { ApolloLink, execute } from "../link/core/index.js";
|
||||
import { version } from "../version.js";
|
||||
import { HttpLink } from "../link/http/index.js";
|
||||
import { QueryManager } from "./QueryManager.js";
|
||||
import { LocalState } from "./LocalState.js";
|
||||
var hasSuggestedDevtools = false;
|
||||
// Though mergeOptions now resides in @apollo/client/utilities, it was
|
||||
// previously declared and exported from this module, and then reexported from
|
||||
// @apollo/client/core. Since we need to preserve that API anyway, the easiest
|
||||
// solution is to reexport mergeOptions where it was previously declared (here).
|
||||
import { mergeOptions } from "../utilities/index.js";
|
||||
import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js";
|
||||
export { mergeOptions };
|
||||
/**
|
||||
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
|
||||
* and mutations) to a GraphQL spec-compliant server over an {@link ApolloLink} instance,
|
||||
* receive results from the server and cache the results in a store. It also delivers updates
|
||||
* to GraphQL queries through {@link Observable} instances.
|
||||
*/
|
||||
var ApolloClient = /** @class */ (function () {
|
||||
/**
|
||||
* Constructs an instance of {@link ApolloClient}.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* import { ApolloClient, InMemoryCache } from '@apollo/client';
|
||||
*
|
||||
* const cache = new InMemoryCache();
|
||||
*
|
||||
* const client = new ApolloClient({
|
||||
* // Provide required constructor fields
|
||||
* cache: cache,
|
||||
* uri: 'http://localhost:4000/',
|
||||
*
|
||||
* // Provide some optional constructor fields
|
||||
* name: 'react-web-client',
|
||||
* version: '1.3',
|
||||
* queryDeduplication: false,
|
||||
* defaultOptions: {
|
||||
* watchQuery: {
|
||||
* fetchPolicy: 'cache-and-network',
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
function ApolloClient(options) {
|
||||
var _this = this;
|
||||
this.resetStoreCallbacks = [];
|
||||
this.clearStoreCallbacks = [];
|
||||
if (!options.cache) {
|
||||
throw newInvariantError(15);
|
||||
}
|
||||
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b,
|
||||
// Expose the client instance as window.__APOLLO_CLIENT__ and call
|
||||
// onBroadcast in queryManager.broadcastQueries to enable browser
|
||||
// devtools, but disable them by default in production.
|
||||
_c = options.connectToDevTools,
|
||||
// Expose the client instance as window.__APOLLO_CLIENT__ and call
|
||||
// onBroadcast in queryManager.broadcastQueries to enable browser
|
||||
// devtools, but disable them by default in production.
|
||||
connectToDevTools = _c === void 0 ? typeof window === "object" &&
|
||||
!window.__APOLLO_CLIENT__ &&
|
||||
globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
|
||||
var link = options.link;
|
||||
if (!link) {
|
||||
link =
|
||||
uri ? new HttpLink({ uri: uri, credentials: credentials, headers: headers }) : ApolloLink.empty();
|
||||
}
|
||||
this.link = link;
|
||||
this.cache = cache;
|
||||
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
||||
this.queryDeduplication = queryDeduplication;
|
||||
this.defaultOptions = defaultOptions || Object.create(null);
|
||||
this.typeDefs = typeDefs;
|
||||
if (ssrForceFetchDelay) {
|
||||
setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
||||
}
|
||||
this.watchQuery = this.watchQuery.bind(this);
|
||||
this.query = this.query.bind(this);
|
||||
this.mutate = this.mutate.bind(this);
|
||||
this.resetStore = this.resetStore.bind(this);
|
||||
this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
|
||||
this.version = version;
|
||||
this.localState = new LocalState({
|
||||
cache: cache,
|
||||
client: this,
|
||||
resolvers: resolvers,
|
||||
fragmentMatcher: fragmentMatcher,
|
||||
});
|
||||
this.queryManager = new QueryManager({
|
||||
cache: this.cache,
|
||||
link: this.link,
|
||||
defaultOptions: this.defaultOptions,
|
||||
defaultContext: defaultContext,
|
||||
documentTransform: documentTransform,
|
||||
queryDeduplication: queryDeduplication,
|
||||
ssrMode: ssrMode,
|
||||
clientAwareness: {
|
||||
name: clientAwarenessName,
|
||||
version: clientAwarenessVersion,
|
||||
},
|
||||
localState: this.localState,
|
||||
assumeImmutableResults: assumeImmutableResults,
|
||||
onBroadcast: connectToDevTools ?
|
||||
function () {
|
||||
if (_this.devToolsHookCb) {
|
||||
_this.devToolsHookCb({
|
||||
action: {},
|
||||
state: {
|
||||
queries: _this.queryManager.getQueryStore(),
|
||||
mutations: _this.queryManager.mutationStore || {},
|
||||
},
|
||||
dataWithOptimisticResults: _this.cache.extract(true),
|
||||
});
|
||||
}
|
||||
}
|
||||
: void 0,
|
||||
});
|
||||
if (connectToDevTools)
|
||||
this.connectToDevTools();
|
||||
}
|
||||
ApolloClient.prototype.connectToDevTools = function () {
|
||||
if (typeof window === "object") {
|
||||
var windowWithDevTools = window;
|
||||
var devtoolsSymbol = Symbol.for("apollo.devtools");
|
||||
(windowWithDevTools[devtoolsSymbol] =
|
||||
windowWithDevTools[devtoolsSymbol] || []).push(this);
|
||||
windowWithDevTools.__APOLLO_CLIENT__ = this;
|
||||
}
|
||||
/**
|
||||
* Suggest installing the devtools for developers who don't have them
|
||||
*/
|
||||
if (!hasSuggestedDevtools && globalThis.__DEV__ !== false) {
|
||||
hasSuggestedDevtools = true;
|
||||
setTimeout(function () {
|
||||
if (typeof window !== "undefined" &&
|
||||
window.document &&
|
||||
window.top === window.self &&
|
||||
!window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
|
||||
var nav = window.navigator;
|
||||
var ua = nav && nav.userAgent;
|
||||
var url = void 0;
|
||||
if (typeof ua === "string") {
|
||||
if (ua.indexOf("Chrome/") > -1) {
|
||||
url =
|
||||
"https://chrome.google.com/webstore/detail/" +
|
||||
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
|
||||
}
|
||||
else if (ua.indexOf("Firefox/") > -1) {
|
||||
url =
|
||||
"https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
|
||||
}
|
||||
}
|
||||
if (url) {
|
||||
globalThis.__DEV__ !== false && invariant.log("Download the Apollo DevTools for a better development " +
|
||||
"experience: %s", url);
|
||||
}
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(ApolloClient.prototype, "documentTransform", {
|
||||
/**
|
||||
* The `DocumentTransform` used to modify GraphQL documents before a request
|
||||
* is made. If a custom `DocumentTransform` is not provided, this will be the
|
||||
* default document transform.
|
||||
*/
|
||||
get: function () {
|
||||
return this.queryManager.documentTransform;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Call this method to terminate any active client processes, making it safe
|
||||
* to dispose of this `ApolloClient` instance.
|
||||
*/
|
||||
ApolloClient.prototype.stop = function () {
|
||||
this.queryManager.stop();
|
||||
};
|
||||
/**
|
||||
* This watches the cache store of the query according to the options specified and
|
||||
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
|
||||
* receive updated results through a GraphQL observer when the cache store changes.
|
||||
*
|
||||
* Note that this method is not an implementation of GraphQL subscriptions. Rather,
|
||||
* it uses Apollo's store in order to reactively deliver updates to your query results.
|
||||
*
|
||||
* For example, suppose you call watchQuery on a GraphQL query that fetches a person's
|
||||
* first and last name and this person has a particular object identifier, provided by
|
||||
* dataIdFromObject. Later, a different query fetches that same person's
|
||||
* first and last name and the first name has now changed. Then, any observers associated
|
||||
* with the results of the first query will be updated with a new result object.
|
||||
*
|
||||
* Note that if the cache does not change, the subscriber will *not* be notified.
|
||||
*
|
||||
* See [here](https://medium.com/apollo-stack/the-concepts-of-graphql-bc68bd819be3#.3mb0cbcmc) for
|
||||
* a description of store reactivity.
|
||||
*/
|
||||
ApolloClient.prototype.watchQuery = function (options) {
|
||||
if (this.defaultOptions.watchQuery) {
|
||||
options = mergeOptions(this.defaultOptions.watchQuery, options);
|
||||
}
|
||||
// XXX Overwriting options is probably not the best way to do this long term...
|
||||
if (this.disableNetworkFetches &&
|
||||
(options.fetchPolicy === "network-only" ||
|
||||
options.fetchPolicy === "cache-and-network")) {
|
||||
options = __assign(__assign({}, options), { fetchPolicy: "cache-first" });
|
||||
}
|
||||
return this.queryManager.watchQuery(options);
|
||||
};
|
||||
/**
|
||||
* This resolves a single query according to the options specified and
|
||||
* returns a `Promise` which is either resolved with the resulting data
|
||||
* or rejected with an error.
|
||||
*
|
||||
* @param options - An object of type {@link QueryOptions} that allows us to
|
||||
* describe how this query should be treated e.g. whether it should hit the
|
||||
* server at all or just resolve from the cache, etc.
|
||||
*/
|
||||
ApolloClient.prototype.query = function (options) {
|
||||
if (this.defaultOptions.query) {
|
||||
options = mergeOptions(this.defaultOptions.query, options);
|
||||
}
|
||||
invariant(options.fetchPolicy !== "cache-and-network", 16);
|
||||
if (this.disableNetworkFetches && options.fetchPolicy === "network-only") {
|
||||
options = __assign(__assign({}, options), { fetchPolicy: "cache-first" });
|
||||
}
|
||||
return this.queryManager.query(options);
|
||||
};
|
||||
/**
|
||||
* This resolves a single mutation according to the options specified and returns a
|
||||
* Promise which is either resolved with the resulting data or rejected with an
|
||||
* error. In some cases both `data` and `errors` might be undefined, for example
|
||||
* when `errorPolicy` is set to `'ignore'`.
|
||||
*
|
||||
* It takes options as an object with the following keys and values:
|
||||
*/
|
||||
ApolloClient.prototype.mutate = function (options) {
|
||||
if (this.defaultOptions.mutate) {
|
||||
options = mergeOptions(this.defaultOptions.mutate, options);
|
||||
}
|
||||
return this.queryManager.mutate(options);
|
||||
};
|
||||
/**
|
||||
* This subscribes to a graphql subscription according to the options specified and returns an
|
||||
* {@link Observable} which either emits received data or an error.
|
||||
*/
|
||||
ApolloClient.prototype.subscribe = function (options) {
|
||||
return this.queryManager.startGraphQLSubscription(options);
|
||||
};
|
||||
/**
|
||||
* Tries to read some data from the store in the shape of the provided
|
||||
* GraphQL query without making a network request. This method will start at
|
||||
* the root query. To start at a specific id returned by `dataIdFromObject`
|
||||
* use `readFragment`.
|
||||
*
|
||||
* @param optimistic - Set to `true` to allow `readQuery` to return
|
||||
* optimistic results. Is `false` by default.
|
||||
*/
|
||||
ApolloClient.prototype.readQuery = function (options, optimistic) {
|
||||
if (optimistic === void 0) { optimistic = false; }
|
||||
return this.cache.readQuery(options, optimistic);
|
||||
};
|
||||
/**
|
||||
* Tries to read some data from the store in the shape of the provided
|
||||
* GraphQL fragment without making a network request. This method will read a
|
||||
* GraphQL fragment from any arbitrary id that is currently cached, unlike
|
||||
* `readQuery` which will only read from the root query.
|
||||
*
|
||||
* You must pass in a GraphQL document with a single fragment or a document
|
||||
* with multiple fragments that represent what you are reading. If you pass
|
||||
* in a document with multiple fragments then you must also specify a
|
||||
* `fragmentName`.
|
||||
*
|
||||
* @param optimistic - Set to `true` to allow `readFragment` to return
|
||||
* optimistic results. Is `false` by default.
|
||||
*/
|
||||
ApolloClient.prototype.readFragment = function (options, optimistic) {
|
||||
if (optimistic === void 0) { optimistic = false; }
|
||||
return this.cache.readFragment(options, optimistic);
|
||||
};
|
||||
/**
|
||||
* Writes some data in the shape of the provided GraphQL query directly to
|
||||
* the store. This method will start at the root query. To start at a
|
||||
* specific id returned by `dataIdFromObject` then use `writeFragment`.
|
||||
*/
|
||||
ApolloClient.prototype.writeQuery = function (options) {
|
||||
var ref = this.cache.writeQuery(options);
|
||||
if (options.broadcast !== false) {
|
||||
this.queryManager.broadcastQueries();
|
||||
}
|
||||
return ref;
|
||||
};
|
||||
/**
|
||||
* Writes some data in the shape of the provided GraphQL fragment directly to
|
||||
* the store. This method will write to a GraphQL fragment from any arbitrary
|
||||
* id that is currently cached, unlike `writeQuery` which will only write
|
||||
* from the root query.
|
||||
*
|
||||
* You must pass in a GraphQL document with a single fragment or a document
|
||||
* with multiple fragments that represent what you are writing. If you pass
|
||||
* in a document with multiple fragments then you must also specify a
|
||||
* `fragmentName`.
|
||||
*/
|
||||
ApolloClient.prototype.writeFragment = function (options) {
|
||||
var ref = this.cache.writeFragment(options);
|
||||
if (options.broadcast !== false) {
|
||||
this.queryManager.broadcastQueries();
|
||||
}
|
||||
return ref;
|
||||
};
|
||||
ApolloClient.prototype.__actionHookForDevTools = function (cb) {
|
||||
this.devToolsHookCb = cb;
|
||||
};
|
||||
ApolloClient.prototype.__requestRaw = function (payload) {
|
||||
return execute(this.link, payload);
|
||||
};
|
||||
/**
|
||||
* Resets your entire store by clearing out your cache and then re-executing
|
||||
* all of your active queries. This makes it so that you may guarantee that
|
||||
* there is no data left in your store from a time before you called this
|
||||
* method.
|
||||
*
|
||||
* `resetStore()` is useful when your user just logged out. You’ve removed the
|
||||
* user session, and you now want to make sure that any references to data you
|
||||
* might have fetched while the user session was active is gone.
|
||||
*
|
||||
* It is important to remember that `resetStore()` *will* refetch any active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
*/
|
||||
ApolloClient.prototype.resetStore = function () {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return _this.queryManager.clearStore({
|
||||
discardWatches: false,
|
||||
});
|
||||
})
|
||||
.then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
|
||||
.then(function () { return _this.reFetchObservableQueries(); });
|
||||
};
|
||||
/**
|
||||
* Remove all data from the store. Unlike `resetStore`, `clearStore` will
|
||||
* not refetch any active queries.
|
||||
*/
|
||||
ApolloClient.prototype.clearStore = function () {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return _this.queryManager.clearStore({
|
||||
discardWatches: true,
|
||||
});
|
||||
})
|
||||
.then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
|
||||
};
|
||||
/**
|
||||
* Allows callbacks to be registered that are executed when the store is
|
||||
* reset. `onResetStore` returns an unsubscribe function that can be used
|
||||
* to remove registered callbacks.
|
||||
*/
|
||||
ApolloClient.prototype.onResetStore = function (cb) {
|
||||
var _this = this;
|
||||
this.resetStoreCallbacks.push(cb);
|
||||
return function () {
|
||||
_this.resetStoreCallbacks = _this.resetStoreCallbacks.filter(function (c) { return c !== cb; });
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Allows callbacks to be registered that are executed when the store is
|
||||
* cleared. `onClearStore` returns an unsubscribe function that can be used
|
||||
* to remove registered callbacks.
|
||||
*/
|
||||
ApolloClient.prototype.onClearStore = function (cb) {
|
||||
var _this = this;
|
||||
this.clearStoreCallbacks.push(cb);
|
||||
return function () {
|
||||
_this.clearStoreCallbacks = _this.clearStoreCallbacks.filter(function (c) { return c !== cb; });
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Refetches all of your active queries.
|
||||
*
|
||||
* `reFetchObservableQueries()` is useful if you want to bring the client back to proper state in case of a network outage
|
||||
*
|
||||
* It is important to remember that `reFetchObservableQueries()` *will* refetch any active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
* Takes optional parameter `includeStandby` which will include queries in standby-mode when refetching.
|
||||
*/
|
||||
ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {
|
||||
return this.queryManager.reFetchObservableQueries(includeStandby);
|
||||
};
|
||||
/**
|
||||
* Refetches specified active queries. Similar to "reFetchObservableQueries()" but with a specific list of queries.
|
||||
*
|
||||
* `refetchQueries()` is useful for use cases to imperatively refresh a selection of queries.
|
||||
*
|
||||
* It is important to remember that `refetchQueries()` *will* refetch specified active
|
||||
* queries. This means that any components that might be mounted will execute
|
||||
* their queries again using your network interface. If you do not want to
|
||||
* re-execute any queries then you should make sure to stop watching any
|
||||
* active queries.
|
||||
*/
|
||||
ApolloClient.prototype.refetchQueries = function (options) {
|
||||
var map = this.queryManager.refetchQueries(options);
|
||||
var queries = [];
|
||||
var results = [];
|
||||
map.forEach(function (result, obsQuery) {
|
||||
queries.push(obsQuery);
|
||||
results.push(result);
|
||||
});
|
||||
var result = Promise.all(results);
|
||||
// In case you need the raw results immediately, without awaiting
|
||||
// Promise.all(results):
|
||||
result.queries = queries;
|
||||
result.results = results;
|
||||
// If you decide to ignore the result Promise because you're using
|
||||
// result.queries and result.results instead, you shouldn't have to worry
|
||||
// about preventing uncaught rejections for the Promise.all result.
|
||||
result.catch(function (error) {
|
||||
globalThis.__DEV__ !== false && invariant.debug(17, error);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* Get all currently active `ObservableQuery` objects, in a `Map` keyed by
|
||||
* query ID strings.
|
||||
*
|
||||
* An "active" query is one that has observers and a `fetchPolicy` other than
|
||||
* "standby" or "cache-only".
|
||||
*
|
||||
* You can include all `ObservableQuery` objects (including the inactive ones)
|
||||
* by passing "all" instead of "active", or you can include just a subset of
|
||||
* active queries by passing an array of query names or DocumentNode objects.
|
||||
*/
|
||||
ApolloClient.prototype.getObservableQueries = function (include) {
|
||||
if (include === void 0) { include = "active"; }
|
||||
return this.queryManager.getObservableQueries(include);
|
||||
};
|
||||
/**
|
||||
* Exposes the cache's complete state, in a serializable format for later restoration.
|
||||
*/
|
||||
ApolloClient.prototype.extract = function (optimistic) {
|
||||
return this.cache.extract(optimistic);
|
||||
};
|
||||
/**
|
||||
* Replaces existing state in the cache (if any) with the values expressed by
|
||||
* `serializedState`.
|
||||
*
|
||||
* Called when hydrating a cache (server side rendering, or offline storage),
|
||||
* and also (potentially) during hot reloads.
|
||||
*/
|
||||
ApolloClient.prototype.restore = function (serializedState) {
|
||||
return this.cache.restore(serializedState);
|
||||
};
|
||||
/**
|
||||
* Add additional local resolvers.
|
||||
*/
|
||||
ApolloClient.prototype.addResolvers = function (resolvers) {
|
||||
this.localState.addResolvers(resolvers);
|
||||
};
|
||||
/**
|
||||
* Set (override existing) local resolvers.
|
||||
*/
|
||||
ApolloClient.prototype.setResolvers = function (resolvers) {
|
||||
this.localState.setResolvers(resolvers);
|
||||
};
|
||||
/**
|
||||
* Get all registered local resolvers.
|
||||
*/
|
||||
ApolloClient.prototype.getResolvers = function () {
|
||||
return this.localState.getResolvers();
|
||||
};
|
||||
/**
|
||||
* Set a custom local state fragment matcher.
|
||||
*/
|
||||
ApolloClient.prototype.setLocalStateFragmentMatcher = function (fragmentMatcher) {
|
||||
this.localState.setFragmentMatcher(fragmentMatcher);
|
||||
};
|
||||
/**
|
||||
* Define a new ApolloLink (or link chain) that Apollo Client will use.
|
||||
*/
|
||||
ApolloClient.prototype.setLink = function (newLink) {
|
||||
this.link = this.queryManager.link = newLink;
|
||||
};
|
||||
Object.defineProperty(ApolloClient.prototype, "defaultContext", {
|
||||
get: function () {
|
||||
return this.queryManager.defaultContext;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return ApolloClient;
|
||||
}());
|
||||
export { ApolloClient };
|
||||
if (globalThis.__DEV__ !== false) {
|
||||
ApolloClient.prototype.getMemoryInternals = getApolloClientMemoryInternals;
|
||||
}
|
||||
//# sourceMappingURL=ApolloClient.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/ApolloClient.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
65
graphql-subscription/node_modules/@apollo/client/core/LocalState.d.ts
generated
vendored
Normal file
65
graphql-subscription/node_modules/@apollo/client/core/LocalState.d.ts
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { DocumentNode, SelectionNode, FieldNode, ASTNode } from "graphql";
|
||||
import type { ApolloCache } from "../cache/index.js";
|
||||
import type { FragmentMap, StoreObject } from "../utilities/index.js";
|
||||
import type { ApolloClient } from "./ApolloClient.js";
|
||||
import type { Resolvers, OperationVariables } from "./types.js";
|
||||
import type { FetchResult } from "../link/core/index.js";
|
||||
export type Resolver = (rootValue?: any, args?: any, context?: any, info?: {
|
||||
field: FieldNode;
|
||||
fragmentMap: FragmentMap;
|
||||
}) => any;
|
||||
export type VariableMap = {
|
||||
[name: string]: any;
|
||||
};
|
||||
export type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean;
|
||||
export type ExecContext = {
|
||||
fragmentMap: FragmentMap;
|
||||
context: any;
|
||||
variables: VariableMap;
|
||||
fragmentMatcher: FragmentMatcher;
|
||||
defaultOperationType: string;
|
||||
exportedVariables: Record<string, any>;
|
||||
onlyRunForcedResolvers: boolean;
|
||||
selectionsToResolve: Set<SelectionNode>;
|
||||
};
|
||||
export type LocalStateOptions<TCacheShape> = {
|
||||
cache: ApolloCache<TCacheShape>;
|
||||
client?: ApolloClient<TCacheShape>;
|
||||
resolvers?: Resolvers | Resolvers[];
|
||||
fragmentMatcher?: FragmentMatcher;
|
||||
};
|
||||
export declare class LocalState<TCacheShape> {
|
||||
private cache;
|
||||
private client?;
|
||||
private resolvers?;
|
||||
private fragmentMatcher?;
|
||||
private selectionsToResolveCache;
|
||||
constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions<TCacheShape>);
|
||||
addResolvers(resolvers: Resolvers | Resolvers[]): void;
|
||||
setResolvers(resolvers: Resolvers | Resolvers[]): void;
|
||||
getResolvers(): Resolvers;
|
||||
runResolvers<TData>({ document, remoteResult, context, variables, onlyRunForcedResolvers, }: {
|
||||
document: DocumentNode | null;
|
||||
remoteResult: FetchResult<TData>;
|
||||
context?: Record<string, any>;
|
||||
variables?: Record<string, any>;
|
||||
onlyRunForcedResolvers?: boolean;
|
||||
}): Promise<FetchResult<TData>>;
|
||||
setFragmentMatcher(fragmentMatcher: FragmentMatcher): void;
|
||||
getFragmentMatcher(): FragmentMatcher | undefined;
|
||||
clientQuery(document: DocumentNode): DocumentNode | null;
|
||||
serverQuery(document: DocumentNode): DocumentNode | null;
|
||||
prepareContext(context?: Record<string, any>): {
|
||||
cache: ApolloCache<TCacheShape>;
|
||||
getCacheKey(obj: StoreObject): string | undefined;
|
||||
};
|
||||
addExportedVariables<TVars extends OperationVariables>(document: DocumentNode, variables?: TVars, context?: {}): Promise<TVars>;
|
||||
shouldForceResolvers(document: ASTNode): boolean;
|
||||
private buildRootValueFromCache;
|
||||
private resolveDocument;
|
||||
private resolveSelectionSet;
|
||||
private resolveField;
|
||||
private resolveSubSelectedArray;
|
||||
private collectSelectionsToResolve;
|
||||
}
|
||||
//# sourceMappingURL=LocalState.d.ts.map
|
||||
356
graphql-subscription/node_modules/@apollo/client/core/LocalState.js
generated
vendored
Normal file
356
graphql-subscription/node_modules/@apollo/client/core/LocalState.js
generated
vendored
Normal file
@@ -0,0 +1,356 @@
|
||||
import { __assign, __awaiter, __generator } from "tslib";
|
||||
import { invariant } from "../utilities/globals/index.js";
|
||||
import { visit, BREAK, isSelectionNode } from "graphql";
|
||||
import { argumentsObjectFromField, buildQueryFromSelectionSet, createFragmentMap, getFragmentDefinitions, getMainDefinition, hasDirectives, isField, isInlineFragment, mergeDeep, mergeDeepArray, removeClientSetsFromDocument, resultKeyNameFromField, shouldInclude, } from "../utilities/index.js";
|
||||
import { cacheSlot } from "../cache/index.js";
|
||||
var LocalState = /** @class */ (function () {
|
||||
function LocalState(_a) {
|
||||
var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
|
||||
this.selectionsToResolveCache = new WeakMap();
|
||||
this.cache = cache;
|
||||
if (client) {
|
||||
this.client = client;
|
||||
}
|
||||
if (resolvers) {
|
||||
this.addResolvers(resolvers);
|
||||
}
|
||||
if (fragmentMatcher) {
|
||||
this.setFragmentMatcher(fragmentMatcher);
|
||||
}
|
||||
}
|
||||
LocalState.prototype.addResolvers = function (resolvers) {
|
||||
var _this = this;
|
||||
this.resolvers = this.resolvers || {};
|
||||
if (Array.isArray(resolvers)) {
|
||||
resolvers.forEach(function (resolverGroup) {
|
||||
_this.resolvers = mergeDeep(_this.resolvers, resolverGroup);
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.resolvers = mergeDeep(this.resolvers, resolvers);
|
||||
}
|
||||
};
|
||||
LocalState.prototype.setResolvers = function (resolvers) {
|
||||
this.resolvers = {};
|
||||
this.addResolvers(resolvers);
|
||||
};
|
||||
LocalState.prototype.getResolvers = function () {
|
||||
return this.resolvers || {};
|
||||
};
|
||||
// Run local client resolvers against the incoming query and remote data.
|
||||
// Locally resolved field values are merged with the incoming remote data,
|
||||
// and returned. Note that locally resolved fields will overwrite
|
||||
// remote data using the same field name.
|
||||
LocalState.prototype.runResolvers = function (_a) {
|
||||
var document = _a.document, remoteResult = _a.remoteResult, context = _a.context, variables = _a.variables, _b = _a.onlyRunForcedResolvers, onlyRunForcedResolvers = _b === void 0 ? false : _b;
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_c) {
|
||||
if (document) {
|
||||
return [2 /*return*/, this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (__assign(__assign({}, remoteResult), { data: localResult.result })); })];
|
||||
}
|
||||
return [2 /*return*/, remoteResult];
|
||||
});
|
||||
});
|
||||
};
|
||||
LocalState.prototype.setFragmentMatcher = function (fragmentMatcher) {
|
||||
this.fragmentMatcher = fragmentMatcher;
|
||||
};
|
||||
LocalState.prototype.getFragmentMatcher = function () {
|
||||
return this.fragmentMatcher;
|
||||
};
|
||||
// Client queries contain everything in the incoming document (if a @client
|
||||
// directive is found).
|
||||
LocalState.prototype.clientQuery = function (document) {
|
||||
if (hasDirectives(["client"], document)) {
|
||||
if (this.resolvers) {
|
||||
return document;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
// Server queries are stripped of all @client based selection sets.
|
||||
LocalState.prototype.serverQuery = function (document) {
|
||||
return removeClientSetsFromDocument(document);
|
||||
};
|
||||
LocalState.prototype.prepareContext = function (context) {
|
||||
var cache = this.cache;
|
||||
return __assign(__assign({}, context), { cache: cache,
|
||||
// Getting an entry's cache key is useful for local state resolvers.
|
||||
getCacheKey: function (obj) {
|
||||
return cache.identify(obj);
|
||||
} });
|
||||
};
|
||||
// To support `@client @export(as: "someVar")` syntax, we'll first resolve
|
||||
// @client @export fields locally, then pass the resolved values back to be
|
||||
// used alongside the original operation variables.
|
||||
LocalState.prototype.addExportedVariables = function (document, variables, context) {
|
||||
if (variables === void 0) { variables = {}; }
|
||||
if (context === void 0) { context = {}; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
if (document) {
|
||||
return [2 /*return*/, this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (__assign(__assign({}, variables), data.exportedVariables)); })];
|
||||
}
|
||||
return [2 /*return*/, __assign({}, variables)];
|
||||
});
|
||||
});
|
||||
};
|
||||
LocalState.prototype.shouldForceResolvers = function (document) {
|
||||
var forceResolvers = false;
|
||||
visit(document, {
|
||||
Directive: {
|
||||
enter: function (node) {
|
||||
if (node.name.value === "client" && node.arguments) {
|
||||
forceResolvers = node.arguments.some(function (arg) {
|
||||
return arg.name.value === "always" &&
|
||||
arg.value.kind === "BooleanValue" &&
|
||||
arg.value.value === true;
|
||||
});
|
||||
if (forceResolvers) {
|
||||
return BREAK;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
return forceResolvers;
|
||||
};
|
||||
// Query the cache and return matching data.
|
||||
LocalState.prototype.buildRootValueFromCache = function (document, variables) {
|
||||
return this.cache.diff({
|
||||
query: buildQueryFromSelectionSet(document),
|
||||
variables: variables,
|
||||
returnPartialData: true,
|
||||
optimistic: false,
|
||||
}).result;
|
||||
};
|
||||
LocalState.prototype.resolveDocument = function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
|
||||
if (context === void 0) { context = {}; }
|
||||
if (variables === void 0) { variables = {}; }
|
||||
if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
|
||||
if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
|
||||
return __generator(this, function (_b) {
|
||||
mainDefinition = getMainDefinition(document);
|
||||
fragments = getFragmentDefinitions(document);
|
||||
fragmentMap = createFragmentMap(fragments);
|
||||
selectionsToResolve = this.collectSelectionsToResolve(mainDefinition, fragmentMap);
|
||||
definitionOperation = mainDefinition.operation;
|
||||
defaultOperationType = definitionOperation ?
|
||||
definitionOperation.charAt(0).toUpperCase() +
|
||||
definitionOperation.slice(1)
|
||||
: "Query";
|
||||
_a = this, cache = _a.cache, client = _a.client;
|
||||
execContext = {
|
||||
fragmentMap: fragmentMap,
|
||||
context: __assign(__assign({}, context), { cache: cache, client: client }),
|
||||
variables: variables,
|
||||
fragmentMatcher: fragmentMatcher,
|
||||
defaultOperationType: defaultOperationType,
|
||||
exportedVariables: {},
|
||||
selectionsToResolve: selectionsToResolve,
|
||||
onlyRunForcedResolvers: onlyRunForcedResolvers,
|
||||
};
|
||||
isClientFieldDescendant = false;
|
||||
return [2 /*return*/, this.resolveSelectionSet(mainDefinition.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (result) { return ({
|
||||
result: result,
|
||||
exportedVariables: execContext.exportedVariables,
|
||||
}); })];
|
||||
});
|
||||
});
|
||||
};
|
||||
LocalState.prototype.resolveSelectionSet = function (selectionSet, isClientFieldDescendant, rootValue, execContext) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var fragmentMap, context, variables, resultsToMerge, execute;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
fragmentMap = execContext.fragmentMap, context = execContext.context, variables = execContext.variables;
|
||||
resultsToMerge = [rootValue];
|
||||
execute = function (selection) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var fragment, typeCondition;
|
||||
return __generator(this, function (_a) {
|
||||
if (!isClientFieldDescendant &&
|
||||
!execContext.selectionsToResolve.has(selection)) {
|
||||
// Skip selections without @client directives
|
||||
// (still processing if one of the ancestors or one of the child fields has @client directive)
|
||||
return [2 /*return*/];
|
||||
}
|
||||
if (!shouldInclude(selection, variables)) {
|
||||
// Skip this entirely.
|
||||
return [2 /*return*/];
|
||||
}
|
||||
if (isField(selection)) {
|
||||
return [2 /*return*/, this.resolveField(selection, isClientFieldDescendant, rootValue, execContext).then(function (fieldResult) {
|
||||
var _a;
|
||||
if (typeof fieldResult !== "undefined") {
|
||||
resultsToMerge.push((_a = {},
|
||||
_a[resultKeyNameFromField(selection)] = fieldResult,
|
||||
_a));
|
||||
}
|
||||
})];
|
||||
}
|
||||
if (isInlineFragment(selection)) {
|
||||
fragment = selection;
|
||||
}
|
||||
else {
|
||||
// This is a named fragment.
|
||||
fragment = fragmentMap[selection.name.value];
|
||||
invariant(fragment, 18, selection.name.value);
|
||||
}
|
||||
if (fragment && fragment.typeCondition) {
|
||||
typeCondition = fragment.typeCondition.name.value;
|
||||
if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
|
||||
return [2 /*return*/, this.resolveSelectionSet(fragment.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (fragmentResult) {
|
||||
resultsToMerge.push(fragmentResult);
|
||||
})];
|
||||
}
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
}); };
|
||||
return [2 /*return*/, Promise.all(selectionSet.selections.map(execute)).then(function () {
|
||||
return mergeDeepArray(resultsToMerge);
|
||||
})];
|
||||
});
|
||||
});
|
||||
};
|
||||
LocalState.prototype.resolveField = function (field, isClientFieldDescendant, rootValue, execContext) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
if (!rootValue) {
|
||||
return [2 /*return*/, null];
|
||||
}
|
||||
variables = execContext.variables;
|
||||
fieldName = field.name.value;
|
||||
aliasedFieldName = resultKeyNameFromField(field);
|
||||
aliasUsed = fieldName !== aliasedFieldName;
|
||||
defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
|
||||
resultPromise = Promise.resolve(defaultResult);
|
||||
// Usually all local resolvers are run when passing through here, but
|
||||
// if we've specifically identified that we only want to run forced
|
||||
// resolvers (that is, resolvers for fields marked with
|
||||
// `@client(always: true)`), then we'll skip running non-forced resolvers.
|
||||
if (!execContext.onlyRunForcedResolvers ||
|
||||
this.shouldForceResolvers(field)) {
|
||||
resolverType = rootValue.__typename || execContext.defaultOperationType;
|
||||
resolverMap = this.resolvers && this.resolvers[resolverType];
|
||||
if (resolverMap) {
|
||||
resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
|
||||
if (resolve) {
|
||||
resultPromise = Promise.resolve(
|
||||
// In case the resolve function accesses reactive variables,
|
||||
// set cacheSlot to the current cache instance.
|
||||
cacheSlot.withValue(this.cache, resolve, [
|
||||
rootValue,
|
||||
argumentsObjectFromField(field, variables),
|
||||
execContext.context,
|
||||
{ field: field, fragmentMap: execContext.fragmentMap },
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return [2 /*return*/, resultPromise.then(function (result) {
|
||||
var _a, _b;
|
||||
if (result === void 0) { result = defaultResult; }
|
||||
// If an @export directive is associated with the current field, store
|
||||
// the `as` export variable name and current result for later use.
|
||||
if (field.directives) {
|
||||
field.directives.forEach(function (directive) {
|
||||
if (directive.name.value === "export" && directive.arguments) {
|
||||
directive.arguments.forEach(function (arg) {
|
||||
if (arg.name.value === "as" && arg.value.kind === "StringValue") {
|
||||
execContext.exportedVariables[arg.value.value] = result;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// Handle all scalar types here.
|
||||
if (!field.selectionSet) {
|
||||
return result;
|
||||
}
|
||||
// From here down, the field has a selection set, which means it's trying
|
||||
// to query a GraphQLObjectType.
|
||||
if (result == null) {
|
||||
// Basically any field in a GraphQL response can be null, or missing
|
||||
return result;
|
||||
}
|
||||
var isClientField = (_b = (_a = field.directives) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.name.value === "client"; })) !== null && _b !== void 0 ? _b : false;
|
||||
if (Array.isArray(result)) {
|
||||
return _this.resolveSubSelectedArray(field, isClientFieldDescendant || isClientField, result, execContext);
|
||||
}
|
||||
// Returned value is an object, and the query has a sub-selection. Recurse.
|
||||
if (field.selectionSet) {
|
||||
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant || isClientField, result, execContext);
|
||||
}
|
||||
})];
|
||||
});
|
||||
});
|
||||
};
|
||||
LocalState.prototype.resolveSubSelectedArray = function (field, isClientFieldDescendant, result, execContext) {
|
||||
var _this = this;
|
||||
return Promise.all(result.map(function (item) {
|
||||
if (item === null) {
|
||||
return null;
|
||||
}
|
||||
// This is a nested array, recurse.
|
||||
if (Array.isArray(item)) {
|
||||
return _this.resolveSubSelectedArray(field, isClientFieldDescendant, item, execContext);
|
||||
}
|
||||
// This is an object, run the selection set on it.
|
||||
if (field.selectionSet) {
|
||||
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant, item, execContext);
|
||||
}
|
||||
}));
|
||||
};
|
||||
// Collect selection nodes on paths from document root down to all @client directives.
|
||||
// This function takes into account transitive fragment spreads.
|
||||
// Complexity equals to a single `visit` over the full document.
|
||||
LocalState.prototype.collectSelectionsToResolve = function (mainDefinition, fragmentMap) {
|
||||
var isSingleASTNode = function (node) { return !Array.isArray(node); };
|
||||
var selectionsToResolveCache = this.selectionsToResolveCache;
|
||||
function collectByDefinition(definitionNode) {
|
||||
if (!selectionsToResolveCache.has(definitionNode)) {
|
||||
var matches_1 = new Set();
|
||||
selectionsToResolveCache.set(definitionNode, matches_1);
|
||||
visit(definitionNode, {
|
||||
Directive: function (node, _, __, ___, ancestors) {
|
||||
if (node.name.value === "client") {
|
||||
ancestors.forEach(function (node) {
|
||||
if (isSingleASTNode(node) && isSelectionNode(node)) {
|
||||
matches_1.add(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
FragmentSpread: function (spread, _, __, ___, ancestors) {
|
||||
var fragment = fragmentMap[spread.name.value];
|
||||
invariant(fragment, 19, spread.name.value);
|
||||
var fragmentSelections = collectByDefinition(fragment);
|
||||
if (fragmentSelections.size > 0) {
|
||||
// Fragment for this spread contains @client directive (either directly or transitively)
|
||||
// Collect selection nodes on paths from the root down to fields with the @client directive
|
||||
ancestors.forEach(function (node) {
|
||||
if (isSingleASTNode(node) && isSelectionNode(node)) {
|
||||
matches_1.add(node);
|
||||
}
|
||||
});
|
||||
matches_1.add(spread);
|
||||
fragmentSelections.forEach(function (selection) {
|
||||
matches_1.add(selection);
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
return selectionsToResolveCache.get(definitionNode);
|
||||
}
|
||||
return collectByDefinition(mainDefinition);
|
||||
};
|
||||
return LocalState;
|
||||
}());
|
||||
export { LocalState };
|
||||
//# sourceMappingURL=LocalState.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/LocalState.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/LocalState.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
130
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.d.ts
generated
vendored
Normal file
130
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.d.ts
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
import { NetworkStatus } from "./networkStatus.js";
|
||||
import type { Concast, Observer, ObservableSubscription } from "../utilities/index.js";
|
||||
import { Observable } from "../utilities/index.js";
|
||||
import type { ApolloError } from "../errors/index.js";
|
||||
import type { QueryManager } from "./QueryManager.js";
|
||||
import type { ApolloQueryResult, OperationVariables, TypedDocumentNode } from "./types.js";
|
||||
import type { WatchQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions } from "./watchQueryOptions.js";
|
||||
import type { QueryInfo } from "./QueryInfo.js";
|
||||
import type { MissingFieldError } from "../cache/index.js";
|
||||
import type { MissingTree } from "../cache/core/types/common.js";
|
||||
export interface FetchMoreOptions<TData = any, TVariables = OperationVariables> {
|
||||
updateQuery?: (previousQueryResult: TData, options: {
|
||||
fetchMoreResult?: TData;
|
||||
variables?: TVariables;
|
||||
}) => TData;
|
||||
}
|
||||
export interface UpdateQueryOptions<TVariables> {
|
||||
variables?: TVariables;
|
||||
}
|
||||
export declare class ObservableQuery<TData = any, TVariables extends OperationVariables = OperationVariables> extends Observable<ApolloQueryResult<TData>> {
|
||||
readonly options: WatchQueryOptions<TVariables, TData>;
|
||||
readonly queryId: string;
|
||||
readonly queryName?: string;
|
||||
get query(): TypedDocumentNode<TData, TVariables>;
|
||||
/**
|
||||
* An object containing the variables that were provided for the query.
|
||||
*/
|
||||
get variables(): TVariables | undefined;
|
||||
private isTornDown;
|
||||
private queryManager;
|
||||
private observers;
|
||||
private subscriptions;
|
||||
private waitForOwnResult;
|
||||
private last?;
|
||||
private lastQuery?;
|
||||
private queryInfo;
|
||||
private concast?;
|
||||
private observer?;
|
||||
private pollingInfo?;
|
||||
constructor({ queryManager, queryInfo, options, }: {
|
||||
queryManager: QueryManager<any>;
|
||||
queryInfo: QueryInfo;
|
||||
options: WatchQueryOptions<TVariables, TData>;
|
||||
});
|
||||
result(): Promise<ApolloQueryResult<TData>>;
|
||||
/** @internal */
|
||||
resetDiff(): void;
|
||||
getCurrentResult(saveAsLastResult?: boolean): ApolloQueryResult<TData>;
|
||||
isDifferentFromLastResult(newResult: ApolloQueryResult<TData>, variables?: TVariables): boolean | undefined;
|
||||
private getLast;
|
||||
getLastResult(variablesMustMatch?: boolean): ApolloQueryResult<TData> | undefined;
|
||||
getLastError(variablesMustMatch?: boolean): ApolloError | undefined;
|
||||
resetLastResults(): void;
|
||||
resetQueryStoreErrors(): void;
|
||||
/**
|
||||
* Update the variables of this observable query, and fetch the new results.
|
||||
* This method should be preferred over `setVariables` in most use cases.
|
||||
*
|
||||
* @param variables - The new set of variables. If there are missing variables,
|
||||
* the previous values of those variables will be used.
|
||||
*/
|
||||
refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<TData>>;
|
||||
/**
|
||||
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
||||
*/
|
||||
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
||||
updateQuery?: (previousQueryResult: TData, options: {
|
||||
fetchMoreResult: TFetchData;
|
||||
variables: TFetchVars;
|
||||
}) => TData;
|
||||
}): Promise<ApolloQueryResult<TFetchData>>;
|
||||
/**
|
||||
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
||||
*
|
||||
* This function returns _another_ function that you can call to terminate the subscription.
|
||||
*/
|
||||
subscribeToMore<TSubscriptionData = TData, TSubscriptionVariables extends OperationVariables = TVariables>(options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>): () => void;
|
||||
setOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): Promise<ApolloQueryResult<TData>>;
|
||||
silentSetOptions(newOptions: Partial<WatchQueryOptions<TVariables, TData>>): void;
|
||||
/**
|
||||
* Update the variables of this observable query, and fetch the new results
|
||||
* if they've changed. Most users should prefer `refetch` instead of
|
||||
* `setVariables` in order to to be properly notified of results even when
|
||||
* they come from the cache.
|
||||
*
|
||||
* Note: the `next` callback will *not* fire if the variables have not changed
|
||||
* or if the result is coming from cache.
|
||||
*
|
||||
* Note: the promise will return the old results immediately if the variables
|
||||
* have not changed.
|
||||
*
|
||||
* Note: the promise will return null immediately if the query is not active
|
||||
* (there are no subscribers).
|
||||
*
|
||||
* @param variables - The new set of variables. If there are missing variables,
|
||||
* the previous values of those variables will be used.
|
||||
*/
|
||||
setVariables(variables: TVariables): Promise<ApolloQueryResult<TData> | void>;
|
||||
/**
|
||||
* A function that enables you to update the query's cached result without executing a followup GraphQL operation.
|
||||
*
|
||||
* See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
|
||||
*/
|
||||
updateQuery<TVars extends OperationVariables = TVariables>(mapFn: (previousQueryResult: TData, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => TData): void;
|
||||
/**
|
||||
* A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
|
||||
*/
|
||||
startPolling(pollInterval: number): void;
|
||||
/**
|
||||
* A function that instructs the query to stop polling after a previous call to `startPolling`.
|
||||
*/
|
||||
stopPolling(): void;
|
||||
private applyNextFetchPolicy;
|
||||
private fetch;
|
||||
private updatePolling;
|
||||
private updateLastResult;
|
||||
reobserveAsConcast(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Concast<ApolloQueryResult<TData>>;
|
||||
reobserve(newOptions?: Partial<WatchQueryOptions<TVariables, TData>>, newNetworkStatus?: NetworkStatus): Promise<ApolloQueryResult<TData>>;
|
||||
resubscribeAfterError(onNext: (value: ApolloQueryResult<TData>) => void, onError?: (error: any) => void, onComplete?: () => void): ObservableSubscription;
|
||||
resubscribeAfterError(observer: Observer<ApolloQueryResult<TData>>): ObservableSubscription;
|
||||
private observe;
|
||||
private reportResult;
|
||||
private reportError;
|
||||
hasObservers(): boolean;
|
||||
private tearDownQuery;
|
||||
private transformDocument;
|
||||
}
|
||||
export declare function reobserveCacheFirst<TData, TVars extends OperationVariables>(obsQuery: ObservableQuery<TData, TVars>): Promise<ApolloQueryResult<TData>>;
|
||||
export declare function logMissingFieldErrors(missing: MissingFieldError[] | MissingTree | undefined): void;
|
||||
//# sourceMappingURL=ObservableQuery.d.ts.map
|
||||
803
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.js
generated
vendored
Normal file
803
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.js
generated
vendored
Normal file
@@ -0,0 +1,803 @@
|
||||
import { __assign, __extends } from "tslib";
|
||||
import { invariant } from "../utilities/globals/index.js";
|
||||
import { equal } from "@wry/equality";
|
||||
import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js";
|
||||
import { cloneDeep, compact, getOperationDefinition, Observable, iterateObserversSafely, fixObservableSubclass, getQueryDefinition, } from "../utilities/index.js";
|
||||
import { equalByQuery } from "./equalByQuery.js";
|
||||
var assign = Object.assign, hasOwnProperty = Object.hasOwnProperty;
|
||||
var ObservableQuery = /** @class */ (function (_super) {
|
||||
__extends(ObservableQuery, _super);
|
||||
function ObservableQuery(_a) {
|
||||
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
||||
var _this = _super.call(this, function (observer) {
|
||||
// Zen Observable has its own error function, so in order to log correctly
|
||||
// we need to provide a custom error callback.
|
||||
try {
|
||||
var subObserver = observer._subscription._observer;
|
||||
if (subObserver && !subObserver.error) {
|
||||
subObserver.error = defaultSubscriptionObserverErrorCallback;
|
||||
}
|
||||
}
|
||||
catch (_a) { }
|
||||
var first = !_this.observers.size;
|
||||
_this.observers.add(observer);
|
||||
// Deliver most recent error or result.
|
||||
var last = _this.last;
|
||||
if (last && last.error) {
|
||||
observer.error && observer.error(last.error);
|
||||
}
|
||||
else if (last && last.result) {
|
||||
observer.next && observer.next(last.result);
|
||||
}
|
||||
// Initiate observation of this query if it hasn't been reported to
|
||||
// the QueryManager yet.
|
||||
if (first) {
|
||||
// Blindly catching here prevents unhandled promise rejections,
|
||||
// and is safe because the ObservableQuery handles this error with
|
||||
// this.observer.error, so we're not just swallowing the error by
|
||||
// ignoring it here.
|
||||
_this.reobserve().catch(function () { });
|
||||
}
|
||||
return function () {
|
||||
if (_this.observers.delete(observer) && !_this.observers.size) {
|
||||
_this.tearDownQuery();
|
||||
}
|
||||
};
|
||||
}) || this;
|
||||
_this.observers = new Set();
|
||||
_this.subscriptions = new Set();
|
||||
// related classes
|
||||
_this.queryInfo = queryInfo;
|
||||
_this.queryManager = queryManager;
|
||||
// active state
|
||||
_this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy);
|
||||
_this.isTornDown = false;
|
||||
var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
||||
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e,
|
||||
// Make sure we don't store "standby" as the initialFetchPolicy.
|
||||
_f = options.initialFetchPolicy,
|
||||
// Make sure we don't store "standby" as the initialFetchPolicy.
|
||||
initialFetchPolicy = _f === void 0 ? fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy) : _f;
|
||||
_this.options = __assign(__assign({}, options), {
|
||||
// Remember the initial options.fetchPolicy so we can revert back to this
|
||||
// policy when variables change. This information can also be specified
|
||||
// (or overridden) by providing options.initialFetchPolicy explicitly.
|
||||
initialFetchPolicy: initialFetchPolicy,
|
||||
// This ensures this.options.fetchPolicy always has a string value, in
|
||||
// case options.fetchPolicy was not provided.
|
||||
fetchPolicy: fetchPolicy });
|
||||
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
||||
var opDef = getOperationDefinition(_this.query);
|
||||
_this.queryName = opDef && opDef.name && opDef.name.value;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(ObservableQuery.prototype, "query", {
|
||||
// The `query` computed property will always reflect the document transformed
|
||||
// by the last run query. `this.options.query` will always reflect the raw
|
||||
// untransformed query to ensure document transforms with runtime conditionals
|
||||
// are run on the original document.
|
||||
get: function () {
|
||||
return this.lastQuery || this.options.query;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
||||
// Computed shorthand for this.options.variables, preserved for
|
||||
// backwards compatibility.
|
||||
/**
|
||||
* An object containing the variables that were provided for the query.
|
||||
*/
|
||||
get: function () {
|
||||
return this.options.variables;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
ObservableQuery.prototype.result = function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
// TODO: this code doesn’t actually make sense insofar as the observer
|
||||
// will never exist in this.observers due how zen-observable wraps observables.
|
||||
// https://github.com/zenparsing/zen-observable/blob/master/src/Observable.js#L169
|
||||
var observer = {
|
||||
next: function (result) {
|
||||
resolve(result);
|
||||
// Stop the query within the QueryManager if we can before
|
||||
// this function returns.
|
||||
//
|
||||
// We do this in order to prevent observers piling up within
|
||||
// the QueryManager. Notice that we only fully unsubscribe
|
||||
// from the subscription in a setTimeout(..., 0) call. This call can
|
||||
// actually be handled by the browser at a much later time. If queries
|
||||
// are fired in the meantime, observers that should have been removed
|
||||
// from the QueryManager will continue to fire, causing an unnecessary
|
||||
// performance hit.
|
||||
_this.observers.delete(observer);
|
||||
if (!_this.observers.size) {
|
||||
_this.queryManager.removeQuery(_this.queryId);
|
||||
}
|
||||
setTimeout(function () {
|
||||
subscription.unsubscribe();
|
||||
}, 0);
|
||||
},
|
||||
error: reject,
|
||||
};
|
||||
var subscription = _this.subscribe(observer);
|
||||
});
|
||||
};
|
||||
/** @internal */
|
||||
ObservableQuery.prototype.resetDiff = function () {
|
||||
this.queryInfo.resetDiff();
|
||||
};
|
||||
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
||||
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
||||
// Use the last result as long as the variables match this.variables.
|
||||
var lastResult = this.getLastResult(true);
|
||||
var networkStatus = this.queryInfo.networkStatus ||
|
||||
(lastResult && lastResult.networkStatus) ||
|
||||
NetworkStatus.ready;
|
||||
var result = __assign(__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
||||
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
||||
if (
|
||||
// These fetch policies should never deliver data from the cache, unless
|
||||
// redelivering a previously delivered result.
|
||||
skipCacheDataFor(fetchPolicy) ||
|
||||
// If this.options.query has @client(always: true) fields, we cannot
|
||||
// trust diff.result, since it was read from the cache without running
|
||||
// local resolvers (and it's too late to run resolvers now, since we must
|
||||
// return a result synchronously).
|
||||
this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) {
|
||||
// Fall through.
|
||||
}
|
||||
else if (this.waitForOwnResult) {
|
||||
// This would usually be a part of `QueryInfo.getDiff()`.
|
||||
// which we skip in the waitForOwnResult case since we are not
|
||||
// interested in the diff.
|
||||
this.queryInfo["updateWatch"]();
|
||||
}
|
||||
else {
|
||||
var diff = this.queryInfo.getDiff();
|
||||
if (diff.complete || this.options.returnPartialData) {
|
||||
result.data = diff.result;
|
||||
}
|
||||
if (equal(result.data, {})) {
|
||||
result.data = void 0;
|
||||
}
|
||||
if (diff.complete) {
|
||||
// Similar to setting result.partial to false, but taking advantage of the
|
||||
// falsiness of missing fields.
|
||||
delete result.partial;
|
||||
// If the diff is complete, and we're using a FetchPolicy that
|
||||
// terminates after a complete cache read, we can assume the next result
|
||||
// we receive will have NetworkStatus.ready and !loading.
|
||||
if (diff.complete &&
|
||||
result.networkStatus === NetworkStatus.loading &&
|
||||
(fetchPolicy === "cache-first" || fetchPolicy === "cache-only")) {
|
||||
result.networkStatus = NetworkStatus.ready;
|
||||
result.loading = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.partial = true;
|
||||
}
|
||||
if (globalThis.__DEV__ !== false &&
|
||||
!diff.complete &&
|
||||
!this.options.partialRefetch &&
|
||||
!result.loading &&
|
||||
!result.data &&
|
||||
!result.error) {
|
||||
logMissingFieldErrors(diff.missing);
|
||||
}
|
||||
}
|
||||
if (saveAsLastResult) {
|
||||
this.updateLastResult(result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Compares newResult to the snapshot we took of this.lastResult when it was
|
||||
// first received.
|
||||
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
|
||||
if (!this.last) {
|
||||
return true;
|
||||
}
|
||||
var resultIsDifferent = this.queryManager.getDocumentInfo(this.query).hasNonreactiveDirective ?
|
||||
!equalByQuery(this.query, this.last.result, newResult, this.variables)
|
||||
: !equal(this.last.result, newResult);
|
||||
return (resultIsDifferent || (variables && !equal(this.last.variables, variables)));
|
||||
};
|
||||
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
||||
var last = this.last;
|
||||
if (last &&
|
||||
last[key] &&
|
||||
(!variablesMustMatch || equal(last.variables, this.variables))) {
|
||||
return last[key];
|
||||
}
|
||||
};
|
||||
ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
|
||||
return this.getLast("result", variablesMustMatch);
|
||||
};
|
||||
ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
|
||||
return this.getLast("error", variablesMustMatch);
|
||||
};
|
||||
ObservableQuery.prototype.resetLastResults = function () {
|
||||
delete this.last;
|
||||
this.isTornDown = false;
|
||||
};
|
||||
ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
||||
this.queryManager.resetErrors(this.queryId);
|
||||
};
|
||||
/**
|
||||
* Update the variables of this observable query, and fetch the new results.
|
||||
* This method should be preferred over `setVariables` in most use cases.
|
||||
*
|
||||
* @param variables - The new set of variables. If there are missing variables,
|
||||
* the previous values of those variables will be used.
|
||||
*/
|
||||
ObservableQuery.prototype.refetch = function (variables) {
|
||||
var _a;
|
||||
var reobserveOptions = {
|
||||
// Always disable polling for refetches.
|
||||
pollInterval: 0,
|
||||
};
|
||||
// Unless the provided fetchPolicy always consults the network
|
||||
// (no-cache, network-only, or cache-and-network), override it with
|
||||
// network-only to force the refetch for this fetchQuery call.
|
||||
var fetchPolicy = this.options.fetchPolicy;
|
||||
if (fetchPolicy === "cache-and-network") {
|
||||
reobserveOptions.fetchPolicy = fetchPolicy;
|
||||
}
|
||||
else if (fetchPolicy === "no-cache") {
|
||||
reobserveOptions.fetchPolicy = "no-cache";
|
||||
}
|
||||
else {
|
||||
reobserveOptions.fetchPolicy = "network-only";
|
||||
}
|
||||
if (globalThis.__DEV__ !== false && variables && hasOwnProperty.call(variables, "variables")) {
|
||||
var queryDef = getQueryDefinition(this.query);
|
||||
var vars = queryDef.variableDefinitions;
|
||||
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
||||
globalThis.__DEV__ !== false && invariant.warn(
|
||||
20,
|
||||
variables,
|
||||
((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || queryDef
|
||||
);
|
||||
}
|
||||
}
|
||||
if (variables && !equal(this.options.variables, variables)) {
|
||||
// Update the existing options with new variables
|
||||
reobserveOptions.variables = this.options.variables = __assign(__assign({}, this.options.variables), variables);
|
||||
}
|
||||
this.queryInfo.resetLastWrite();
|
||||
return this.reobserve(reobserveOptions, NetworkStatus.refetch);
|
||||
};
|
||||
/**
|
||||
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
||||
*/
|
||||
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
||||
var _this = this;
|
||||
var combinedOptions = __assign(__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : (__assign(__assign(__assign(__assign({}, this.options), { query: this.options.query }), fetchMoreOptions), { variables: __assign(__assign({}, this.options.variables), fetchMoreOptions.variables) })))), {
|
||||
// The fetchMore request goes immediately to the network and does
|
||||
// not automatically write its result to the cache (hence no-cache
|
||||
// instead of network-only), because we allow the caller of
|
||||
// fetchMore to provide an updateQuery callback that determines how
|
||||
// the data gets written to the cache.
|
||||
fetchPolicy: "no-cache" });
|
||||
combinedOptions.query = this.transformDocument(combinedOptions.query);
|
||||
var qid = this.queryManager.generateQueryId();
|
||||
// If a temporary query is passed to `fetchMore`, we don't want to store
|
||||
// it as the last query result since it may be an optimized query for
|
||||
// pagination. We will however run the transforms on the original document
|
||||
// as well as the document passed in `fetchMoreOptions` to ensure the cache
|
||||
// uses the most up-to-date document which may rely on runtime conditionals.
|
||||
this.lastQuery =
|
||||
fetchMoreOptions.query ?
|
||||
this.transformDocument(this.options.query)
|
||||
: combinedOptions.query;
|
||||
// Simulate a loading result for the original query with
|
||||
// result.networkStatus === NetworkStatus.fetchMore.
|
||||
var queryInfo = this.queryInfo;
|
||||
var originalNetworkStatus = queryInfo.networkStatus;
|
||||
queryInfo.networkStatus = NetworkStatus.fetchMore;
|
||||
if (combinedOptions.notifyOnNetworkStatusChange) {
|
||||
this.observe();
|
||||
}
|
||||
var updatedQuerySet = new Set();
|
||||
return this.queryManager
|
||||
.fetchQuery(qid, combinedOptions, NetworkStatus.fetchMore)
|
||||
.then(function (fetchMoreResult) {
|
||||
_this.queryManager.removeQuery(qid);
|
||||
if (queryInfo.networkStatus === NetworkStatus.fetchMore) {
|
||||
queryInfo.networkStatus = originalNetworkStatus;
|
||||
}
|
||||
// Performing this cache update inside a cache.batch transaction ensures
|
||||
// any affected cache.watch watchers are notified at most once about any
|
||||
// updates. Most watchers will be using the QueryInfo class, which
|
||||
// responds to notifications by calling reobserveCacheFirst to deliver
|
||||
// fetchMore cache results back to this ObservableQuery.
|
||||
_this.queryManager.cache.batch({
|
||||
update: function (cache) {
|
||||
var updateQuery = fetchMoreOptions.updateQuery;
|
||||
if (updateQuery) {
|
||||
cache.updateQuery({
|
||||
query: _this.query,
|
||||
variables: _this.variables,
|
||||
returnPartialData: true,
|
||||
optimistic: false,
|
||||
}, function (previous) {
|
||||
return updateQuery(previous, {
|
||||
fetchMoreResult: fetchMoreResult.data,
|
||||
variables: combinedOptions.variables,
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
// If we're using a field policy instead of updateQuery, the only
|
||||
// thing we need to do is write the new data to the cache using
|
||||
// combinedOptions.variables (instead of this.variables, which is
|
||||
// what this.updateQuery uses, because it works by abusing the
|
||||
// original field value, keyed by the original variables).
|
||||
cache.writeQuery({
|
||||
query: combinedOptions.query,
|
||||
variables: combinedOptions.variables,
|
||||
data: fetchMoreResult.data,
|
||||
});
|
||||
}
|
||||
},
|
||||
onWatchUpdated: function (watch) {
|
||||
// Record the DocumentNode associated with any watched query whose
|
||||
// data were updated by the cache writes above.
|
||||
updatedQuerySet.add(watch.query);
|
||||
},
|
||||
});
|
||||
return fetchMoreResult;
|
||||
})
|
||||
.finally(function () {
|
||||
// In case the cache writes above did not generate a broadcast
|
||||
// notification (which would have been intercepted by onWatchUpdated),
|
||||
// likely because the written data were the same as what was already in
|
||||
// the cache, we still want fetchMore to deliver its final loading:false
|
||||
// result with the unchanged data.
|
||||
if (!updatedQuerySet.has(_this.query)) {
|
||||
reobserveCacheFirst(_this);
|
||||
}
|
||||
});
|
||||
};
|
||||
// XXX the subscription variables are separate from the query variables.
|
||||
// if you want to update subscription variables, right now you have to do that separately,
|
||||
// and you can only do it by stopping the subscription and then subscribing again with new variables.
|
||||
/**
|
||||
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
||||
*
|
||||
* This function returns _another_ function that you can call to terminate the subscription.
|
||||
*/
|
||||
ObservableQuery.prototype.subscribeToMore = function (options) {
|
||||
var _this = this;
|
||||
var subscription = this.queryManager
|
||||
.startGraphQLSubscription({
|
||||
query: options.document,
|
||||
variables: options.variables,
|
||||
context: options.context,
|
||||
})
|
||||
.subscribe({
|
||||
next: function (subscriptionData) {
|
||||
var updateQuery = options.updateQuery;
|
||||
if (updateQuery) {
|
||||
_this.updateQuery(function (previous, _a) {
|
||||
var variables = _a.variables;
|
||||
return updateQuery(previous, {
|
||||
subscriptionData: subscriptionData,
|
||||
variables: variables,
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (err) {
|
||||
if (options.onError) {
|
||||
options.onError(err);
|
||||
return;
|
||||
}
|
||||
globalThis.__DEV__ !== false && invariant.error(21, err);
|
||||
},
|
||||
});
|
||||
this.subscriptions.add(subscription);
|
||||
return function () {
|
||||
if (_this.subscriptions.delete(subscription)) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
ObservableQuery.prototype.setOptions = function (newOptions) {
|
||||
return this.reobserve(newOptions);
|
||||
};
|
||||
ObservableQuery.prototype.silentSetOptions = function (newOptions) {
|
||||
var mergedOptions = compact(this.options, newOptions || {});
|
||||
assign(this.options, mergedOptions);
|
||||
};
|
||||
/**
|
||||
* Update the variables of this observable query, and fetch the new results
|
||||
* if they've changed. Most users should prefer `refetch` instead of
|
||||
* `setVariables` in order to to be properly notified of results even when
|
||||
* they come from the cache.
|
||||
*
|
||||
* Note: the `next` callback will *not* fire if the variables have not changed
|
||||
* or if the result is coming from cache.
|
||||
*
|
||||
* Note: the promise will return the old results immediately if the variables
|
||||
* have not changed.
|
||||
*
|
||||
* Note: the promise will return null immediately if the query is not active
|
||||
* (there are no subscribers).
|
||||
*
|
||||
* @param variables - The new set of variables. If there are missing variables,
|
||||
* the previous values of those variables will be used.
|
||||
*/
|
||||
ObservableQuery.prototype.setVariables = function (variables) {
|
||||
if (equal(this.variables, variables)) {
|
||||
// If we have no observers, then we don't actually want to make a network
|
||||
// request. As soon as someone observes the query, the request will kick
|
||||
// off. For now, we just store any changes. (See #1077)
|
||||
return this.observers.size ? this.result() : Promise.resolve();
|
||||
}
|
||||
this.options.variables = variables;
|
||||
// See comment above
|
||||
if (!this.observers.size) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.reobserve({
|
||||
// Reset options.fetchPolicy to its original value.
|
||||
fetchPolicy: this.options.initialFetchPolicy,
|
||||
variables: variables,
|
||||
}, NetworkStatus.setVariables);
|
||||
};
|
||||
/**
|
||||
* A function that enables you to update the query's cached result without executing a followup GraphQL operation.
|
||||
*
|
||||
* See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
|
||||
*/
|
||||
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
||||
var queryManager = this.queryManager;
|
||||
var result = queryManager.cache.diff({
|
||||
query: this.options.query,
|
||||
variables: this.variables,
|
||||
returnPartialData: true,
|
||||
optimistic: false,
|
||||
}).result;
|
||||
var newResult = mapFn(result, {
|
||||
variables: this.variables,
|
||||
});
|
||||
if (newResult) {
|
||||
queryManager.cache.writeQuery({
|
||||
query: this.options.query,
|
||||
data: newResult,
|
||||
variables: this.variables,
|
||||
});
|
||||
queryManager.broadcastQueries();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
|
||||
*/
|
||||
ObservableQuery.prototype.startPolling = function (pollInterval) {
|
||||
this.options.pollInterval = pollInterval;
|
||||
this.updatePolling();
|
||||
};
|
||||
/**
|
||||
* A function that instructs the query to stop polling after a previous call to `startPolling`.
|
||||
*/
|
||||
ObservableQuery.prototype.stopPolling = function () {
|
||||
this.options.pollInterval = 0;
|
||||
this.updatePolling();
|
||||
};
|
||||
// Update options.fetchPolicy according to options.nextFetchPolicy.
|
||||
ObservableQuery.prototype.applyNextFetchPolicy = function (reason,
|
||||
// It's possible to use this method to apply options.nextFetchPolicy to
|
||||
// options.fetchPolicy even if options !== this.options, though that happens
|
||||
// most often when the options are temporary, used for only one request and
|
||||
// then thrown away, so nextFetchPolicy may not end up mattering.
|
||||
options) {
|
||||
if (options.nextFetchPolicy) {
|
||||
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
||||
if (fetchPolicy === "standby") {
|
||||
// Do nothing, leaving options.fetchPolicy unchanged.
|
||||
}
|
||||
else if (typeof options.nextFetchPolicy === "function") {
|
||||
// When someone chooses "cache-and-network" or "network-only" as their
|
||||
// initial FetchPolicy, they often do not want future cache updates to
|
||||
// trigger unconditional network requests, which is what repeatedly
|
||||
// applying the "cache-and-network" or "network-only" policies would
|
||||
// seem to imply. Instead, when the cache reports an update after the
|
||||
// initial network request, it may be desirable for subsequent network
|
||||
// requests to be triggered only if the cache result is incomplete. To
|
||||
// that end, the options.nextFetchPolicy option provides an easy way to
|
||||
// update options.fetchPolicy after the initial network request, without
|
||||
// having to call observableQuery.setOptions.
|
||||
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
||||
reason: reason,
|
||||
options: options,
|
||||
observable: this,
|
||||
initialFetchPolicy: initialFetchPolicy,
|
||||
});
|
||||
}
|
||||
else if (reason === "variables-changed") {
|
||||
options.fetchPolicy = initialFetchPolicy;
|
||||
}
|
||||
else {
|
||||
options.fetchPolicy = options.nextFetchPolicy;
|
||||
}
|
||||
}
|
||||
return options.fetchPolicy;
|
||||
};
|
||||
ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
|
||||
// TODO Make sure we update the networkStatus (and infer fetchVariables)
|
||||
// before actually committing to the fetch.
|
||||
this.queryManager.setObservableQuery(this);
|
||||
return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
|
||||
};
|
||||
// Turns polling on or off based on this.options.pollInterval.
|
||||
ObservableQuery.prototype.updatePolling = function () {
|
||||
var _this = this;
|
||||
// Avoid polling in SSR mode
|
||||
if (this.queryManager.ssrMode) {
|
||||
return;
|
||||
}
|
||||
var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
|
||||
if (!pollInterval) {
|
||||
if (pollingInfo) {
|
||||
clearTimeout(pollingInfo.timeout);
|
||||
delete this.pollingInfo;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (pollingInfo && pollingInfo.interval === pollInterval) {
|
||||
return;
|
||||
}
|
||||
invariant(pollInterval, 22);
|
||||
var info = pollingInfo || (this.pollingInfo = {});
|
||||
info.interval = pollInterval;
|
||||
var maybeFetch = function () {
|
||||
var _a, _b;
|
||||
if (_this.pollingInfo) {
|
||||
if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus) &&
|
||||
!((_b = (_a = _this.options).skipPollAttempt) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
||||
_this.reobserve({
|
||||
// Most fetchPolicy options don't make sense to use in a polling context, as
|
||||
// users wouldn't want to be polling the cache directly. However, network-only and
|
||||
// no-cache are both useful for when the user wants to control whether or not the
|
||||
// polled results are written to the cache.
|
||||
fetchPolicy: _this.options.initialFetchPolicy === "no-cache" ?
|
||||
"no-cache"
|
||||
: "network-only",
|
||||
}, NetworkStatus.poll).then(poll, poll);
|
||||
}
|
||||
else {
|
||||
poll();
|
||||
}
|
||||
}
|
||||
};
|
||||
var poll = function () {
|
||||
var info = _this.pollingInfo;
|
||||
if (info) {
|
||||
clearTimeout(info.timeout);
|
||||
info.timeout = setTimeout(maybeFetch, info.interval);
|
||||
}
|
||||
};
|
||||
poll();
|
||||
};
|
||||
ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
||||
if (variables === void 0) { variables = this.variables; }
|
||||
var error = this.getLastError();
|
||||
// Preserve this.last.error unless the variables have changed.
|
||||
if (error && this.last && !equal(variables, this.last.variables)) {
|
||||
error = void 0;
|
||||
}
|
||||
return (this.last = __assign({ result: this.queryManager.assumeImmutableResults ?
|
||||
newResult
|
||||
: cloneDeep(newResult), variables: variables }, (error ? { error: error } : null)));
|
||||
};
|
||||
ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
|
||||
var _this = this;
|
||||
this.isTornDown = false;
|
||||
var useDisposableConcast =
|
||||
// Refetching uses a disposable Concast to allow refetches using different
|
||||
// options/variables, without permanently altering the options of the
|
||||
// original ObservableQuery.
|
||||
newNetworkStatus === NetworkStatus.refetch ||
|
||||
// The fetchMore method does not actually call the reobserve method, but,
|
||||
// if it did, it would definitely use a disposable Concast.
|
||||
newNetworkStatus === NetworkStatus.fetchMore ||
|
||||
// Polling uses a disposable Concast so the polling options (which force
|
||||
// fetchPolicy to be "network-only" or "no-cache") won't override the original options.
|
||||
newNetworkStatus === NetworkStatus.poll;
|
||||
// Save the old variables, since Object.assign may modify them below.
|
||||
var oldVariables = this.options.variables;
|
||||
var oldFetchPolicy = this.options.fetchPolicy;
|
||||
var mergedOptions = compact(this.options, newOptions || {});
|
||||
var options = useDisposableConcast ?
|
||||
// Disposable Concast fetches receive a shallow copy of this.options
|
||||
// (merged with newOptions), leaving this.options unmodified.
|
||||
mergedOptions
|
||||
: assign(this.options, mergedOptions);
|
||||
// Don't update options.query with the transformed query to avoid
|
||||
// overwriting this.options.query when we aren't using a disposable concast.
|
||||
// We want to ensure we can re-run the custom document transforms the next
|
||||
// time a request is made against the original query.
|
||||
var query = this.transformDocument(options.query);
|
||||
this.lastQuery = query;
|
||||
if (!useDisposableConcast) {
|
||||
// We can skip calling updatePolling if we're not changing this.options.
|
||||
this.updatePolling();
|
||||
// Reset options.fetchPolicy to its original value when variables change,
|
||||
// unless a new fetchPolicy was provided by newOptions.
|
||||
if (newOptions &&
|
||||
newOptions.variables &&
|
||||
!equal(newOptions.variables, oldVariables) &&
|
||||
// Don't mess with the fetchPolicy if it's currently "standby".
|
||||
options.fetchPolicy !== "standby" &&
|
||||
// If we're changing the fetchPolicy anyway, don't try to change it here
|
||||
// using applyNextFetchPolicy. The explicit options.fetchPolicy wins.
|
||||
options.fetchPolicy === oldFetchPolicy) {
|
||||
this.applyNextFetchPolicy("variables-changed", options);
|
||||
if (newNetworkStatus === void 0) {
|
||||
newNetworkStatus = NetworkStatus.setVariables;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.waitForOwnResult && (this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy));
|
||||
var finishWaitingForOwnResult = function () {
|
||||
if (_this.concast === concast) {
|
||||
_this.waitForOwnResult = false;
|
||||
}
|
||||
};
|
||||
var variables = options.variables && __assign({}, options.variables);
|
||||
var _a = this.fetch(options, newNetworkStatus, query), concast = _a.concast, fromLink = _a.fromLink;
|
||||
var observer = {
|
||||
next: function (result) {
|
||||
if (equal(_this.variables, variables)) {
|
||||
finishWaitingForOwnResult();
|
||||
_this.reportResult(result, variables);
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
if (equal(_this.variables, variables)) {
|
||||
finishWaitingForOwnResult();
|
||||
_this.reportError(error, variables);
|
||||
}
|
||||
},
|
||||
};
|
||||
if (!useDisposableConcast && (fromLink || !this.concast)) {
|
||||
// We use the {add,remove}Observer methods directly to avoid wrapping
|
||||
// observer with an unnecessary SubscriptionObserver object.
|
||||
if (this.concast && this.observer) {
|
||||
this.concast.removeObserver(this.observer);
|
||||
}
|
||||
this.concast = concast;
|
||||
this.observer = observer;
|
||||
}
|
||||
concast.addObserver(observer);
|
||||
return concast;
|
||||
};
|
||||
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
||||
return this.reobserveAsConcast(newOptions, newNetworkStatus)
|
||||
.promise;
|
||||
};
|
||||
ObservableQuery.prototype.resubscribeAfterError = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
// If `lastError` is set in the current when the subscription is re-created,
|
||||
// the subscription will immediately receive the error, which will
|
||||
// cause it to terminate again. To avoid this, we first clear
|
||||
// the last error/result from the `observableQuery` before re-starting
|
||||
// the subscription, and restore the last value afterwards so that the
|
||||
// subscription has a chance to stay open.
|
||||
var last = this.last;
|
||||
this.resetLastResults();
|
||||
var subscription = this.subscribe.apply(this, args);
|
||||
this.last = last;
|
||||
return subscription;
|
||||
};
|
||||
// (Re)deliver the current result to this.observers without applying fetch
|
||||
// policies or making network requests.
|
||||
ObservableQuery.prototype.observe = function () {
|
||||
this.reportResult(
|
||||
// Passing false is important so that this.getCurrentResult doesn't
|
||||
// save the fetchMore result as this.lastResult, causing it to be
|
||||
// ignored due to the this.isDifferentFromLastResult check in
|
||||
// this.reportResult.
|
||||
this.getCurrentResult(false), this.variables);
|
||||
};
|
||||
ObservableQuery.prototype.reportResult = function (result, variables) {
|
||||
var lastError = this.getLastError();
|
||||
var isDifferent = this.isDifferentFromLastResult(result, variables);
|
||||
// Update the last result even when isDifferentFromLastResult returns false,
|
||||
// because the query may be using the @nonreactive directive, and we want to
|
||||
// save the the latest version of any nonreactive subtrees (in case
|
||||
// getCurrentResult is called), even though we skip broadcasting changes.
|
||||
if (lastError || !result.partial || this.options.returnPartialData) {
|
||||
this.updateLastResult(result, variables);
|
||||
}
|
||||
if (lastError || isDifferent) {
|
||||
iterateObserversSafely(this.observers, "next", result);
|
||||
}
|
||||
};
|
||||
ObservableQuery.prototype.reportError = function (error, variables) {
|
||||
// Since we don't get the current result on errors, only the error, we
|
||||
// must mirror the updates that occur in QueryStore.markQueryError here
|
||||
var errorResult = __assign(__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: NetworkStatus.error, loading: false });
|
||||
this.updateLastResult(errorResult, variables);
|
||||
iterateObserversSafely(this.observers, "error", (this.last.error = error));
|
||||
};
|
||||
ObservableQuery.prototype.hasObservers = function () {
|
||||
return this.observers.size > 0;
|
||||
};
|
||||
ObservableQuery.prototype.tearDownQuery = function () {
|
||||
if (this.isTornDown)
|
||||
return;
|
||||
if (this.concast && this.observer) {
|
||||
this.concast.removeObserver(this.observer);
|
||||
delete this.concast;
|
||||
delete this.observer;
|
||||
}
|
||||
this.stopPolling();
|
||||
// stop all active GraphQL subscriptions
|
||||
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
||||
this.subscriptions.clear();
|
||||
this.queryManager.stopQuery(this.queryId);
|
||||
this.observers.clear();
|
||||
this.isTornDown = true;
|
||||
};
|
||||
ObservableQuery.prototype.transformDocument = function (document) {
|
||||
return this.queryManager.transform(document);
|
||||
};
|
||||
return ObservableQuery;
|
||||
}(Observable));
|
||||
export { ObservableQuery };
|
||||
// Necessary because the ObservableQuery constructor has a different
|
||||
// signature than the Observable constructor.
|
||||
fixObservableSubclass(ObservableQuery);
|
||||
// Reobserve with fetchPolicy effectively set to "cache-first", triggering
|
||||
// delivery of any new data from the cache, possibly falling back to the network
|
||||
// if any cache data are missing. This allows _complete_ cache results to be
|
||||
// delivered without also kicking off unnecessary network requests when
|
||||
// this.options.fetchPolicy is "cache-and-network" or "network-only". When
|
||||
// this.options.fetchPolicy is any other policy ("cache-first", "cache-only",
|
||||
// "standby", or "no-cache"), we call this.reobserve() as usual.
|
||||
export function reobserveCacheFirst(obsQuery) {
|
||||
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
||||
if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
|
||||
return obsQuery.reobserve({
|
||||
fetchPolicy: "cache-first",
|
||||
// Use a temporary nextFetchPolicy function that replaces itself with the
|
||||
// previous nextFetchPolicy value and returns the original fetchPolicy.
|
||||
nextFetchPolicy: function (currentFetchPolicy, context) {
|
||||
// Replace this nextFetchPolicy function in the options object with the
|
||||
// original this.options.nextFetchPolicy value.
|
||||
this.nextFetchPolicy = nextFetchPolicy;
|
||||
// If the original nextFetchPolicy value was a function, give it a
|
||||
// chance to decide what happens here.
|
||||
if (typeof this.nextFetchPolicy === "function") {
|
||||
return this.nextFetchPolicy(currentFetchPolicy, context);
|
||||
}
|
||||
// Otherwise go back to the original this.options.fetchPolicy.
|
||||
return fetchPolicy;
|
||||
},
|
||||
});
|
||||
}
|
||||
return obsQuery.reobserve();
|
||||
}
|
||||
function defaultSubscriptionObserverErrorCallback(error) {
|
||||
globalThis.__DEV__ !== false && invariant.error(23, error.message, error.stack);
|
||||
}
|
||||
export function logMissingFieldErrors(missing) {
|
||||
if (globalThis.__DEV__ !== false && missing) {
|
||||
globalThis.__DEV__ !== false && invariant.debug(24, missing);
|
||||
}
|
||||
}
|
||||
function skipCacheDataFor(fetchPolicy /* `undefined` would mean `"cache-first"` */) {
|
||||
return (fetchPolicy === "network-only" ||
|
||||
fetchPolicy === "no-cache" ||
|
||||
fetchPolicy === "standby");
|
||||
}
|
||||
//# sourceMappingURL=ObservableQuery.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/ObservableQuery.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
61
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.d.ts
generated
vendored
Normal file
61
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import type { DocumentNode, GraphQLError } from "graphql";
|
||||
import type { Cache } from "../cache/index.js";
|
||||
import type { WatchQueryOptions, ErrorPolicy } from "./watchQueryOptions.js";
|
||||
import type { ObservableQuery } from "./ObservableQuery.js";
|
||||
import type { QueryListener } from "./types.js";
|
||||
import type { FetchResult } from "../link/core/index.js";
|
||||
import { NetworkStatus } from "./networkStatus.js";
|
||||
import type { ApolloError } from "../errors/index.js";
|
||||
import type { QueryManager } from "./QueryManager.js";
|
||||
export type QueryStoreValue = Pick<QueryInfo, "variables" | "networkStatus" | "networkError" | "graphQLErrors">;
|
||||
export declare const enum CacheWriteBehavior {
|
||||
FORBID = 0,
|
||||
OVERWRITE = 1,
|
||||
MERGE = 2
|
||||
}
|
||||
export declare class QueryInfo {
|
||||
readonly queryId: string;
|
||||
listeners: Set<QueryListener>;
|
||||
document: DocumentNode | null;
|
||||
lastRequestId: number;
|
||||
variables?: Record<string, any>;
|
||||
networkStatus?: NetworkStatus;
|
||||
networkError?: Error | null;
|
||||
graphQLErrors?: ReadonlyArray<GraphQLError>;
|
||||
stopped: boolean;
|
||||
private cache;
|
||||
constructor(queryManager: QueryManager<any>, queryId?: string);
|
||||
init(query: {
|
||||
document: DocumentNode;
|
||||
variables: Record<string, any> | undefined;
|
||||
networkStatus?: NetworkStatus;
|
||||
observableQuery?: ObservableQuery<any, any>;
|
||||
lastRequestId?: number;
|
||||
}): this;
|
||||
private dirty;
|
||||
private notifyTimeout?;
|
||||
reset(): void;
|
||||
resetDiff(): void;
|
||||
getDiff(): Cache.DiffResult<any>;
|
||||
private lastDiff?;
|
||||
private updateLastDiff;
|
||||
private getDiffOptions;
|
||||
setDiff(diff: Cache.DiffResult<any> | null): void;
|
||||
readonly observableQuery: ObservableQuery<any, any> | null;
|
||||
private oqListener?;
|
||||
setObservableQuery(oq: ObservableQuery<any, any> | null): void;
|
||||
notify(): void;
|
||||
private shouldNotify;
|
||||
stop(): void;
|
||||
private cancel;
|
||||
private lastWatch?;
|
||||
private updateWatch;
|
||||
private lastWrite?;
|
||||
resetLastWrite(): void;
|
||||
private shouldWrite;
|
||||
markResult<T>(result: FetchResult<T>, document: DocumentNode, options: Pick<WatchQueryOptions, "variables" | "fetchPolicy" | "errorPolicy">, cacheWriteBehavior: CacheWriteBehavior): void;
|
||||
markReady(): NetworkStatus;
|
||||
markError(error: ApolloError): ApolloError;
|
||||
}
|
||||
export declare function shouldWriteResult<T>(result: FetchResult<T>, errorPolicy?: ErrorPolicy): boolean;
|
||||
//# sourceMappingURL=QueryInfo.d.ts.map
|
||||
403
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.js
generated
vendored
Normal file
403
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.js
generated
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
import { __assign } from "tslib";
|
||||
import { equal } from "@wry/equality";
|
||||
import { DeepMerger } from "../utilities/index.js";
|
||||
import { mergeIncrementalData } from "../utilities/index.js";
|
||||
import { reobserveCacheFirst } from "./ObservableQuery.js";
|
||||
import { isNonEmptyArray, graphQLResultHasError, canUseWeakMap, } from "../utilities/index.js";
|
||||
import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js";
|
||||
var destructiveMethodCounts = new (canUseWeakMap ? WeakMap : Map)();
|
||||
function wrapDestructiveCacheMethod(cache, methodName) {
|
||||
var original = cache[methodName];
|
||||
if (typeof original === "function") {
|
||||
// @ts-expect-error this is just too generic to be typed correctly
|
||||
cache[methodName] = function () {
|
||||
destructiveMethodCounts.set(cache,
|
||||
// The %1e15 allows the count to wrap around to 0 safely every
|
||||
// quadrillion evictions, so there's no risk of overflow. To be
|
||||
// clear, this is more of a pedantic principle than something
|
||||
// that matters in any conceivable practical scenario.
|
||||
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
||||
// @ts-expect-error this is just too generic to be typed correctly
|
||||
return original.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
}
|
||||
function cancelNotifyTimeout(info) {
|
||||
if (info["notifyTimeout"]) {
|
||||
clearTimeout(info["notifyTimeout"]);
|
||||
info["notifyTimeout"] = void 0;
|
||||
}
|
||||
}
|
||||
// A QueryInfo object represents a single query managed by the
|
||||
// QueryManager, which tracks all QueryInfo objects by queryId in its
|
||||
// this.queries Map. QueryInfo objects store the latest results and errors
|
||||
// for the given query, and are responsible for reporting those results to
|
||||
// the corresponding ObservableQuery, via the QueryInfo.notify method.
|
||||
// Results are reported asynchronously whenever setDiff marks the
|
||||
// QueryInfo object as dirty, though a call to the QueryManager's
|
||||
// broadcastQueries method may trigger the notification before it happens
|
||||
// automatically. This class used to be a simple interface type without
|
||||
// any field privacy or meaningful methods, which is why it still has so
|
||||
// many public fields. The effort to lock down and simplify the QueryInfo
|
||||
// interface is ongoing, and further improvements are welcome.
|
||||
var QueryInfo = /** @class */ (function () {
|
||||
function QueryInfo(queryManager, queryId) {
|
||||
if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
|
||||
this.queryId = queryId;
|
||||
this.listeners = new Set();
|
||||
this.document = null;
|
||||
this.lastRequestId = 1;
|
||||
this.stopped = false;
|
||||
this.dirty = false;
|
||||
this.observableQuery = null;
|
||||
var cache = (this.cache = queryManager.cache);
|
||||
// Track how often cache.evict is called, since we want eviction to
|
||||
// override the feud-stopping logic in the markResult method, by
|
||||
// causing shouldWrite to return true. Wrapping the cache.evict method
|
||||
// is a bit of a hack, but it saves us from having to make eviction
|
||||
// counting an official part of the ApolloCache API.
|
||||
if (!destructiveMethodCounts.has(cache)) {
|
||||
destructiveMethodCounts.set(cache, 0);
|
||||
wrapDestructiveCacheMethod(cache, "evict");
|
||||
wrapDestructiveCacheMethod(cache, "modify");
|
||||
wrapDestructiveCacheMethod(cache, "reset");
|
||||
}
|
||||
}
|
||||
QueryInfo.prototype.init = function (query) {
|
||||
var networkStatus = query.networkStatus || NetworkStatus.loading;
|
||||
if (this.variables &&
|
||||
this.networkStatus !== NetworkStatus.loading &&
|
||||
!equal(this.variables, query.variables)) {
|
||||
networkStatus = NetworkStatus.setVariables;
|
||||
}
|
||||
if (!equal(query.variables, this.variables)) {
|
||||
this.lastDiff = void 0;
|
||||
}
|
||||
Object.assign(this, {
|
||||
document: query.document,
|
||||
variables: query.variables,
|
||||
networkError: null,
|
||||
graphQLErrors: this.graphQLErrors || [],
|
||||
networkStatus: networkStatus,
|
||||
});
|
||||
if (query.observableQuery) {
|
||||
this.setObservableQuery(query.observableQuery);
|
||||
}
|
||||
if (query.lastRequestId) {
|
||||
this.lastRequestId = query.lastRequestId;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
QueryInfo.prototype.reset = function () {
|
||||
cancelNotifyTimeout(this);
|
||||
this.dirty = false;
|
||||
};
|
||||
QueryInfo.prototype.resetDiff = function () {
|
||||
this.lastDiff = void 0;
|
||||
};
|
||||
QueryInfo.prototype.getDiff = function () {
|
||||
var options = this.getDiffOptions();
|
||||
if (this.lastDiff && equal(options, this.lastDiff.options)) {
|
||||
return this.lastDiff.diff;
|
||||
}
|
||||
this.updateWatch(this.variables);
|
||||
var oq = this.observableQuery;
|
||||
if (oq && oq.options.fetchPolicy === "no-cache") {
|
||||
return { complete: false };
|
||||
}
|
||||
var diff = this.cache.diff(options);
|
||||
this.updateLastDiff(diff, options);
|
||||
return diff;
|
||||
};
|
||||
QueryInfo.prototype.updateLastDiff = function (diff, options) {
|
||||
this.lastDiff =
|
||||
diff ?
|
||||
{
|
||||
diff: diff,
|
||||
options: options || this.getDiffOptions(),
|
||||
}
|
||||
: void 0;
|
||||
};
|
||||
QueryInfo.prototype.getDiffOptions = function (variables) {
|
||||
var _a;
|
||||
if (variables === void 0) { variables = this.variables; }
|
||||
return {
|
||||
query: this.document,
|
||||
variables: variables,
|
||||
returnPartialData: true,
|
||||
optimistic: true,
|
||||
canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
|
||||
};
|
||||
};
|
||||
QueryInfo.prototype.setDiff = function (diff) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
||||
// If we do not tolerate partial results, skip this update to prevent it
|
||||
// from being reported. This prevents a situtuation where a query that
|
||||
// errors and another succeeds with overlapping data does not report the
|
||||
// partial data result to the errored query.
|
||||
//
|
||||
// See https://github.com/apollographql/apollo-client/issues/11400 for more
|
||||
// information on this issue.
|
||||
if (diff &&
|
||||
!diff.complete &&
|
||||
!((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.returnPartialData) &&
|
||||
// In the case of a cache eviction, the diff will become partial so we
|
||||
// schedule a notification to send a network request (this.oqListener) to
|
||||
// go and fetch the missing data.
|
||||
!(oldDiff && oldDiff.complete)) {
|
||||
return;
|
||||
}
|
||||
this.updateLastDiff(diff);
|
||||
if (!this.dirty && !equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
||||
this.dirty = true;
|
||||
if (!this.notifyTimeout) {
|
||||
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
QueryInfo.prototype.setObservableQuery = function (oq) {
|
||||
var _this = this;
|
||||
if (oq === this.observableQuery)
|
||||
return;
|
||||
if (this.oqListener) {
|
||||
this.listeners.delete(this.oqListener);
|
||||
}
|
||||
this.observableQuery = oq;
|
||||
if (oq) {
|
||||
oq["queryInfo"] = this;
|
||||
this.listeners.add((this.oqListener = function () {
|
||||
var diff = _this.getDiff();
|
||||
if (diff.fromOptimisticTransaction) {
|
||||
// If this diff came from an optimistic transaction, deliver the
|
||||
// current cache data to the ObservableQuery, but don't perform a
|
||||
// reobservation, since oq.reobserveCacheFirst might make a network
|
||||
// request, and we never want to trigger network requests in the
|
||||
// middle of optimistic updates.
|
||||
oq["observe"]();
|
||||
}
|
||||
else {
|
||||
// Otherwise, make the ObservableQuery "reobserve" the latest data
|
||||
// using a temporary fetch policy of "cache-first", so complete cache
|
||||
// results have a chance to be delivered without triggering additional
|
||||
// network requests, even when options.fetchPolicy is "network-only"
|
||||
// or "cache-and-network". All other fetch policies are preserved by
|
||||
// this method, and are handled by calling oq.reobserve(). If this
|
||||
// reobservation is spurious, isDifferentFromLastResult still has a
|
||||
// chance to catch it before delivery to ObservableQuery subscribers.
|
||||
reobserveCacheFirst(oq);
|
||||
}
|
||||
}));
|
||||
}
|
||||
else {
|
||||
delete this.oqListener;
|
||||
}
|
||||
};
|
||||
QueryInfo.prototype.notify = function () {
|
||||
var _this = this;
|
||||
cancelNotifyTimeout(this);
|
||||
if (this.shouldNotify()) {
|
||||
this.listeners.forEach(function (listener) { return listener(_this); });
|
||||
}
|
||||
this.dirty = false;
|
||||
};
|
||||
QueryInfo.prototype.shouldNotify = function () {
|
||||
if (!this.dirty || !this.listeners.size) {
|
||||
return false;
|
||||
}
|
||||
if (isNetworkRequestInFlight(this.networkStatus) && this.observableQuery) {
|
||||
var fetchPolicy = this.observableQuery.options.fetchPolicy;
|
||||
if (fetchPolicy !== "cache-only" && fetchPolicy !== "cache-and-network") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
QueryInfo.prototype.stop = function () {
|
||||
if (!this.stopped) {
|
||||
this.stopped = true;
|
||||
// Cancel the pending notify timeout
|
||||
this.reset();
|
||||
this.cancel();
|
||||
// Revert back to the no-op version of cancel inherited from
|
||||
// QueryInfo.prototype.
|
||||
this.cancel = QueryInfo.prototype.cancel;
|
||||
var oq = this.observableQuery;
|
||||
if (oq)
|
||||
oq.stopPolling();
|
||||
}
|
||||
};
|
||||
// This method is a no-op by default, until/unless overridden by the
|
||||
// updateWatch method.
|
||||
QueryInfo.prototype.cancel = function () { };
|
||||
QueryInfo.prototype.updateWatch = function (variables) {
|
||||
var _this = this;
|
||||
if (variables === void 0) { variables = this.variables; }
|
||||
var oq = this.observableQuery;
|
||||
if (oq && oq.options.fetchPolicy === "no-cache") {
|
||||
return;
|
||||
}
|
||||
var watchOptions = __assign(__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
||||
if (!this.lastWatch || !equal(watchOptions, this.lastWatch)) {
|
||||
this.cancel();
|
||||
this.cancel = this.cache.watch((this.lastWatch = watchOptions));
|
||||
}
|
||||
};
|
||||
QueryInfo.prototype.resetLastWrite = function () {
|
||||
this.lastWrite = void 0;
|
||||
};
|
||||
QueryInfo.prototype.shouldWrite = function (result, variables) {
|
||||
var lastWrite = this.lastWrite;
|
||||
return !(lastWrite &&
|
||||
// If cache.evict has been called since the last time we wrote this
|
||||
// data into the cache, there's a chance writing this result into
|
||||
// the cache will repair what was evicted.
|
||||
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
||||
equal(variables, lastWrite.variables) &&
|
||||
equal(result.data, lastWrite.result.data));
|
||||
};
|
||||
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
||||
var _this = this;
|
||||
var merger = new DeepMerger();
|
||||
var graphQLErrors = isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
|
||||
// Cancel the pending notify timeout (if it exists) to prevent extraneous network
|
||||
// requests. To allow future notify timeouts, diff and dirty are reset as well.
|
||||
this.reset();
|
||||
if ("incremental" in result && isNonEmptyArray(result.incremental)) {
|
||||
var mergedData = mergeIncrementalData(this.getDiff().result, result);
|
||||
result.data = mergedData;
|
||||
// Detect the first chunk of a deferred query and merge it with existing
|
||||
// cache data. This ensures a `cache-first` fetch policy that returns
|
||||
// partial cache data or a `cache-and-network` fetch policy that already
|
||||
// has full data in the cache does not complain when trying to merge the
|
||||
// initial deferred server data with existing cache data.
|
||||
}
|
||||
else if ("hasNext" in result && result.hasNext) {
|
||||
var diff = this.getDiff();
|
||||
result.data = merger.merge(diff.result, result.data);
|
||||
}
|
||||
this.graphQLErrors = graphQLErrors;
|
||||
if (options.fetchPolicy === "no-cache") {
|
||||
this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
||||
}
|
||||
else if (cacheWriteBehavior !== 0 /* CacheWriteBehavior.FORBID */) {
|
||||
if (shouldWriteResult(result, options.errorPolicy)) {
|
||||
// Using a transaction here so we have a chance to read the result
|
||||
// back from the cache before the watch callback fires as a result
|
||||
// of writeQuery, so we can store the new diff quietly and ignore
|
||||
// it when we receive it redundantly from the watch callback.
|
||||
this.cache.performTransaction(function (cache) {
|
||||
if (_this.shouldWrite(result, options.variables)) {
|
||||
cache.writeQuery({
|
||||
query: document,
|
||||
data: result.data,
|
||||
variables: options.variables,
|
||||
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
||||
});
|
||||
_this.lastWrite = {
|
||||
result: result,
|
||||
variables: options.variables,
|
||||
dmCount: destructiveMethodCounts.get(_this.cache),
|
||||
};
|
||||
}
|
||||
else {
|
||||
// If result is the same as the last result we received from
|
||||
// the network (and the variables match too), avoid writing
|
||||
// result into the cache again. The wisdom of skipping this
|
||||
// cache write is far from obvious, since any cache write
|
||||
// could be the one that puts the cache back into a desired
|
||||
// state, fixing corruption or missing data. However, if we
|
||||
// always write every network result into the cache, we enable
|
||||
// feuds between queries competing to update the same data in
|
||||
// incompatible ways, which can lead to an endless cycle of
|
||||
// cache broadcasts and useless network requests. As with any
|
||||
// feud, eventually one side must step back from the brink,
|
||||
// letting the other side(s) have the last word(s). There may
|
||||
// be other points where we could break this cycle, such as
|
||||
// silencing the broadcast for cache.writeQuery (not a good
|
||||
// idea, since it just delays the feud a bit) or somehow
|
||||
// avoiding the network request that just happened (also bad,
|
||||
// because the server could return useful new data). All
|
||||
// options considered, skipping this cache write seems to be
|
||||
// the least damaging place to break the cycle, because it
|
||||
// reflects the intuition that we recently wrote this exact
|
||||
// result into the cache, so the cache *should* already/still
|
||||
// contain this data. If some other query has clobbered that
|
||||
// data in the meantime, that's too bad, but there will be no
|
||||
// winners if every query blindly reverts to its own version
|
||||
// of the data. This approach also gives the network a chance
|
||||
// to return new data, which will be written into the cache as
|
||||
// usual, notifying only those queries that are directly
|
||||
// affected by the cache updates, as usual. In the future, an
|
||||
// even more sophisticated cache could perhaps prevent or
|
||||
// mitigate the clobbering somehow, but that would make this
|
||||
// particular cache write even less important, and thus
|
||||
// skipping it would be even safer than it is today.
|
||||
if (_this.lastDiff && _this.lastDiff.diff.complete) {
|
||||
// Reuse data from the last good (complete) diff that we
|
||||
// received, when possible.
|
||||
result.data = _this.lastDiff.diff.result;
|
||||
return;
|
||||
}
|
||||
// If the previous this.diff was incomplete, fall through to
|
||||
// re-reading the latest data with cache.diff, below.
|
||||
}
|
||||
var diffOptions = _this.getDiffOptions(options.variables);
|
||||
var diff = cache.diff(diffOptions);
|
||||
// In case the QueryManager stops this QueryInfo before its
|
||||
// results are delivered, it's important to avoid restarting the
|
||||
// cache watch when markResult is called. We also avoid updating
|
||||
// the watch if we are writing a result that doesn't match the current
|
||||
// variables to avoid race conditions from broadcasting the wrong
|
||||
// result.
|
||||
if (!_this.stopped && equal(_this.variables, options.variables)) {
|
||||
// Any time we're about to update this.diff, we need to make
|
||||
// sure we've started watching the cache.
|
||||
_this.updateWatch(options.variables);
|
||||
}
|
||||
// If we're allowed to write to the cache, and we can read a
|
||||
// complete result from the cache, update result.data to be the
|
||||
// result from the cache, rather than the raw network result.
|
||||
// Set without setDiff to avoid triggering a notify call, since
|
||||
// we have other ways of notifying for this result.
|
||||
_this.updateLastDiff(diff, diffOptions);
|
||||
if (diff.complete) {
|
||||
result.data = diff.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.lastWrite = void 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
QueryInfo.prototype.markReady = function () {
|
||||
this.networkError = null;
|
||||
return (this.networkStatus = NetworkStatus.ready);
|
||||
};
|
||||
QueryInfo.prototype.markError = function (error) {
|
||||
this.networkStatus = NetworkStatus.error;
|
||||
this.lastWrite = void 0;
|
||||
this.reset();
|
||||
if (error.graphQLErrors) {
|
||||
this.graphQLErrors = error.graphQLErrors;
|
||||
}
|
||||
if (error.networkError) {
|
||||
this.networkError = error.networkError;
|
||||
}
|
||||
return error;
|
||||
};
|
||||
return QueryInfo;
|
||||
}());
|
||||
export { QueryInfo };
|
||||
export function shouldWriteResult(result, errorPolicy) {
|
||||
if (errorPolicy === void 0) { errorPolicy = "none"; }
|
||||
var ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
||||
var writeWithErrors = !graphQLResultHasError(result);
|
||||
if (!writeWithErrors && ignoreErrors && result.data) {
|
||||
writeWithErrors = true;
|
||||
}
|
||||
return writeWithErrors;
|
||||
}
|
||||
//# sourceMappingURL=QueryInfo.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/QueryInfo.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
132
graphql-subscription/node_modules/@apollo/client/core/QueryManager.d.ts
generated
vendored
Normal file
132
graphql-subscription/node_modules/@apollo/client/core/QueryManager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import type { DocumentNode } from "graphql";
|
||||
import type { ApolloLink, FetchResult } from "../link/core/index.js";
|
||||
import type { Cache, ApolloCache } from "../cache/index.js";
|
||||
import { Observable, DocumentTransform } from "../utilities/index.js";
|
||||
import type { QueryOptions, WatchQueryOptions, SubscriptionOptions, MutationOptions, ErrorPolicy, MutationFetchPolicy } from "./watchQueryOptions.js";
|
||||
import { ObservableQuery } from "./ObservableQuery.js";
|
||||
import { NetworkStatus } from "./networkStatus.js";
|
||||
import type { ApolloQueryResult, OperationVariables, MutationUpdaterFunction, OnQueryUpdated, InternalRefetchQueriesInclude, InternalRefetchQueriesOptions, InternalRefetchQueriesMap, DefaultContext } from "./types.js";
|
||||
import { LocalState } from "./LocalState.js";
|
||||
import type { QueryStoreValue } from "./QueryInfo.js";
|
||||
interface MutationStoreValue {
|
||||
mutation: DocumentNode;
|
||||
variables: Record<string, any>;
|
||||
loading: boolean;
|
||||
error: Error | null;
|
||||
}
|
||||
type UpdateQueries<TData> = MutationOptions<TData, any, any>["updateQueries"];
|
||||
interface TransformCacheEntry {
|
||||
hasClientExports: boolean;
|
||||
hasForcedResolvers: boolean;
|
||||
hasNonreactiveDirective: boolean;
|
||||
clientQuery: DocumentNode | null;
|
||||
serverQuery: DocumentNode | null;
|
||||
defaultVars: OperationVariables;
|
||||
asQuery: DocumentNode;
|
||||
}
|
||||
import type { DefaultOptions } from "./ApolloClient.js";
|
||||
import { Trie } from "@wry/trie";
|
||||
export declare class QueryManager<TStore> {
|
||||
cache: ApolloCache<TStore>;
|
||||
link: ApolloLink;
|
||||
defaultOptions: DefaultOptions;
|
||||
readonly assumeImmutableResults: boolean;
|
||||
readonly documentTransform: DocumentTransform;
|
||||
readonly ssrMode: boolean;
|
||||
readonly defaultContext: Partial<DefaultContext>;
|
||||
private queryDeduplication;
|
||||
private clientAwareness;
|
||||
private localState;
|
||||
private onBroadcast?;
|
||||
mutationStore?: {
|
||||
[mutationId: string]: MutationStoreValue;
|
||||
};
|
||||
private queries;
|
||||
protected fetchCancelFns: Map<string, (error: any) => any>;
|
||||
constructor({ cache, link, defaultOptions, documentTransform, queryDeduplication, onBroadcast, ssrMode, clientAwareness, localState, assumeImmutableResults, defaultContext, }: {
|
||||
cache: ApolloCache<TStore>;
|
||||
link: ApolloLink;
|
||||
defaultOptions?: DefaultOptions;
|
||||
documentTransform?: DocumentTransform;
|
||||
queryDeduplication?: boolean;
|
||||
onBroadcast?: () => void;
|
||||
ssrMode?: boolean;
|
||||
clientAwareness?: Record<string, string>;
|
||||
localState?: LocalState<TStore>;
|
||||
assumeImmutableResults?: boolean;
|
||||
defaultContext?: Partial<DefaultContext>;
|
||||
});
|
||||
/**
|
||||
* Call this method to terminate any active query processes, making it safe
|
||||
* to dispose of this QueryManager instance.
|
||||
*/
|
||||
stop(): void;
|
||||
private cancelPendingFetches;
|
||||
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
|
||||
markMutationResult<TData, TVariables, TContext, TCache extends ApolloCache<any>>(mutation: {
|
||||
mutationId: string;
|
||||
result: FetchResult<TData>;
|
||||
document: DocumentNode;
|
||||
variables?: TVariables;
|
||||
fetchPolicy?: MutationFetchPolicy;
|
||||
errorPolicy: ErrorPolicy;
|
||||
context?: TContext;
|
||||
updateQueries: UpdateQueries<TData>;
|
||||
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
|
||||
awaitRefetchQueries?: boolean;
|
||||
refetchQueries?: InternalRefetchQueriesInclude;
|
||||
removeOptimistic?: string;
|
||||
onQueryUpdated?: OnQueryUpdated<any>;
|
||||
keepRootFields?: boolean;
|
||||
}, cache?: ApolloCache<TStore>): Promise<FetchResult<TData>>;
|
||||
markMutationOptimistic<TData, TVariables, TContext, TCache extends ApolloCache<any>>(optimisticResponse: any, mutation: {
|
||||
mutationId: string;
|
||||
document: DocumentNode;
|
||||
variables?: TVariables;
|
||||
fetchPolicy?: MutationFetchPolicy;
|
||||
errorPolicy: ErrorPolicy;
|
||||
context?: TContext;
|
||||
updateQueries: UpdateQueries<TData>;
|
||||
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
|
||||
keepRootFields?: boolean;
|
||||
}): boolean;
|
||||
fetchQuery<TData, TVars extends OperationVariables>(queryId: string, options: WatchQueryOptions<TVars, TData>, networkStatus?: NetworkStatus): Promise<ApolloQueryResult<TData>>;
|
||||
getQueryStore(): Record<string, QueryStoreValue>;
|
||||
resetErrors(queryId: string): void;
|
||||
transform(document: DocumentNode): DocumentNode;
|
||||
private transformCache;
|
||||
getDocumentInfo(document: DocumentNode): TransformCacheEntry;
|
||||
private getVariables;
|
||||
watchQuery<T, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
|
||||
query<TData, TVars extends OperationVariables = OperationVariables>(options: QueryOptions<TVars, TData>, queryId?: string): Promise<ApolloQueryResult<TData>>;
|
||||
private queryIdCounter;
|
||||
generateQueryId(): string;
|
||||
private requestIdCounter;
|
||||
generateRequestId(): number;
|
||||
private mutationIdCounter;
|
||||
generateMutationId(): string;
|
||||
stopQueryInStore(queryId: string): void;
|
||||
private stopQueryInStoreNoBroadcast;
|
||||
clearStore(options?: Cache.ResetOptions): Promise<void>;
|
||||
getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
|
||||
reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]>;
|
||||
setObservableQuery(observableQuery: ObservableQuery<any, any>): void;
|
||||
startGraphQLSubscription<T = any>({ query, fetchPolicy, errorPolicy, variables, context, }: SubscriptionOptions): Observable<FetchResult<T>>;
|
||||
stopQuery(queryId: string): void;
|
||||
private stopQueryNoBroadcast;
|
||||
removeQuery(queryId: string): void;
|
||||
broadcastQueries(): void;
|
||||
getLocalState(): LocalState<TStore>;
|
||||
protected inFlightLinkObservables: Trie<{
|
||||
observable?: Observable<FetchResult<any>> | undefined;
|
||||
}>;
|
||||
private getObservableFromLink;
|
||||
private getResultsFromLink;
|
||||
private fetchConcastWithInfo;
|
||||
refetchQueries<TResult>({ updateCache, include, optimistic, removeOptimistic, onQueryUpdated, }: InternalRefetchQueriesOptions<ApolloCache<TStore>, TResult>): InternalRefetchQueriesMap<TResult>;
|
||||
private fetchQueryByPolicy;
|
||||
private getQuery;
|
||||
private prepareContext;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=QueryManager.d.ts.map
|
||||
1123
graphql-subscription/node_modules/@apollo/client/core/QueryManager.js
generated
vendored
Normal file
1123
graphql-subscription/node_modules/@apollo/client/core/QueryManager.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
graphql-subscription/node_modules/@apollo/client/core/QueryManager.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/QueryManager.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2642
graphql-subscription/node_modules/@apollo/client/core/core.cjs
generated
vendored
Normal file
2642
graphql-subscription/node_modules/@apollo/client/core/core.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
graphql-subscription/node_modules/@apollo/client/core/core.cjs.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/core.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2642
graphql-subscription/node_modules/@apollo/client/core/core.cjs.native.js
generated
vendored
Normal file
2642
graphql-subscription/node_modules/@apollo/client/core/core.cjs.native.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.d.ts
generated
vendored
Normal file
4
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { DocumentNode } from "graphql";
|
||||
import type { ApolloQueryResult, OperationVariables } from "./types.js";
|
||||
export declare function equalByQuery(query: DocumentNode, { data: aData, ...aRest }: Partial<ApolloQueryResult<unknown>>, { data: bData, ...bRest }: Partial<ApolloQueryResult<unknown>>, variables?: OperationVariables): boolean;
|
||||
//# sourceMappingURL=equalByQuery.d.ts.map
|
||||
87
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.js
generated
vendored
Normal file
87
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
import { __rest } from "tslib";
|
||||
import equal from "@wry/equality";
|
||||
import { createFragmentMap, getFragmentDefinitions, getFragmentFromSelection, getMainDefinition, isField, resultKeyNameFromField, shouldInclude, } from "../utilities/index.js";
|
||||
// Returns true if aResult and bResult are deeply equal according to the fields
|
||||
// selected by the given query, ignoring any fields marked as @nonreactive.
|
||||
export function equalByQuery(query, _a, _b, variables) {
|
||||
var aData = _a.data, aRest = __rest(_a, ["data"]);
|
||||
var bData = _b.data, bRest = __rest(_b, ["data"]);
|
||||
return (equal(aRest, bRest) &&
|
||||
equalBySelectionSet(getMainDefinition(query).selectionSet, aData, bData, {
|
||||
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
|
||||
variables: variables,
|
||||
}));
|
||||
}
|
||||
function equalBySelectionSet(selectionSet, aResult, bResult, context) {
|
||||
if (aResult === bResult) {
|
||||
return true;
|
||||
}
|
||||
var seenSelections = new Set();
|
||||
// Returning true from this Array.prototype.every callback function skips the
|
||||
// current field/subtree. Returning false aborts the entire traversal
|
||||
// immediately, causing equalBySelectionSet to return false.
|
||||
return selectionSet.selections.every(function (selection) {
|
||||
// Avoid re-processing the same selection at the same level of recursion, in
|
||||
// case the same field gets included via multiple indirect fragment spreads.
|
||||
if (seenSelections.has(selection))
|
||||
return true;
|
||||
seenSelections.add(selection);
|
||||
// Ignore @skip(if: true) and @include(if: false) fields.
|
||||
if (!shouldInclude(selection, context.variables))
|
||||
return true;
|
||||
// If the field or (named) fragment spread has a @nonreactive directive on
|
||||
// it, we don't care if it's different, so we pretend it's the same.
|
||||
if (selectionHasNonreactiveDirective(selection))
|
||||
return true;
|
||||
if (isField(selection)) {
|
||||
var resultKey = resultKeyNameFromField(selection);
|
||||
var aResultChild = aResult && aResult[resultKey];
|
||||
var bResultChild = bResult && bResult[resultKey];
|
||||
var childSelectionSet = selection.selectionSet;
|
||||
if (!childSelectionSet) {
|
||||
// These are scalar values, so we can compare them with deep equal
|
||||
// without redoing the main recursive work.
|
||||
return equal(aResultChild, bResultChild);
|
||||
}
|
||||
var aChildIsArray = Array.isArray(aResultChild);
|
||||
var bChildIsArray = Array.isArray(bResultChild);
|
||||
if (aChildIsArray !== bChildIsArray)
|
||||
return false;
|
||||
if (aChildIsArray && bChildIsArray) {
|
||||
var length_1 = aResultChild.length;
|
||||
if (bResultChild.length !== length_1) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < length_1; ++i) {
|
||||
if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
|
||||
}
|
||||
else {
|
||||
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
||||
if (fragment) {
|
||||
// The fragment might === selection if it's an inline fragment, but
|
||||
// could be !== if it's a named fragment ...spread.
|
||||
if (selectionHasNonreactiveDirective(fragment))
|
||||
return true;
|
||||
return equalBySelectionSet(fragment.selectionSet,
|
||||
// Notice that we reuse the same aResult and bResult values here,
|
||||
// since the fragment ...spread does not specify a field name, but
|
||||
// consists of multiple fields (within the fragment's selection set)
|
||||
// that should be applied to the current result value(s).
|
||||
aResult, bResult, context);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function selectionHasNonreactiveDirective(selection) {
|
||||
return (!!selection.directives && selection.directives.some(directiveIsNonreactive));
|
||||
}
|
||||
function directiveIsNonreactive(dir) {
|
||||
return dir.name.value === "nonreactive";
|
||||
}
|
||||
//# sourceMappingURL=equalByQuery.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/equalByQuery.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
22
graphql-subscription/node_modules/@apollo/client/core/index.d.ts
generated
vendored
Normal file
22
graphql-subscription/node_modules/@apollo/client/core/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export type { ApolloClientOptions, DefaultOptions } from "./ApolloClient.js";
|
||||
export { ApolloClient, mergeOptions } from "./ApolloClient.js";
|
||||
export type { FetchMoreOptions, UpdateQueryOptions, } from "./ObservableQuery.js";
|
||||
export { ObservableQuery } from "./ObservableQuery.js";
|
||||
export type { QueryOptions, WatchQueryOptions, MutationOptions, SubscriptionOptions, FetchPolicy, WatchQueryFetchPolicy, MutationFetchPolicy, RefetchWritePolicy, ErrorPolicy, FetchMoreQueryOptions, SubscribeToMoreOptions, } from "./watchQueryOptions.js";
|
||||
export { NetworkStatus, isNetworkRequestSettled } from "./networkStatus.js";
|
||||
export * from "./types.js";
|
||||
export type { Resolver, FragmentMatcher } from "./LocalState.js";
|
||||
export { isApolloError, ApolloError } from "../errors/index.js";
|
||||
export type { Transaction, DataProxy, InMemoryCacheConfig, ReactiveVar, TypePolicies, TypePolicy, FieldPolicy, FieldReadFunction, FieldMergeFunction, FieldFunctionOptions, PossibleTypesMap, } from "../cache/index.js";
|
||||
export { Cache, ApolloCache, InMemoryCache, MissingFieldError, defaultDataIdFromObject, makeVar, } from "../cache/index.js";
|
||||
export * from "../cache/inmemory/types.js";
|
||||
export * from "../link/core/index.js";
|
||||
export * from "../link/http/index.js";
|
||||
export type { ServerError } from "../link/utils/index.js";
|
||||
export { fromError, toPromise, fromPromise, throwServerError, } from "../link/utils/index.js";
|
||||
export type { DocumentTransformCacheKey, Observer, ObservableSubscription, Reference, StoreObject, } from "../utilities/index.js";
|
||||
export { DocumentTransform, Observable, isReference, makeReference, } from "../utilities/index.js";
|
||||
import { setVerbosity } from "ts-invariant";
|
||||
export { setVerbosity as setLogVerbosity };
|
||||
export { gql, resetCaches, disableFragmentWarnings, enableExperimentalFragmentVariables, disableExperimentalFragmentVariables, } from "graphql-tag";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
35
graphql-subscription/node_modules/@apollo/client/core/index.js
generated
vendored
Normal file
35
graphql-subscription/node_modules/@apollo/client/core/index.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Core */
|
||||
export { ApolloClient, mergeOptions } from "./ApolloClient.js";
|
||||
export { ObservableQuery } from "./ObservableQuery.js";
|
||||
export { NetworkStatus, isNetworkRequestSettled } from "./networkStatus.js";
|
||||
export * from "./types.js";
|
||||
export { isApolloError, ApolloError } from "../errors/index.js";
|
||||
export { Cache, ApolloCache, InMemoryCache, MissingFieldError, defaultDataIdFromObject, makeVar, } from "../cache/index.js";
|
||||
export * from "../cache/inmemory/types.js";
|
||||
/* Link */
|
||||
export * from "../link/core/index.js";
|
||||
export * from "../link/http/index.js";
|
||||
export { fromError, toPromise, fromPromise, throwServerError, } from "../link/utils/index.js";
|
||||
export { DocumentTransform, Observable, isReference, makeReference, } from "../utilities/index.js";
|
||||
/* Supporting */
|
||||
// The verbosity of invariant.{log,warn,error} can be controlled globally
|
||||
// (for anyone using the same ts-invariant package) by passing "log",
|
||||
// "warn", "error", or "silent" to setVerbosity ("log" is the default).
|
||||
// Note that all invariant.* logging is hidden in production.
|
||||
import { setVerbosity } from "ts-invariant";
|
||||
export { setVerbosity as setLogVerbosity };
|
||||
setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
|
||||
// Note that importing `gql` by itself, then destructuring
|
||||
// additional properties separately before exporting, is intentional.
|
||||
// Due to the way the `graphql-tag` library is setup, certain bundlers
|
||||
// can't find the properties added to the exported `gql` function without
|
||||
// additional guidance (e.g. Rollup - see
|
||||
// https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module).
|
||||
// Instead of having people that are using bundlers with `@apollo/client` add
|
||||
// extra bundler config to help `graphql-tag` exports be found (which would be
|
||||
// awkward since they aren't importing `graphql-tag` themselves), this
|
||||
// workaround of pulling the extra properties off the `gql` function,
|
||||
// then re-exporting them separately, helps keeps bundlers happy without any
|
||||
// additional config changes.
|
||||
export { gql, resetCaches, disableFragmentWarnings, enableExperimentalFragmentVariables, disableExperimentalFragmentVariables, } from "graphql-tag";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/index.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,UAAU;AAGV,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAK/D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAcvD,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAkBhE,OAAO,EACL,KAAK,EACL,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,OAAO,GACR,MAAM,mBAAmB,CAAC;AAE3B,cAAc,4BAA4B,CAAC;AAE3C,UAAU;AAEV,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAWhC,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,aAAa,GACd,MAAM,uBAAuB,CAAC;AAE/B,gBAAgB;AAEhB,yEAAyE;AACzE,qEAAqE;AACrE,uEAAuE;AACvE,6DAA6D;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,CAAC;AAC3C,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEzC,0DAA0D;AAC1D,qEAAqE;AACrE,sEAAsE;AACtE,yEAAyE;AACzE,yCAAyC;AACzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,qEAAqE;AACrE,4EAA4E;AAC5E,6BAA6B;AAC7B,OAAO,EACL,GAAG,EACH,WAAW,EACX,uBAAuB,EACvB,mCAAmC,EACnC,oCAAoC,GACrC,MAAM,aAAa,CAAC","sourcesContent":["/* Core */\n\nexport type { ApolloClientOptions, DefaultOptions } from \"./ApolloClient.js\";\nexport { ApolloClient, mergeOptions } from \"./ApolloClient.js\";\nexport type {\n FetchMoreOptions,\n UpdateQueryOptions,\n} from \"./ObservableQuery.js\";\nexport { ObservableQuery } from \"./ObservableQuery.js\";\nexport type {\n QueryOptions,\n WatchQueryOptions,\n MutationOptions,\n SubscriptionOptions,\n FetchPolicy,\n WatchQueryFetchPolicy,\n MutationFetchPolicy,\n RefetchWritePolicy,\n ErrorPolicy,\n FetchMoreQueryOptions,\n SubscribeToMoreOptions,\n} from \"./watchQueryOptions.js\";\nexport { NetworkStatus, isNetworkRequestSettled } from \"./networkStatus.js\";\nexport * from \"./types.js\";\nexport type { Resolver, FragmentMatcher } from \"./LocalState.js\";\nexport { isApolloError, ApolloError } from \"../errors/index.js\";\n/* Cache */\n\nexport type {\n // All the exports (types) from ../cache, minus cacheSlot,\n // which we want to keep semi-private.\n Transaction,\n DataProxy,\n InMemoryCacheConfig,\n ReactiveVar,\n TypePolicies,\n TypePolicy,\n FieldPolicy,\n FieldReadFunction,\n FieldMergeFunction,\n FieldFunctionOptions,\n PossibleTypesMap,\n} from \"../cache/index.js\";\nexport {\n Cache,\n ApolloCache,\n InMemoryCache,\n MissingFieldError,\n defaultDataIdFromObject,\n makeVar,\n} from \"../cache/index.js\";\n\nexport * from \"../cache/inmemory/types.js\";\n\n/* Link */\n\nexport * from \"../link/core/index.js\";\nexport * from \"../link/http/index.js\";\nexport type { ServerError } from \"../link/utils/index.js\";\nexport {\n fromError,\n toPromise,\n fromPromise,\n throwServerError,\n} from \"../link/utils/index.js\";\n\n/* Utilities */\n\nexport type {\n DocumentTransformCacheKey,\n Observer,\n ObservableSubscription,\n Reference,\n StoreObject,\n} from \"../utilities/index.js\";\nexport {\n DocumentTransform,\n Observable,\n isReference,\n makeReference,\n} from \"../utilities/index.js\";\n\n/* Supporting */\n\n// The verbosity of invariant.{log,warn,error} can be controlled globally\n// (for anyone using the same ts-invariant package) by passing \"log\",\n// \"warn\", \"error\", or \"silent\" to setVerbosity (\"log\" is the default).\n// Note that all invariant.* logging is hidden in production.\nimport { setVerbosity } from \"ts-invariant\";\nexport { setVerbosity as setLogVerbosity };\nsetVerbosity(__DEV__ ? \"log\" : \"silent\");\n\n// Note that importing `gql` by itself, then destructuring\n// additional properties separately before exporting, is intentional.\n// Due to the way the `graphql-tag` library is setup, certain bundlers\n// can't find the properties added to the exported `gql` function without\n// additional guidance (e.g. Rollup - see\n// https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module).\n// Instead of having people that are using bundlers with `@apollo/client` add\n// extra bundler config to help `graphql-tag` exports be found (which would be\n// awkward since they aren't importing `graphql-tag` themselves), this\n// workaround of pulling the extra properties off the `gql` function,\n// then re-exporting them separately, helps keeps bundlers happy without any\n// additional config changes.\nexport {\n gql,\n resetCaches,\n disableFragmentWarnings,\n enableExperimentalFragmentVariables,\n disableExperimentalFragmentVariables,\n} from \"graphql-tag\";\n"]}
|
||||
51
graphql-subscription/node_modules/@apollo/client/core/networkStatus.d.ts
generated
vendored
Normal file
51
graphql-subscription/node_modules/@apollo/client/core/networkStatus.d.ts
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* The current status of a query’s execution in our system.
|
||||
*/
|
||||
export declare enum NetworkStatus {
|
||||
/**
|
||||
* The query has never been run before and the query is now currently running. A query will still
|
||||
* have this network status even if a partial data result was returned from the cache, but a
|
||||
* query was dispatched anyway.
|
||||
*/
|
||||
loading = 1,
|
||||
/**
|
||||
* If `setVariables` was called and a query was fired because of that then the network status
|
||||
* will be `setVariables` until the result of that query comes back.
|
||||
*/
|
||||
setVariables = 2,
|
||||
/**
|
||||
* Indicates that `fetchMore` was called on this query and that the query created is currently in
|
||||
* flight.
|
||||
*/
|
||||
fetchMore = 3,
|
||||
/**
|
||||
* Similar to the `setVariables` network status. It means that `refetch` was called on a query
|
||||
* and the refetch request is currently in flight.
|
||||
*/
|
||||
refetch = 4,
|
||||
/**
|
||||
* Indicates that a polling query is currently in flight. So for example if you are polling a
|
||||
* query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
|
||||
* a poll request has been sent but not resolved.
|
||||
*/
|
||||
poll = 6,
|
||||
/**
|
||||
* No request is in flight for this query, and no errors happened. Everything is OK.
|
||||
*/
|
||||
ready = 7,
|
||||
/**
|
||||
* No request is in flight for this query, but one or more errors were detected.
|
||||
*/
|
||||
error = 8
|
||||
}
|
||||
/**
|
||||
* Returns true if there is currently a network request in flight according to a given network
|
||||
* status.
|
||||
*/
|
||||
export declare function isNetworkRequestInFlight(networkStatus?: NetworkStatus): boolean;
|
||||
/**
|
||||
* Returns true if the network request is in ready or error state according to a given network
|
||||
* status.
|
||||
*/
|
||||
export declare function isNetworkRequestSettled(networkStatus?: NetworkStatus): boolean;
|
||||
//# sourceMappingURL=networkStatus.d.ts.map
|
||||
56
graphql-subscription/node_modules/@apollo/client/core/networkStatus.js
generated
vendored
Normal file
56
graphql-subscription/node_modules/@apollo/client/core/networkStatus.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* The current status of a query’s execution in our system.
|
||||
*/
|
||||
export var NetworkStatus;
|
||||
(function (NetworkStatus) {
|
||||
/**
|
||||
* The query has never been run before and the query is now currently running. A query will still
|
||||
* have this network status even if a partial data result was returned from the cache, but a
|
||||
* query was dispatched anyway.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
||||
/**
|
||||
* If `setVariables` was called and a query was fired because of that then the network status
|
||||
* will be `setVariables` until the result of that query comes back.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
|
||||
/**
|
||||
* Indicates that `fetchMore` was called on this query and that the query created is currently in
|
||||
* flight.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
|
||||
/**
|
||||
* Similar to the `setVariables` network status. It means that `refetch` was called on a query
|
||||
* and the refetch request is currently in flight.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
|
||||
/**
|
||||
* Indicates that a polling query is currently in flight. So for example if you are polling a
|
||||
* query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
|
||||
* a poll request has been sent but not resolved.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
|
||||
/**
|
||||
* No request is in flight for this query, and no errors happened. Everything is OK.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
|
||||
/**
|
||||
* No request is in flight for this query, but one or more errors were detected.
|
||||
*/
|
||||
NetworkStatus[NetworkStatus["error"] = 8] = "error";
|
||||
})(NetworkStatus || (NetworkStatus = {}));
|
||||
/**
|
||||
* Returns true if there is currently a network request in flight according to a given network
|
||||
* status.
|
||||
*/
|
||||
export function isNetworkRequestInFlight(networkStatus) {
|
||||
return networkStatus ? networkStatus < 7 : false;
|
||||
}
|
||||
/**
|
||||
* Returns true if the network request is in ready or error state according to a given network
|
||||
* status.
|
||||
*/
|
||||
export function isNetworkRequestSettled(networkStatus) {
|
||||
return networkStatus === 7 || networkStatus === 8;
|
||||
}
|
||||
//# sourceMappingURL=networkStatus.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/networkStatus.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/networkStatus.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"networkStatus.js","sourceRoot":"","sources":["../../src/core/networkStatus.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,aA0CX;AA1CD,WAAY,aAAa;IACvB;;;;OAIG;IACH,uDAAW,CAAA;IAEX;;;OAGG;IACH,iEAAgB,CAAA;IAEhB;;;OAGG;IACH,2DAAa,CAAA;IAEb;;;OAGG;IACH,uDAAW,CAAA;IAEX;;;;OAIG;IACH,iDAAQ,CAAA;IAER;;OAEG;IACH,mDAAS,CAAA;IAET;;OAEG;IACH,mDAAS,CAAA;AACX,CAAC,EA1CW,aAAa,KAAb,aAAa,QA0CxB;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,aAA6B;IAE7B,OAAO,aAAa,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,aAA6B;IAE7B,OAAO,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * The current status of a query’s execution in our system.\n */\nexport enum NetworkStatus {\n /**\n * The query has never been run before and the query is now currently running. A query will still\n * have this network status even if a partial data result was returned from the cache, but a\n * query was dispatched anyway.\n */\n loading = 1,\n\n /**\n * If `setVariables` was called and a query was fired because of that then the network status\n * will be `setVariables` until the result of that query comes back.\n */\n setVariables = 2,\n\n /**\n * Indicates that `fetchMore` was called on this query and that the query created is currently in\n * flight.\n */\n fetchMore = 3,\n\n /**\n * Similar to the `setVariables` network status. It means that `refetch` was called on a query\n * and the refetch request is currently in flight.\n */\n refetch = 4,\n\n /**\n * Indicates that a polling query is currently in flight. So for example if you are polling a\n * query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever\n * a poll request has been sent but not resolved.\n */\n poll = 6,\n\n /**\n * No request is in flight for this query, and no errors happened. Everything is OK.\n */\n ready = 7,\n\n /**\n * No request is in flight for this query, but one or more errors were detected.\n */\n error = 8,\n}\n\n/**\n * Returns true if there is currently a network request in flight according to a given network\n * status.\n */\nexport function isNetworkRequestInFlight(\n networkStatus?: NetworkStatus\n): boolean {\n return networkStatus ? networkStatus < 7 : false;\n}\n\n/**\n * Returns true if the network request is in ready or error state according to a given network\n * status.\n */\nexport function isNetworkRequestSettled(\n networkStatus?: NetworkStatus\n): boolean {\n return networkStatus === 7 || networkStatus === 8;\n}\n"]}
|
||||
8
graphql-subscription/node_modules/@apollo/client/core/package.json
generated
vendored
Normal file
8
graphql-subscription/node_modules/@apollo/client/core/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@apollo/client/core",
|
||||
"type": "module",
|
||||
"main": "core.cjs",
|
||||
"module": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"sideEffects": false
|
||||
}
|
||||
86
graphql-subscription/node_modules/@apollo/client/core/types.d.ts
generated
vendored
Normal file
86
graphql-subscription/node_modules/@apollo/client/core/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import type { DocumentNode, GraphQLError } from "graphql";
|
||||
import type { ApolloCache } from "../cache/index.js";
|
||||
import type { FetchResult } from "../link/core/index.js";
|
||||
import type { ApolloError } from "../errors/index.js";
|
||||
import type { QueryInfo } from "./QueryInfo.js";
|
||||
import type { NetworkStatus } from "./networkStatus.js";
|
||||
import type { Resolver } from "./LocalState.js";
|
||||
import type { ObservableQuery } from "./ObservableQuery.js";
|
||||
import type { QueryOptions } from "./watchQueryOptions.js";
|
||||
import type { Cache } from "../cache/index.js";
|
||||
import type { IsStrictlyAny } from "../utilities/index.js";
|
||||
export type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
||||
export type MethodKeys<T> = {
|
||||
[P in keyof T]: T[P] extends Function ? P : never;
|
||||
}[keyof T];
|
||||
export interface DefaultContext extends Record<string, any> {
|
||||
}
|
||||
export type QueryListener = (queryInfo: QueryInfo) => void;
|
||||
export type OnQueryUpdated<TResult> = (observableQuery: ObservableQuery<any>, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => boolean | TResult;
|
||||
export type RefetchQueryDescriptor = string | DocumentNode;
|
||||
export type InternalRefetchQueryDescriptor = RefetchQueryDescriptor | QueryOptions;
|
||||
type RefetchQueriesIncludeShorthand = "all" | "active";
|
||||
export type RefetchQueriesInclude = RefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
|
||||
export type InternalRefetchQueriesInclude = InternalRefetchQueryDescriptor[] | RefetchQueriesIncludeShorthand;
|
||||
export interface RefetchQueriesOptions<TCache extends ApolloCache<any>, TResult> {
|
||||
updateCache?: (cache: TCache) => void;
|
||||
include?: RefetchQueriesInclude;
|
||||
optimistic?: boolean;
|
||||
onQueryUpdated?: OnQueryUpdated<TResult> | null;
|
||||
}
|
||||
export type RefetchQueriesPromiseResults<TResult> = IsStrictlyAny<TResult> extends true ? any[] : TResult extends boolean ? ApolloQueryResult<any>[] : TResult extends PromiseLike<infer U> ? U[] : TResult[];
|
||||
export interface RefetchQueriesResult<TResult> extends Promise<RefetchQueriesPromiseResults<TResult>> {
|
||||
queries: ObservableQuery<any>[];
|
||||
results: InternalRefetchQueriesResult<TResult>[];
|
||||
}
|
||||
export interface InternalRefetchQueriesOptions<TCache extends ApolloCache<any>, TResult> extends Omit<RefetchQueriesOptions<TCache, TResult>, "include"> {
|
||||
include?: InternalRefetchQueriesInclude;
|
||||
removeOptimistic?: string;
|
||||
}
|
||||
export type InternalRefetchQueriesResult<TResult> = TResult extends boolean ? Promise<ApolloQueryResult<any>> : TResult;
|
||||
export type InternalRefetchQueriesMap<TResult> = Map<ObservableQuery<any>, InternalRefetchQueriesResult<TResult>>;
|
||||
export type { QueryOptions as PureQueryOptions };
|
||||
export type OperationVariables = Record<string, any>;
|
||||
export interface ApolloQueryResult<T> {
|
||||
data: T;
|
||||
/**
|
||||
* A list of any errors that occurred during server-side execution of a GraphQL operation.
|
||||
* See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
|
||||
*/
|
||||
errors?: ReadonlyArray<GraphQLError>;
|
||||
/**
|
||||
* The single Error object that is passed to onError and useQuery hooks, and is often thrown during manual `client.query` calls.
|
||||
* This will contain both a NetworkError field and any GraphQLErrors.
|
||||
* See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
|
||||
*/
|
||||
error?: ApolloError;
|
||||
loading: boolean;
|
||||
networkStatus: NetworkStatus;
|
||||
partial?: boolean;
|
||||
}
|
||||
export type MutationQueryReducer<T> = (previousResult: Record<string, any>, options: {
|
||||
mutationResult: FetchResult<T>;
|
||||
queryName: string | undefined;
|
||||
queryVariables: Record<string, any>;
|
||||
}) => Record<string, any>;
|
||||
export type MutationQueryReducersMap<T = {
|
||||
[key: string]: any;
|
||||
}> = {
|
||||
[queryName: string]: MutationQueryReducer<T>;
|
||||
};
|
||||
/**
|
||||
* @deprecated Use `MutationUpdaterFunction` instead.
|
||||
*/
|
||||
export type MutationUpdaterFn<T = {
|
||||
[key: string]: any;
|
||||
}> = (cache: ApolloCache<T>, mutationResult: FetchResult<T>) => void;
|
||||
export type MutationUpdaterFunction<TData, TVariables, TContext, TCache extends ApolloCache<any>> = (cache: TCache, result: Omit<FetchResult<TData>, "context">, options: {
|
||||
context?: TContext;
|
||||
variables?: TVariables;
|
||||
}) => void;
|
||||
export interface Resolvers {
|
||||
[key: string]: {
|
||||
[field: string]: Resolver;
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
2
graphql-subscription/node_modules/@apollo/client/core/types.js
generated
vendored
Normal file
2
graphql-subscription/node_modules/@apollo/client/core/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/types.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/types.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
450
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.d.ts
generated
vendored
Normal file
450
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,450 @@
|
||||
import type { DocumentNode } from "graphql";
|
||||
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
||||
import type { FetchResult } from "../link/core/index.js";
|
||||
import type { DefaultContext, MutationQueryReducersMap, OperationVariables, MutationUpdaterFunction, OnQueryUpdated, InternalRefetchQueriesInclude } from "./types.js";
|
||||
import type { ApolloCache } from "../cache/index.js";
|
||||
import type { ObservableQuery } from "./ObservableQuery.js";
|
||||
import type { IgnoreModifier } from "../cache/core/types/common.js";
|
||||
/**
|
||||
* fetchPolicy determines where the client may return a result from. The options are:
|
||||
* - cache-first (default): return result from cache. Only fetch from network if cached result is not available.
|
||||
* - cache-and-network: return result from cache first (if it exists), then return network result once it's available.
|
||||
* - cache-only: return result from cache if available, fail otherwise.
|
||||
* - no-cache: return result from network, fail if network call doesn't succeed, don't save to cache
|
||||
* - network-only: return result from network, fail if network call doesn't succeed, save to cache
|
||||
* - standby: only for queries that aren't actively watched, but should be available for refetch and updateQueries.
|
||||
*/
|
||||
export type FetchPolicy = "cache-first" | "network-only" | "cache-only" | "no-cache" | "standby";
|
||||
export type WatchQueryFetchPolicy = FetchPolicy | "cache-and-network";
|
||||
export type MutationFetchPolicy = Extract<FetchPolicy, "network-only" | "no-cache">;
|
||||
export type RefetchWritePolicy = "merge" | "overwrite";
|
||||
/**
|
||||
* errorPolicy determines the level of events for errors in the execution result. The options are:
|
||||
* - none (default): any errors from the request are treated like runtime errors and the observable is stopped
|
||||
* - ignore: errors from the request do not stop the observable, but also don't call `next`
|
||||
* - all: errors are treated like data and will notify observables
|
||||
*/
|
||||
export type ErrorPolicy = "none" | "ignore" | "all";
|
||||
/**
|
||||
* Query options.
|
||||
*/
|
||||
export interface QueryOptions<TVariables = OperationVariables, TData = any> {
|
||||
/**
|
||||
* A GraphQL query string parsed into an AST with the gql template literal.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
query: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
||||
/**
|
||||
* An object containing all of the GraphQL variables your query requires to execute.
|
||||
*
|
||||
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
variables?: TVariables;
|
||||
/**
|
||||
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
||||
*
|
||||
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
||||
*
|
||||
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
errorPolicy?: ErrorPolicy;
|
||||
/**
|
||||
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
context?: DefaultContext;
|
||||
/**
|
||||
* Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server).
|
||||
*
|
||||
* For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
|
||||
*
|
||||
* The default value is `cache-first`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
fetchPolicy?: FetchPolicy;
|
||||
/**
|
||||
* Specifies the interval (in milliseconds) at which the query polls for updated results.
|
||||
*
|
||||
* The default value is `0` (no polling).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
pollInterval?: number;
|
||||
/**
|
||||
* If `true`, the in-progress query's associated component re-renders whenever the network status changes or a network error occurs.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
notifyOnNetworkStatusChange?: boolean;
|
||||
/**
|
||||
* If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
returnPartialData?: boolean;
|
||||
/**
|
||||
* If `true`, causes a query refetch if the query result is detected as partial.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* Setting this option is unnecessary in Apollo Client 3, thanks to a more consistent application of fetch policies. It might be removed in a future release.
|
||||
*/
|
||||
partialRefetch?: boolean;
|
||||
/**
|
||||
* Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
|
||||
*/
|
||||
canonizeResults?: boolean;
|
||||
}
|
||||
/**
|
||||
* Watched query options.
|
||||
*/
|
||||
export interface WatchQueryOptions<TVariables extends OperationVariables = OperationVariables, TData = any> extends SharedWatchQueryOptions<TVariables, TData> {
|
||||
/**
|
||||
* A GraphQL query string parsed into an AST with the gql template literal.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
query: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
||||
}
|
||||
export interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData> {
|
||||
/**
|
||||
* Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending a request to the server).
|
||||
*
|
||||
* For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
|
||||
*
|
||||
* The default value is `cache-first`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
fetchPolicy?: WatchQueryFetchPolicy;
|
||||
/**
|
||||
* Specifies the {@link FetchPolicy} to be used after this query has completed.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
|
||||
/**
|
||||
* Defaults to the initial value of options.fetchPolicy, but can be explicitly configured to specify the WatchQueryFetchPolicy to revert back to whenever variables change (unless nextFetchPolicy intervenes).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
initialFetchPolicy?: WatchQueryFetchPolicy;
|
||||
/**
|
||||
* Specifies whether a `NetworkStatus.refetch` operation should merge incoming field data with existing data, or overwrite the existing data. Overwriting is probably preferable, but merging is currently the default behavior, for backwards compatibility with Apollo Client 3.x.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
refetchWritePolicy?: RefetchWritePolicy;
|
||||
/**
|
||||
* An object containing all of the GraphQL variables your query requires to execute.
|
||||
*
|
||||
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
variables?: TVariables;
|
||||
/**
|
||||
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
||||
*
|
||||
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
||||
*
|
||||
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
errorPolicy?: ErrorPolicy;
|
||||
/**
|
||||
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
context?: DefaultContext;
|
||||
/**
|
||||
* Specifies the interval (in milliseconds) at which the query polls for updated results.
|
||||
*
|
||||
* The default value is `0` (no polling).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
pollInterval?: number;
|
||||
/**
|
||||
* If `true`, the in-progress query's associated component re-renders whenever the network status changes or a network error occurs.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
notifyOnNetworkStatusChange?: boolean;
|
||||
/**
|
||||
* If `true`, the query can return partial results from the cache if the cache doesn't contain results for all queried fields.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
returnPartialData?: boolean;
|
||||
/**
|
||||
* If `true`, causes a query refetch if the query result is detected as partial.
|
||||
*
|
||||
* The default value is `false`.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* Setting this option is unnecessary in Apollo Client 3, thanks to a more consistent application of fetch policies. It might be removed in a future release.
|
||||
*/
|
||||
partialRefetch?: boolean;
|
||||
/**
|
||||
* Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore. A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
|
||||
*/
|
||||
canonizeResults?: boolean;
|
||||
/**
|
||||
* A callback function that's called whenever a refetch attempt occurs while polling. If the function returns `true`, the refetch is skipped and not reattempted until the next poll interval.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
skipPollAttempt?: () => boolean;
|
||||
}
|
||||
export interface NextFetchPolicyContext<TData, TVariables extends OperationVariables> {
|
||||
reason: "after-fetch" | "variables-changed";
|
||||
observable: ObservableQuery<TData, TVariables>;
|
||||
options: WatchQueryOptions<TVariables, TData>;
|
||||
initialFetchPolicy: WatchQueryFetchPolicy;
|
||||
}
|
||||
export interface FetchMoreQueryOptions<TVariables, TData = any> {
|
||||
/**
|
||||
* A GraphQL query string parsed into an AST with the gql template literal.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
||||
/**
|
||||
* An object containing all of the GraphQL variables your query requires to execute.
|
||||
*
|
||||
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
variables?: Partial<TVariables>;
|
||||
context?: DefaultContext;
|
||||
}
|
||||
export type UpdateQueryFn<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = (previousQueryResult: TData, options: {
|
||||
subscriptionData: {
|
||||
data: TSubscriptionData;
|
||||
};
|
||||
variables?: TSubscriptionVariables;
|
||||
}) => TData;
|
||||
export type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
|
||||
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
|
||||
variables?: TSubscriptionVariables;
|
||||
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
|
||||
onError?: (error: Error) => void;
|
||||
context?: DefaultContext;
|
||||
};
|
||||
export interface SubscriptionOptions<TVariables = OperationVariables, TData = any> {
|
||||
/**
|
||||
* A GraphQL document, often created with `gql` from the `graphql-tag` package, that contains a single subscription inside of it.
|
||||
*/
|
||||
query: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
||||
/**
|
||||
* An object containing all of the variables your subscription needs to execute
|
||||
*/
|
||||
variables?: TVariables;
|
||||
/**
|
||||
* How you want your component to interact with the Apollo cache. For details, see [Setting a fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy).
|
||||
*/
|
||||
fetchPolicy?: FetchPolicy;
|
||||
/**
|
||||
* Specifies the {@link ErrorPolicy} to be used for this operation
|
||||
*/
|
||||
errorPolicy?: ErrorPolicy;
|
||||
/**
|
||||
* Shared context between your component and your network interface (Apollo Link).
|
||||
*/
|
||||
context?: DefaultContext;
|
||||
}
|
||||
export interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> {
|
||||
/**
|
||||
* By providing either an object or a callback function that, when invoked after a mutation, allows you to return optimistic data and optionally skip updates via the `IGNORE` sentinel object, Apollo Client caches this temporary (and potentially incorrect) response until the mutation completes, enabling more responsive UI updates.
|
||||
*
|
||||
* For more information, see [Optimistic mutation results](https://www.apollographql.com/docs/react/performance/optimistic-ui/).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
|
||||
IGNORE: IgnoreModifier;
|
||||
}) => TData);
|
||||
/**
|
||||
* A {@link MutationQueryReducersMap}, which is map from query names to mutation query reducers. Briefly, this map defines how to incorporate the results of the mutation into the results of queries that are currently being watched by your application.
|
||||
*/
|
||||
updateQueries?: MutationQueryReducersMap<TData>;
|
||||
/**
|
||||
* An array (or a function that _returns_ an array) that specifies which queries you want to refetch after the mutation occurs.
|
||||
*
|
||||
* Each array value can be either:
|
||||
*
|
||||
* - An object containing the `query` to execute, along with any `variables`
|
||||
*
|
||||
* - A string indicating the operation name of the query to refetch
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
|
||||
/**
|
||||
* If `true`, makes sure all queries included in `refetchQueries` are completed before the mutation is considered complete.
|
||||
*
|
||||
* The default value is `false` (queries are refetched asynchronously).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
awaitRefetchQueries?: boolean;
|
||||
/**
|
||||
* A function used to update the Apollo Client cache after the mutation completes.
|
||||
*
|
||||
* For more information, see [Updating the cache after a mutation](https://www.apollographql.com/docs/react/data/mutations#updating-the-cache-after-a-mutation).
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
|
||||
/**
|
||||
* Optional callback for intercepting queries whose cache data has been updated by the mutation, as well as any queries specified in the `refetchQueries: [...]` list passed to `client.mutate`.
|
||||
*
|
||||
* Returning a `Promise` from `onQueryUpdated` will cause the final mutation `Promise` to await the returned `Promise`. Returning `false` causes the query to be ignored.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
onQueryUpdated?: OnQueryUpdated<any>;
|
||||
/**
|
||||
* Specifies how the mutation handles a response that returns both GraphQL errors and partial results.
|
||||
*
|
||||
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
||||
*
|
||||
* The default value is `none`, meaning that the mutation result includes error details but _not_ partial results.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
errorPolicy?: ErrorPolicy;
|
||||
/**
|
||||
* An object containing all of the GraphQL variables your mutation requires to execute.
|
||||
*
|
||||
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
variables?: TVariables;
|
||||
/**
|
||||
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 2. Networking options
|
||||
*/
|
||||
context?: TContext;
|
||||
}
|
||||
export interface MutationOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationSharedOptions<TData, TVariables, TContext, TCache> {
|
||||
/**
|
||||
* A GraphQL document, often created with `gql` from the `graphql-tag` package, that contains a single mutation inside of it.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 1. Operation options
|
||||
*/
|
||||
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
||||
}
|
||||
export interface MutationSharedOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationBaseOptions<TData, TVariables, TContext, TCache> {
|
||||
/**
|
||||
* Provide `no-cache` if the mutation's result should _not_ be written to the Apollo Client cache.
|
||||
*
|
||||
* The default value is `network-only` (which means the result _is_ written to the cache).
|
||||
*
|
||||
* Unlike queries, mutations _do not_ support [fetch policies](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy) besides `network-only` and `no-cache`.
|
||||
*
|
||||
* @docGroup
|
||||
*
|
||||
* 3. Caching options
|
||||
*/
|
||||
fetchPolicy?: MutationFetchPolicy;
|
||||
/**
|
||||
* To avoid retaining sensitive information from mutation root field arguments, Apollo Client v3.4+ automatically clears any `ROOT_MUTATION` fields from the cache after each mutation finishes. If you need this information to remain in the cache, you can prevent the removal by passing `keepRootFields: true` to the mutation. `ROOT_MUTATION` result data are also passed to the mutation `update` function, so we recommend obtaining the results that way, rather than using this option, if possible.
|
||||
*/
|
||||
keepRootFields?: boolean;
|
||||
}
|
||||
//# sourceMappingURL=watchQueryOptions.d.ts.map
|
||||
2
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.js
generated
vendored
Normal file
2
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=watchQueryOptions.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/core/watchQueryOptions.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user