@apollo/client 3.3.7 → 3.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -0
- package/apollo-client.cjs.js +66 -52
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -1
- package/cache/cache.cjs.js +27 -24
- package/cache/cache.cjs.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +4 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/reactiveVars.d.ts +1 -0
- package/cache/inmemory/reactiveVars.d.ts.map +1 -1
- package/cache/inmemory/reactiveVars.js +25 -25
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +2 -2
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -0
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +8 -3
- package/core/QueryInfo.js.map +1 -1
- package/core/core.cjs.js +10 -5
- package/core/core.cjs.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +9 -10
- package/react/data/MutationData.d.ts +1 -1
- package/react/data/MutationData.d.ts.map +1 -1
- package/react/data/MutationData.js.map +1 -1
- package/react/data/QueryData.d.ts +2 -2
- package/react/data/QueryData.d.ts.map +1 -1
- package/react/data/QueryData.js.map +1 -1
- package/react/hooks/hooks.cjs.js +14 -18
- package/react/hooks/hooks.cjs.js.map +1 -1
- package/react/hooks/useReactiveVar.d.ts.map +1 -1
- package/react/hooks/useReactiveVar.js +3 -0
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +11 -18
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +2 -2
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -5
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/Observable.d.ts +1 -0
- package/utilities/observables/Observable.d.ts.map +1 -1
- package/utilities/observables/Observable.js.map +1 -1
- package/utilities/observables/subclassing.d.ts +4 -0
- package/utilities/observables/subclassing.d.ts.map +1 -0
- package/utilities/observables/subclassing.js +12 -0
- package/utilities/observables/subclassing.js.map +1 -0
- package/utilities/utilities.cjs.js +16 -5
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
package/core/QueryInfo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryInfo.js","sourceRoot":"","sources":["../../src/core/QueryInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAOtC,OAAO,EAEL,eAAe,EACf,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAUzB,IAAM,uBAAuB,GAAG,IAAI,CAClC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAC9B,EAA4B,CAAC;AAE9B,SAAS,0BAA0B,CACjC,KAAuB,EACvB,UAAkC;IAElC,IAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,KAAK,CAAC,UAAU,CAAC,GAAG;YAClB,uBAAuB,CAAC,GAAG,CACzB,KAAK,EAKL,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAE,GAAG,CAAC,CAAC,GAAG,I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BAAM;gBACL,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;aACzB;SACF;IACH,CAAC;IAEM,6BAAS,GAAhB;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC;IAClD,CAAC;IAEM,6BAAS,GAAhB,UAAiB,KAAkB;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;QAExB,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAE1B,IAAI,KAAK,CAAC,aAAa,EAAE;YACvB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;SAC1C;QAED,IAAI,KAAK,CAAC,YAAY,EAAE;YACtB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;SACxC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IACH,gBAAC;AAAD,CAAC,AAhWD,IAgWC;;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAAsB,EACtB,WAAiC;IAAjC,4BAAA,EAAA,oBAAiC;IAEjC,IAAM,YAAY,GAChB,WAAW,KAAK,QAAQ;QACxB,WAAW,KAAK,KAAK,CAAC;IACxB,IAAI,eAAe,GAAG,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,eAAe,IAAI,YAAY,IAAI,MAAM,CAAC,IAAI,EAAE;QACnD,eAAe,GAAG,IAAI,CAAC;KACxB;IACD,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { DocumentNode, GraphQLError } from 'graphql';\nimport { equal } from \"@wry/equality\";\n\nimport { Cache, ApolloCache } from '../cache';\nimport { WatchQueryOptions, ErrorPolicy } from './watchQueryOptions';\nimport { ObservableQuery } from './ObservableQuery';\nimport { QueryListener } from './types';\nimport { FetchResult } from '../link/core';\nimport {\n ObservableSubscription,\n isNonEmptyArray,\n graphQLResultHasError,\n canUseWeakMap,\n} from '../utilities';\nimport {\n NetworkStatus,\n isNetworkRequestInFlight,\n} from './networkStatus';\nimport { ApolloError } from '../errors';\n\nexport type QueryStoreValue = Pick<QueryInfo,\n | \"variables\"\n | \"networkStatus\"\n | \"networkError\"\n | \"graphQLErrors\"\n >;\n\nconst destructiveMethodCounts = new (\n canUseWeakMap ? WeakMap : Map\n)<ApolloCache<any>, number>();\n\nfunction wrapDestructiveCacheMethod(\n cache: ApolloCache<any>,\n methodName: keyof ApolloCache<any>,\n) {\n const original = cache[methodName];\n if (typeof original === \"function\") {\n cache[methodName] = function () {\n destructiveMethodCounts.set(\n cache,\n // The %1e15 allows the count to wrap around to 0 safely every\n // quadrillion evictions, so there's no risk of overflow. To be\n // clear, this is more of a pedantic principle than something\n // that matters in any conceivable practical scenario.\n (destructiveMethodCounts.get(cache)! + 1) % 1e15,\n );\n return original.apply(this, arguments);\n };\n }\n}\n\nfunction cancelNotifyTimeout(info: QueryInfo) {\n if (info[\"notifyTimeout\"]) {\n clearTimeout(info[\"notifyTimeout\"]);\n info[\"notifyTimeout\"] = void 0;\n }\n}\n\n// A QueryInfo object represents a single query managed by the\n// QueryManager, which tracks all QueryInfo objects by queryId in its\n// this.queries Map. QueryInfo objects store the latest results and errors\n// for the given query, and are responsible for reporting those results to\n// the corresponding ObservableQuery, via the QueryInfo.notify method.\n// Results are reported asynchronously whenever setDiff marks the\n// QueryInfo object as dirty, though a call to the QueryManager's\n// broadcastQueries method may trigger the notification before it happens\n// automatically. This class used to be a simple interface type without\n// any field privacy or meaningful methods, which is why it still has so\n// many public fields. The effort to lock down and simplify the QueryInfo\n// interface is ongoing, and further improvements are welcome.\nexport class QueryInfo {\n listeners = new Set<QueryListener>();\n document: DocumentNode | null = null;\n lastRequestId = 1;\n subscriptions = new Set<ObservableSubscription>();\n variables?: Record<string, any>;\n networkStatus?: NetworkStatus;\n networkError?: Error | null;\n graphQLErrors?: ReadonlyArray<GraphQLError>;\n stopped = false;\n\n constructor(private cache: ApolloCache<any>) {\n // Track how often cache.evict is called, since we want eviction to\n // override the feud-stopping logic in the markResult method, by\n // causing shouldWrite to return true. Wrapping the cache.evict method\n // is a bit of a hack, but it saves us from having to make eviction\n // counting an official part of the ApolloCache API.\n if (!destructiveMethodCounts.has(cache)) {\n destructiveMethodCounts.set(cache, 0);\n wrapDestructiveCacheMethod(cache, \"evict\");\n wrapDestructiveCacheMethod(cache, \"modify\");\n wrapDestructiveCacheMethod(cache, \"reset\");\n }\n }\n\n public init(query: {\n document: DocumentNode;\n variables: Record<string, any> | undefined,\n // The initial networkStatus for this fetch, most often\n // NetworkStatus.loading, but also possibly fetchMore, poll, refetch,\n // or setVariables.\n networkStatus?: NetworkStatus,\n observableQuery?: ObservableQuery<any>;\n lastRequestId?: number;\n }): this {\n let networkStatus = query.networkStatus || NetworkStatus.loading;\n if (this.variables &&\n this.networkStatus !== NetworkStatus.loading &&\n !equal(this.variables, query.variables)) {\n networkStatus = NetworkStatus.setVariables;\n }\n\n if (!equal(query.variables, this.variables)) {\n this.diff = null;\n }\n\n Object.assign(this, {\n document: query.document,\n variables: query.variables,\n networkError: null,\n graphQLErrors: this.graphQLErrors || [],\n networkStatus,\n });\n\n if (query.observableQuery) {\n this.setObservableQuery(query.observableQuery);\n }\n\n if (query.lastRequestId) {\n this.lastRequestId = query.lastRequestId;\n }\n\n return this;\n }\n\n private dirty: boolean = false;\n\n private notifyTimeout?: ReturnType<typeof setTimeout>;\n\n private diff: Cache.DiffResult<any> | null = null;\n\n getDiff(variables = this.variables): Cache.DiffResult<any> {\n if (this.diff && equal(variables, this.variables)) {\n return this.diff;\n }\n\n this.updateWatch(this.variables = variables);\n\n return this.diff = this.cache.diff({\n query: this.document!,\n variables,\n returnPartialData: true,\n optimistic: true,\n });\n }\n\n setDiff(diff: Cache.DiffResult<any> | null) {\n const oldDiff = this.diff;\n this.diff = diff;\n if (!this.dirty &&\n (diff && diff.result) !== (oldDiff && oldDiff.result)) {\n this.dirty = true;\n if (!this.notifyTimeout) {\n this.notifyTimeout = setTimeout(() => this.notify(), 0);\n }\n }\n }\n\n public readonly observableQuery: ObservableQuery<any> | null = null;\n private oqListener?: QueryListener;\n\n setObservableQuery(oq: ObservableQuery<any> | null) {\n if (oq === this.observableQuery) return;\n\n if (this.oqListener) {\n this.listeners.delete(this.oqListener);\n }\n\n (this as any).observableQuery = oq;\n\n if (oq) {\n oq[\"queryInfo\"] = this;\n this.listeners.add(this.oqListener = () => {\n // If this.diff came from an optimistic transaction, deliver the\n // current cache data to the ObservableQuery, but don't perform a\n // full reobservation, since oq.reobserve might make a network\n // request, and we don't want to trigger network requests for\n // optimistic updates.\n if (this.getDiff().fromOptimisticTransaction) {\n oq[\"observe\"]();\n } else {\n oq.reobserve();\n }\n });\n } else {\n delete this.oqListener;\n }\n }\n\n notify() {\n cancelNotifyTimeout(this);\n\n if (this.shouldNotify()) {\n this.listeners.forEach(listener => listener(this));\n }\n\n this.dirty = false;\n }\n\n private shouldNotify() {\n if (!this.dirty || !this.listeners.size) {\n return false;\n }\n\n if (isNetworkRequestInFlight(this.networkStatus) &&\n this.observableQuery) {\n const { fetchPolicy } = this.observableQuery.options;\n if (fetchPolicy !== \"cache-only\" &&\n fetchPolicy !== \"cache-and-network\") {\n return false;\n }\n }\n\n return true;\n }\n\n public stop() {\n if (!this.stopped) {\n this.stopped = true;\n\n this.cancel();\n // Revert back to the no-op version of cancel inherited from\n // QueryInfo.prototype.\n delete this.cancel;\n\n this.subscriptions.forEach(sub => sub.unsubscribe());\n\n const oq = this.observableQuery;\n if (oq) oq.stopPolling();\n }\n }\n\n // This method is a no-op by default, until/unless overridden by the\n // updateWatch method.\n private cancel() {}\n\n private lastWatch?: Cache.WatchOptions;\n\n private updateWatch(variables = this.variables) {\n const oq = this.observableQuery;\n if (oq && oq.options.fetchPolicy === \"no-cache\") {\n return;\n }\n if (!this.lastWatch ||\n this.lastWatch.query !== this.document ||\n !equal(variables, this.lastWatch.variables)) {\n this.cancel();\n this.cancel = this.cache.watch(this.lastWatch = {\n query: this.document!,\n variables,\n optimistic: true,\n callback: diff => this.setDiff(diff),\n });\n }\n }\n\n private lastWrite?: {\n result: FetchResult<any>;\n variables: WatchQueryOptions[\"variables\"];\n dmCount: number | undefined;\n };\n\n private shouldWrite(\n result: FetchResult<any>,\n variables: WatchQueryOptions[\"variables\"],\n ) {\n const { lastWrite } = this;\n return !(\n lastWrite &&\n // If cache.evict has been called since the last time we wrote this\n // data into the cache, there's a chance writing this result into\n // the cache will repair what was evicted.\n lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&\n equal(variables, lastWrite.variables) &&\n equal(result.data, lastWrite.result.data)\n );\n }\n\n public markResult<T>(\n result: FetchResult<T>,\n options: Pick<WatchQueryOptions,\n | \"variables\"\n | \"fetchPolicy\"\n | \"errorPolicy\">,\n allowCacheWrite: boolean,\n ) {\n this.graphQLErrors = isNonEmptyArray(result.errors) ? result.errors : [];\n\n // If there is a pending notify timeout, cancel it because we are\n // about to update this.diff to hold the latest data, and we can\n // assume the data will be broadcast through some other mechanism.\n cancelNotifyTimeout(this);\n\n if (options.fetchPolicy === 'no-cache') {\n this.diff = { result: result.data, complete: true };\n\n } else if (allowCacheWrite) {\n if (shouldWriteResult(result, options.errorPolicy)) {\n // Using a transaction here so we have a chance to read the result\n // back from the cache before the watch callback fires as a result\n // of writeQuery, so we can store the new diff quietly and ignore\n // it when we receive it redundantly from the watch callback.\n this.cache.performTransaction(cache => {\n if (this.shouldWrite(result, options.variables)) {\n cache.writeQuery({\n query: this.document!,\n data: result.data as T,\n variables: options.variables,\n });\n\n this.lastWrite = {\n result,\n variables: options.variables,\n dmCount: destructiveMethodCounts.get(this.cache),\n };\n } else {\n // If result is the same as the last result we received from\n // the network (and the variables match too), avoid writing\n // result into the cache again. The wisdom of skipping this\n // cache write is far from obvious, since any cache write\n // could be the one that puts the cache back into a desired\n // state, fixing corruption or missing data. However, if we\n // always write every network result into the cache, we enable\n // feuds between queries competing to update the same data in\n // incompatible ways, which can lead to an endless cycle of\n // cache broadcasts and useless network requests. As with any\n // feud, eventually one side must step back from the brink,\n // letting the other side(s) have the last word(s). There may\n // be other points where we could break this cycle, such as\n // silencing the broadcast for cache.writeQuery (not a good\n // idea, since it just delays the feud a bit) or somehow\n // avoiding the network request that just happened (also bad,\n // because the server could return useful new data). All\n // options considered, skipping this cache write seems to be\n // the least damaging place to break the cycle, because it\n // reflects the intuition that we recently wrote this exact\n // result into the cache, so the cache *should* already/still\n // contain this data. If some other query has clobbered that\n // data in the meantime, that's too bad, but there will be no\n // winners if every query blindly reverts to its own version\n // of the data. This approach also gives the network a chance\n // to return new data, which will be written into the cache as\n // usual, notifying only those queries that are directly\n // affected by the cache updates, as usual. In the future, an\n // even more sophisticated cache could perhaps prevent or\n // mitigate the clobbering somehow, but that would make this\n // particular cache write even less important, and thus\n // skipping it would be even safer than it is today.\n if (this.diff && this.diff.complete) {\n // Reuse data from the last good (complete) diff that we\n // received, when possible.\n result.data = this.diff.result;\n return;\n }\n // If the previous this.diff was incomplete, fall through to\n // re-reading the latest data with cache.diff, below.\n }\n\n const diff = cache.diff<T>({\n query: this.document!,\n variables: options.variables,\n returnPartialData: true,\n optimistic: true,\n });\n\n // In case the QueryManager stops this QueryInfo before its\n // results are delivered, it's important to avoid restarting the\n // cache watch when markResult is called.\n if (!this.stopped) {\n // Any time we're about to update this.diff, we need to make\n // sure we've started watching the cache.\n this.updateWatch(options.variables);\n }\n\n // If we're allowed to write to the cache, and we can read a\n // complete result from the cache, update result.data to be the\n // result from the cache, rather than the raw network result.\n // Set without setDiff to avoid triggering a notify call, since\n // we have other ways of notifying for this result.\n this.diff = diff;\n if (diff.complete) {\n result.data = diff.result;\n }\n });\n\n } else {\n this.lastWrite = void 0;\n }\n }\n }\n\n public markReady() {\n this.networkError = null;\n return this.networkStatus = NetworkStatus.ready;\n }\n\n public markError(error: ApolloError) {\n this.networkStatus = NetworkStatus.error;\n this.lastWrite = void 0;\n\n cancelNotifyTimeout(this);\n\n if (error.graphQLErrors) {\n this.graphQLErrors = error.graphQLErrors;\n }\n\n if (error.networkError) {\n this.networkError = error.networkError;\n }\n\n return error;\n }\n}\n\nexport function shouldWriteResult<T>(\n result: FetchResult<T>,\n errorPolicy: ErrorPolicy = \"none\",\n) {\n const ignoreErrors =\n errorPolicy === \"ignore\" ||\n errorPolicy === \"all\";\n let writeWithErrors = !graphQLResultHasError(result);\n if (!writeWithErrors && ignoreErrors && result.data) {\n writeWithErrors = true;\n }\n return writeWithErrors;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QueryInfo.js","sourceRoot":"","sources":["../../src/core/QueryInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAOtC,OAAO,EAEL,eAAe,EACf,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAUzB,IAAM,uBAAuB,GAAG,IAAI,CAClC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAC9B,EAA4B,CAAC;AAE9B,SAAS,0BAA0B,CACjC,KAAuB,EACvB,UAAkC;IAElC,IAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,KAAK,CAAC,UAAU,CAAC,GAAG;YAClB,uBAAuB,CAAC,GAAG,CACzB,KAAK,EAKL,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CACjD,CAAC;YACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACzC,CAAC,CAAC;KACH;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAe;IAC1C,IAAI,IAAI,CAAC,eAAe,CAAC,EAAE;QACzB,YAAY,CAAC,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AAG,KAAK,CAAC,CAAC;aACzB;SACF;IACH,CAAC;IAEM,6BAAS,GAAhB;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC;IAClD,CAAC;IAEM,6BAAS,GAAhB,UAAiB,KAAkB;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;QAExB,IAAI,CAAC,KAAK,EAAE,CAAC;QAEb,IAAI,KAAK,CAAC,aAAa,EAAE;YACvB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;SAC1C;QAED,IAAI,KAAK,CAAC,YAAY,EAAE;YACtB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;SACxC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IACH,gBAAC;AAAD,CAAC,AArWD,IAqWC;;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAAsB,EACtB,WAAiC;IAAjC,4BAAA,EAAA,oBAAiC;IAEjC,IAAM,YAAY,GAChB,WAAW,KAAK,QAAQ;QACxB,WAAW,KAAK,KAAK,CAAC;IACxB,IAAI,eAAe,GAAG,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,eAAe,IAAI,YAAY,IAAI,MAAM,CAAC,IAAI,EAAE;QACnD,eAAe,GAAG,IAAI,CAAC;KACxB;IACD,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { DocumentNode, GraphQLError } from 'graphql';\nimport { equal } from \"@wry/equality\";\n\nimport { Cache, ApolloCache } from '../cache';\nimport { WatchQueryOptions, ErrorPolicy } from './watchQueryOptions';\nimport { ObservableQuery } from './ObservableQuery';\nimport { QueryListener } from './types';\nimport { FetchResult } from '../link/core';\nimport {\n ObservableSubscription,\n isNonEmptyArray,\n graphQLResultHasError,\n canUseWeakMap,\n} from '../utilities';\nimport {\n NetworkStatus,\n isNetworkRequestInFlight,\n} from './networkStatus';\nimport { ApolloError } from '../errors';\n\nexport type QueryStoreValue = Pick<QueryInfo,\n | \"variables\"\n | \"networkStatus\"\n | \"networkError\"\n | \"graphQLErrors\"\n >;\n\nconst destructiveMethodCounts = new (\n canUseWeakMap ? WeakMap : Map\n)<ApolloCache<any>, number>();\n\nfunction wrapDestructiveCacheMethod(\n cache: ApolloCache<any>,\n methodName: keyof ApolloCache<any>,\n) {\n const original = cache[methodName];\n if (typeof original === \"function\") {\n cache[methodName] = function () {\n destructiveMethodCounts.set(\n cache,\n // The %1e15 allows the count to wrap around to 0 safely every\n // quadrillion evictions, so there's no risk of overflow. To be\n // clear, this is more of a pedantic principle than something\n // that matters in any conceivable practical scenario.\n (destructiveMethodCounts.get(cache)! + 1) % 1e15,\n );\n return original.apply(this, arguments);\n };\n }\n}\n\nfunction cancelNotifyTimeout(info: QueryInfo) {\n if (info[\"notifyTimeout\"]) {\n clearTimeout(info[\"notifyTimeout\"]);\n info[\"notifyTimeout\"] = void 0;\n }\n}\n\n// A QueryInfo object represents a single query managed by the\n// QueryManager, which tracks all QueryInfo objects by queryId in its\n// this.queries Map. QueryInfo objects store the latest results and errors\n// for the given query, and are responsible for reporting those results to\n// the corresponding ObservableQuery, via the QueryInfo.notify method.\n// Results are reported asynchronously whenever setDiff marks the\n// QueryInfo object as dirty, though a call to the QueryManager's\n// broadcastQueries method may trigger the notification before it happens\n// automatically. This class used to be a simple interface type without\n// any field privacy or meaningful methods, which is why it still has so\n// many public fields. The effort to lock down and simplify the QueryInfo\n// interface is ongoing, and further improvements are welcome.\nexport class QueryInfo {\n listeners = new Set<QueryListener>();\n document: DocumentNode | null = null;\n lastRequestId = 1;\n subscriptions = new Set<ObservableSubscription>();\n variables?: Record<string, any>;\n networkStatus?: NetworkStatus;\n networkError?: Error | null;\n graphQLErrors?: ReadonlyArray<GraphQLError>;\n stopped = false;\n\n constructor(private cache: ApolloCache<any>) {\n // Track how often cache.evict is called, since we want eviction to\n // override the feud-stopping logic in the markResult method, by\n // causing shouldWrite to return true. Wrapping the cache.evict method\n // is a bit of a hack, but it saves us from having to make eviction\n // counting an official part of the ApolloCache API.\n if (!destructiveMethodCounts.has(cache)) {\n destructiveMethodCounts.set(cache, 0);\n wrapDestructiveCacheMethod(cache, \"evict\");\n wrapDestructiveCacheMethod(cache, \"modify\");\n wrapDestructiveCacheMethod(cache, \"reset\");\n }\n }\n\n public init(query: {\n document: DocumentNode;\n variables: Record<string, any> | undefined,\n // The initial networkStatus for this fetch, most often\n // NetworkStatus.loading, but also possibly fetchMore, poll, refetch,\n // or setVariables.\n networkStatus?: NetworkStatus,\n observableQuery?: ObservableQuery<any>;\n lastRequestId?: number;\n }): this {\n let networkStatus = query.networkStatus || NetworkStatus.loading;\n if (this.variables &&\n this.networkStatus !== NetworkStatus.loading &&\n !equal(this.variables, query.variables)) {\n networkStatus = NetworkStatus.setVariables;\n }\n\n if (!equal(query.variables, this.variables)) {\n this.diff = null;\n }\n\n Object.assign(this, {\n document: query.document,\n variables: query.variables,\n networkError: null,\n graphQLErrors: this.graphQLErrors || [],\n networkStatus,\n });\n\n if (query.observableQuery) {\n this.setObservableQuery(query.observableQuery);\n }\n\n if (query.lastRequestId) {\n this.lastRequestId = query.lastRequestId;\n }\n\n return this;\n }\n\n private dirty: boolean = false;\n\n private notifyTimeout?: ReturnType<typeof setTimeout>;\n\n private diff: Cache.DiffResult<any> | null = null;\n\n reset() {\n cancelNotifyTimeout(this);\n this.diff = null;\n this.dirty = false;\n }\n\n getDiff(variables = this.variables): Cache.DiffResult<any> {\n if (this.diff && equal(variables, this.variables)) {\n return this.diff;\n }\n\n this.updateWatch(this.variables = variables);\n\n return this.diff = this.cache.diff({\n query: this.document!,\n variables,\n returnPartialData: true,\n optimistic: true,\n });\n }\n\n setDiff(diff: Cache.DiffResult<any> | null) {\n const oldDiff = this.diff;\n this.diff = diff;\n if (!this.dirty &&\n (diff && diff.result) !== (oldDiff && oldDiff.result)) {\n this.dirty = true;\n if (!this.notifyTimeout) {\n this.notifyTimeout = setTimeout(() => this.notify(), 0);\n }\n }\n }\n\n public readonly observableQuery: ObservableQuery<any> | null = null;\n private oqListener?: QueryListener;\n\n setObservableQuery(oq: ObservableQuery<any> | null) {\n if (oq === this.observableQuery) return;\n\n if (this.oqListener) {\n this.listeners.delete(this.oqListener);\n }\n\n (this as any).observableQuery = oq;\n\n if (oq) {\n oq[\"queryInfo\"] = this;\n this.listeners.add(this.oqListener = () => {\n // If this.diff came from an optimistic transaction, deliver the\n // current cache data to the ObservableQuery, but don't perform a\n // full reobservation, since oq.reobserve might make a network\n // request, and we don't want to trigger network requests for\n // optimistic updates.\n if (this.getDiff().fromOptimisticTransaction) {\n oq[\"observe\"]();\n } else {\n oq.reobserve();\n }\n });\n } else {\n delete this.oqListener;\n }\n }\n\n notify() {\n cancelNotifyTimeout(this);\n\n if (this.shouldNotify()) {\n this.listeners.forEach(listener => listener(this));\n }\n\n this.dirty = false;\n }\n\n private shouldNotify() {\n if (!this.dirty || !this.listeners.size) {\n return false;\n }\n\n if (isNetworkRequestInFlight(this.networkStatus) &&\n this.observableQuery) {\n const { fetchPolicy } = this.observableQuery.options;\n if (fetchPolicy !== \"cache-only\" &&\n fetchPolicy !== \"cache-and-network\") {\n return false;\n }\n }\n\n return true;\n }\n\n public stop() {\n if (!this.stopped) {\n this.stopped = true;\n\n this.cancel();\n // Revert back to the no-op version of cancel inherited from\n // QueryInfo.prototype.\n delete this.cancel;\n\n this.subscriptions.forEach(sub => sub.unsubscribe());\n\n const oq = this.observableQuery;\n if (oq) oq.stopPolling();\n }\n }\n\n // This method is a no-op by default, until/unless overridden by the\n // updateWatch method.\n private cancel() {}\n\n private lastWatch?: Cache.WatchOptions;\n\n private updateWatch(variables = this.variables) {\n const oq = this.observableQuery;\n if (oq && oq.options.fetchPolicy === \"no-cache\") {\n return;\n }\n if (!this.lastWatch ||\n this.lastWatch.query !== this.document ||\n !equal(variables, this.lastWatch.variables)) {\n this.cancel();\n this.cancel = this.cache.watch(this.lastWatch = {\n query: this.document!,\n variables,\n optimistic: true,\n callback: diff => this.setDiff(diff),\n });\n }\n }\n\n private lastWrite?: {\n result: FetchResult<any>;\n variables: WatchQueryOptions[\"variables\"];\n dmCount: number | undefined;\n };\n\n private shouldWrite(\n result: FetchResult<any>,\n variables: WatchQueryOptions[\"variables\"],\n ) {\n const { lastWrite } = this;\n return !(\n lastWrite &&\n // If cache.evict has been called since the last time we wrote this\n // data into the cache, there's a chance writing this result into\n // the cache will repair what was evicted.\n lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&\n equal(variables, lastWrite.variables) &&\n equal(result.data, lastWrite.result.data)\n );\n }\n\n public markResult<T>(\n result: FetchResult<T>,\n options: Pick<WatchQueryOptions,\n | \"variables\"\n | \"fetchPolicy\"\n | \"errorPolicy\">,\n allowCacheWrite: boolean,\n ) {\n this.graphQLErrors = isNonEmptyArray(result.errors) ? result.errors : [];\n\n // Cancel the pending notify timeout (if it exists) to prevent extraneous network\n // requests. To allow future notify timeouts, diff and dirty are reset as well.\n this.reset();\n\n if (options.fetchPolicy === 'no-cache') {\n this.diff = { result: result.data, complete: true };\n\n } else if (!this.stopped && allowCacheWrite) {\n if (shouldWriteResult(result, options.errorPolicy)) {\n // Using a transaction here so we have a chance to read the result\n // back from the cache before the watch callback fires as a result\n // of writeQuery, so we can store the new diff quietly and ignore\n // it when we receive it redundantly from the watch callback.\n this.cache.performTransaction(cache => {\n if (this.shouldWrite(result, options.variables)) {\n cache.writeQuery({\n query: this.document!,\n data: result.data as T,\n variables: options.variables,\n });\n\n this.lastWrite = {\n result,\n variables: options.variables,\n dmCount: destructiveMethodCounts.get(this.cache),\n };\n } else {\n // If result is the same as the last result we received from\n // the network (and the variables match too), avoid writing\n // result into the cache again. The wisdom of skipping this\n // cache write is far from obvious, since any cache write\n // could be the one that puts the cache back into a desired\n // state, fixing corruption or missing data. However, if we\n // always write every network result into the cache, we enable\n // feuds between queries competing to update the same data in\n // incompatible ways, which can lead to an endless cycle of\n // cache broadcasts and useless network requests. As with any\n // feud, eventually one side must step back from the brink,\n // letting the other side(s) have the last word(s). There may\n // be other points where we could break this cycle, such as\n // silencing the broadcast for cache.writeQuery (not a good\n // idea, since it just delays the feud a bit) or somehow\n // avoiding the network request that just happened (also bad,\n // because the server could return useful new data). All\n // options considered, skipping this cache write seems to be\n // the least damaging place to break the cycle, because it\n // reflects the intuition that we recently wrote this exact\n // result into the cache, so the cache *should* already/still\n // contain this data. If some other query has clobbered that\n // data in the meantime, that's too bad, but there will be no\n // winners if every query blindly reverts to its own version\n // of the data. This approach also gives the network a chance\n // to return new data, which will be written into the cache as\n // usual, notifying only those queries that are directly\n // affected by the cache updates, as usual. In the future, an\n // even more sophisticated cache could perhaps prevent or\n // mitigate the clobbering somehow, but that would make this\n // particular cache write even less important, and thus\n // skipping it would be even safer than it is today.\n if (this.diff && this.diff.complete) {\n // Reuse data from the last good (complete) diff that we\n // received, when possible.\n result.data = this.diff.result;\n return;\n }\n // If the previous this.diff was incomplete, fall through to\n // re-reading the latest data with cache.diff, below.\n }\n\n const diff = cache.diff<T>({\n query: this.document!,\n variables: options.variables,\n returnPartialData: true,\n optimistic: true,\n });\n\n // In case the QueryManager stops this QueryInfo before its\n // results are delivered, it's important to avoid restarting the\n // cache watch when markResult is called.\n if (!this.stopped) {\n // Any time we're about to update this.diff, we need to make\n // sure we've started watching the cache.\n this.updateWatch(options.variables);\n }\n\n // If we're allowed to write to the cache, and we can read a\n // complete result from the cache, update result.data to be the\n // result from the cache, rather than the raw network result.\n // Set without setDiff to avoid triggering a notify call, since\n // we have other ways of notifying for this result.\n this.diff = diff;\n if (diff.complete) {\n result.data = diff.result;\n }\n });\n\n } else {\n this.lastWrite = void 0;\n }\n }\n }\n\n public markReady() {\n this.networkError = null;\n return this.networkStatus = NetworkStatus.ready;\n }\n\n public markError(error: ApolloError) {\n this.networkStatus = NetworkStatus.error;\n this.lastWrite = void 0;\n\n this.reset();\n\n if (error.graphQLErrors) {\n this.graphQLErrors = error.graphQLErrors;\n }\n\n if (error.networkError) {\n this.networkError = error.networkError;\n }\n\n return error;\n }\n}\n\nexport function shouldWriteResult<T>(\n result: FetchResult<T>,\n errorPolicy: ErrorPolicy = \"none\",\n) {\n const ignoreErrors =\n errorPolicy === \"ignore\" ||\n errorPolicy === \"all\";\n let writeWithErrors = !graphQLResultHasError(result);\n if (!writeWithErrors && ignoreErrors && result.data) {\n writeWithErrors = true;\n }\n return writeWithErrors;\n}\n"]}
|
package/core/core.cjs.js
CHANGED
|
@@ -16,7 +16,7 @@ var cache = require('../cache');
|
|
|
16
16
|
var utils = require('../link/utils');
|
|
17
17
|
var gql = _interopDefault(require('graphql-tag'));
|
|
18
18
|
|
|
19
|
-
var version = '3.3.
|
|
19
|
+
var version = '3.3.11';
|
|
20
20
|
|
|
21
21
|
(function (NetworkStatus) {
|
|
22
22
|
NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
|
@@ -438,7 +438,6 @@ var ObservableQuery = (function (_super) {
|
|
|
438
438
|
this.reobserver.stop();
|
|
439
439
|
delete this.reobserver;
|
|
440
440
|
}
|
|
441
|
-
delete this.options.context;
|
|
442
441
|
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
443
442
|
this.subscriptions.clear();
|
|
444
443
|
this.queryManager.stopQuery(this.queryId);
|
|
@@ -447,6 +446,7 @@ var ObservableQuery = (function (_super) {
|
|
|
447
446
|
};
|
|
448
447
|
return ObservableQuery;
|
|
449
448
|
}(utilities.Observable));
|
|
449
|
+
utilities.fixObservableSubclass(ObservableQuery);
|
|
450
450
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
451
451
|
process.env.NODE_ENV === "production" || tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
|
|
452
452
|
}
|
|
@@ -773,6 +773,11 @@ var QueryInfo = (function () {
|
|
|
773
773
|
}
|
|
774
774
|
return this;
|
|
775
775
|
};
|
|
776
|
+
QueryInfo.prototype.reset = function () {
|
|
777
|
+
cancelNotifyTimeout(this);
|
|
778
|
+
this.diff = null;
|
|
779
|
+
this.dirty = false;
|
|
780
|
+
};
|
|
776
781
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
777
782
|
if (variables === void 0) { variables = this.variables; }
|
|
778
783
|
if (this.diff && equality.equal(variables, this.variables)) {
|
|
@@ -884,11 +889,11 @@ var QueryInfo = (function () {
|
|
|
884
889
|
QueryInfo.prototype.markResult = function (result, options, allowCacheWrite) {
|
|
885
890
|
var _this = this;
|
|
886
891
|
this.graphQLErrors = utilities.isNonEmptyArray(result.errors) ? result.errors : [];
|
|
887
|
-
|
|
892
|
+
this.reset();
|
|
888
893
|
if (options.fetchPolicy === 'no-cache') {
|
|
889
894
|
this.diff = { result: result.data, complete: true };
|
|
890
895
|
}
|
|
891
|
-
else if (allowCacheWrite) {
|
|
896
|
+
else if (!this.stopped && allowCacheWrite) {
|
|
892
897
|
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
893
898
|
this.cache.performTransaction(function (cache) {
|
|
894
899
|
if (_this.shouldWrite(result, options.variables)) {
|
|
@@ -936,7 +941,7 @@ var QueryInfo = (function () {
|
|
|
936
941
|
QueryInfo.prototype.markError = function (error) {
|
|
937
942
|
this.networkStatus = exports.NetworkStatus.error;
|
|
938
943
|
this.lastWrite = void 0;
|
|
939
|
-
|
|
944
|
+
this.reset();
|
|
940
945
|
if (error.graphQLErrors) {
|
|
941
946
|
this.graphQLErrors = error.graphQLErrors;
|
|
942
947
|
}
|