graphql-persisted 0.0.7 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of graphql-persisted might be problematic. Click here for more details.

@@ -1,427 +0,0 @@
1
- import isEqual from 'lodash.isequal';
2
- import { graphqlNormalize } from 'graphql-normalize';
3
- import { produce } from 'immer';
4
- import { MissingMetaError, assertOperationHash } from './errors';
5
- import { variableObject, variableString } from './helpers';
6
- /**
7
- * Manages the cached normalized state, and the execution of
8
- * data accessed by different components
9
- */
10
- export class GraphQLQueryCache {
11
- constructor(config) {
12
- // All queries we are "subscribed to", meaning that we React to any changes
13
- // when there are updates to the cache.
14
- this._subscribedQueries = {};
15
- // All "in-flight" fetches, to deduplicate fetches that are already in-flight
16
- // for an operation
17
- this._inFlight = {};
18
- // Keeps track of all the operations that have been issued in the application,
19
- // as well as the metadata indicating the TTL / polling / invalidation / refetch
20
- // logic necessary to keep things up to date
21
- this._runtimeCache = {};
22
- /**
23
- * A list of all "effects" that have run, used to keep track of
24
- */
25
- this._effectsIssued = []; // TODO: Include subscriptions
26
- this._fetcher = config.fetcher;
27
- this._endpoint = config.endpoint || `/graphql`;
28
- this._persistedOperations = config.persistedOperations;
29
- this._persistedDocuments = config.persistedDocuments;
30
- this._configMeta = unwrapMeta(config.meta);
31
- this._queryInvalidation = config.queryInvalidation ?? {};
32
- this._mutationInvalidation = config.mutationInvalidation ?? {};
33
- this._cacheStore = produce(config.hydratedCache ?? {
34
- meta: {},
35
- fields: {},
36
- operations: {},
37
- }, noop);
38
- }
39
- /**
40
- * Invalidates a query by name or predicate fn
41
- */
42
- invalidateQuery(toInvalidate) {
43
- produce(this._runtimeCache, () => {
44
- //
45
- });
46
- }
47
- /**
48
- * Invalidates a query by name or predicate fn
49
- */
50
- refetchQuery(toRefetch) {
51
- produce(this._runtimeCache, () => {
52
- //
53
- });
54
- }
55
- /**
56
- * JSON.stringify(queryCache) produces the data we need
57
- * to rehydrate the Client
58
- */
59
- toJSON() {
60
- const { fields, operations, meta } = this._cacheStore;
61
- return {
62
- fields,
63
- operations: operations,
64
- meta: meta,
65
- };
66
- }
67
- // /**
68
- // * Whether we've fetched the query in the cache yet
69
- // */
70
- // hasQuery<Q extends keyof GraphQLQuery.QueryRegistry>(
71
- // queryName: Q,
72
- // variable: SerializedVariables | GraphQLQuery.OperationVariables[Q]
73
- // ) {
74
- // // Object.values(this._cacheStore.operations).find((o) => {
75
- // // return o.operationType === 'query' && o
76
- // // })
77
- // }
78
- /**
79
- * Attempts to read a query from the cache, returning undefined
80
- * if we are unable to for any reason. Used in initial hook execution
81
- * where we don't want any side-effects, incase we're doing SSR
82
- */
83
- tryReadQuery(args) {
84
- try {
85
- return this.readQuery(args);
86
- }
87
- catch {
88
- return undefined;
89
- }
90
- }
91
- /**
92
- * Reads the query from the cache. Throws an error if we are unable
93
- * to read the data, due to an incomplete result or lack of operation
94
- * metadata
95
- */
96
- readQuery(args) {
97
- const { queryName, variables, options } = args;
98
- const key = this._getKey(queryName, variables);
99
- const op = this._cacheStore.operations[key];
100
- if (op) {
101
- return op;
102
- }
103
- // If we don't have metadata, we can't know how to read the query
104
- // from the cache
105
- const meta = this._getMeta(queryName);
106
- const { result } = graphqlNormalize({
107
- action: 'read',
108
- variableValues: typeof variables === 'string' ? JSON.parse(variables) : variables,
109
- meta: meta,
110
- cache: this._cacheStore.fields,
111
- isEqual,
112
- });
113
- return {
114
- data: result,
115
- };
116
- }
117
- /**
118
- * Reads the query from the cache if any of the following conditions are met:
119
- * a) We already have the result of this query in the operation cache
120
- * b) We have the necessary metadata, as well as all of the necessary fields info to complete
121
- * this query from the field cache
122
- */
123
- readOrFetchQuery(args) {
124
- // If we don't have the metadata for the Query yet, we won't know how
125
- // to read it from the cache. In this case we first need to fetch the query
126
- // and check for the meta in the extensions to know how to normalize it
127
- try {
128
- const readResult = this.readQuery(args);
129
- if (readResult) {
130
- this.fetchQuery(args);
131
- }
132
- return readResult;
133
- }
134
- catch {
135
- return this.fetchQuery(args);
136
- }
137
- }
138
- /**
139
- * Loads the query if it's not already in the cache,
140
- * useful when hydrating the cache outside of a component
141
- */
142
- preloadQuery(queryName, options) {
143
- const { blockIfStale = true } = options;
144
- const variables = variableString(options.variables ?? {});
145
- const sha256Hash = this._persistedOperations[queryName];
146
- const key = `${sha256Hash}:${variables}`;
147
- const operation = this._cacheStore.operations[key];
148
- // TODO: Give an option to eager return if we already have the operation but it's stale
149
- if (!operation || operation.stale) {
150
- const inFlight = this.fetchQuery({ queryName, variables: variables, options: {} });
151
- return operation && blockIfStale === false ? operation : inFlight;
152
- }
153
- return operation;
154
- }
155
- fetchQuery(args) {
156
- return this._executeOperation('query', args.queryName, args.variables, args.options);
157
- }
158
- /**
159
- * Executes a mutation, returning the result of that mutation
160
- */
161
- async executeMutation(mutationName, variables, options = {}) {
162
- return this._executeOperation('mutation', mutationName, variables, options);
163
- }
164
- /**
165
- * Executes a query, returning the result of that query
166
- */
167
- async executeQuery(queryName, variables) {
168
- return this._executeOperation('query', queryName, variables);
169
- }
170
- async executeSubscription() {
171
- throw new Error('Not yet supported');
172
- }
173
- _getKey(operationName, variables) {
174
- const sha256Hash = this._persistedOperations[operationName];
175
- return `${sha256Hash}:${variableString(variables)}`;
176
- }
177
- /**
178
- * "Subscribes" to a query, meaning that when there are updates to fields in the
179
- * field cache, we'll re-materialize the known value of the query. We'll also
180
- * process based on configuration options, such as TTL, invalidateOnMutation
181
- */
182
- subscribeToQuery(args) {
183
- var _a;
184
- const { queryName, queryResult, variables, onUpdate, options } = args;
185
- const key = this._getKey(queryName, variables);
186
- const queries = ((_a = this._subscribedQueries)[key] ?? (_a[key] = []));
187
- queries.push(args);
188
- // Now that the component is subscribed, we can begin fetching,
189
- // refetching, and otherwise managing the query
190
- if (!queryResult) {
191
- this.readOrFetchQuery(args);
192
- }
193
- else if (options.ttl) {
194
- //
195
- }
196
- return () => {
197
- queries.splice(queries.indexOf(args), 1);
198
- };
199
- }
200
- async _executeOperation(operationType, operationName, variables) {
201
- const sha256Hash = this._persistedOperations[operationName];
202
- const key = this._getKey(operationName, variables);
203
- const operationVariables = variableObject(variables);
204
- assertOperationHash(sha256Hash, operationType, operationName);
205
- const inFlight = this._inFlight[key];
206
- if (operationType === 'query' && inFlight) {
207
- return inFlight;
208
- }
209
- const operationInFlight = this._fetch({
210
- query: '',
211
- operationName,
212
- variables: operationVariables,
213
- extensions: {
214
- persistedQuery: { version: 1, sha256Hash },
215
- },
216
- });
217
- this._inFlight[key] = operationInFlight;
218
- const operationResult = await operationInFlight.finally(() => {
219
- delete this._inFlight[key];
220
- });
221
- if (operationResult.fetchError) {
222
- return operationResult;
223
- }
224
- const meta = operationResult.extensions?.['graphqlNormalizeMeta'] ??
225
- this._getMeta(operationName);
226
- // Ensure we have metadata to be able to normalize the operation in our cache
227
- if (!meta) {
228
- throw new MissingMetaError(operationName);
229
- }
230
- const lastCache = this._cacheStore;
231
- this._cacheStore = produce(this._cacheStore, (c) => {
232
- const currentResult = c.operations[key];
233
- const { added, modified, result } = graphqlNormalize({
234
- action: 'write',
235
- operationResult,
236
- meta,
237
- cache: c.fields,
238
- variableValues: operationVariables,
239
- currentResult,
240
- isEqual,
241
- });
242
- //
243
- if (operationType === 'query' && (added || modified)) {
244
- c.operations[key] = {
245
- stale: false,
246
- meta,
247
- operationName,
248
- variableValues: operationVariables,
249
- data: result,
250
- errors: operationResult.errors,
251
- extensions: operationResult.extensions,
252
- operationType: operationType,
253
- };
254
- }
255
- // If we've modified anything in the cache, we also need to update any
256
- // mounted queries
257
- if (modified) {
258
- for (const [k, val] of Object.entries(c.operations)) {
259
- if (k === key || val.operationType !== 'query') {
260
- continue;
261
- }
262
- //
263
- if (val.data) {
264
- const { result } = graphqlNormalize({
265
- action: 'read',
266
- currentResult: val.data,
267
- cache: c.fields,
268
- meta: val.meta,
269
- variableValues: val.variableValues,
270
- });
271
- if (result !== val) {
272
- val.data = result;
273
- }
274
- }
275
- }
276
- }
277
- });
278
- // If this was a mutation, we need to go through and determine if we need to mark
279
- // any Queries as "stale", or eagerly refetch any of the queries
280
- if (operationType === 'mutation') {
281
- const toInvalidate = new Set();
282
- const mutationName = operationName;
283
- const mutationFn = this._mutationInvalidation?.[mutationName];
284
- for (const [operationKey, operation] of Object.entries(this._cacheStore.operations)) {
285
- if (operation.operationType !== 'query') {
286
- continue;
287
- }
288
- const queryName = operation.operationName;
289
- const queryVariables = operation.variableValues;
290
- const queryFn = this._queryInvalidation[queryName];
291
- if (queryFn?.(mutationName, operationVariables, queryVariables)) {
292
- toInvalidate.add(operationKey);
293
- }
294
- if (mutationFn?.(queryName, queryVariables, operationVariables)) {
295
- toInvalidate.add(operationKey);
296
- }
297
- }
298
- if (toInvalidate.size) {
299
- this._cacheStore = produce(this._cacheStore, (o) => {
300
- for (const key of toInvalidate) {
301
- const op = o.operations[key];
302
- if (op)
303
- op.stale = true;
304
- }
305
- });
306
- }
307
- }
308
- // If we've updated any operations, we need to update any subscribed components
309
- if (lastCache.operations !== this._cacheStore.operations) {
310
- for (const [key, val] of Object.entries(this._cacheStore.operations)) {
311
- if (this._cacheStore.operations[key] !== lastCache.operations[key]) {
312
- if (this._subscribedQueries[key]) {
313
- this._subscribedQueries[key]?.forEach((o) => o.onUpdate(val));
314
- }
315
- }
316
- }
317
- }
318
- if (operationType === 'query') {
319
- return this._cacheStore.operations[key];
320
- }
321
- return operationResult;
322
- }
323
- _getMeta(opName) {
324
- const meta = this._cacheStore.meta[opName] ?? this._configMeta?.[opName];
325
- if (!meta) {
326
- throw new MissingMetaError(opName);
327
- }
328
- return meta;
329
- }
330
- /**
331
- * Handles "fetch", ensuring we catch network errors and handle non-200
332
- * responses properly so we're able to forward these on in a normalized fashion
333
- */
334
- async _fetch(body) {
335
- let result;
336
- try {
337
- result = await this._makeFetch(body);
338
- if (result.status === 200) {
339
- const json = (await result.json());
340
- return json;
341
- }
342
- else {
343
- return {
344
- fetchError: {
345
- name: 'ResponseError',
346
- message: await result.text(),
347
- status: result.status,
348
- statusText: result.statusText,
349
- },
350
- };
351
- }
352
- }
353
- catch (e) {
354
- const error = e instanceof Error ? e : new Error(String(e));
355
- return {
356
- fetchError: {
357
- name: error.name,
358
- message: error.message,
359
- stack: error.stack,
360
- status: result?.status,
361
- statusText: result?.statusText,
362
- },
363
- };
364
- }
365
- }
366
- _makeFetch(body) {
367
- const reqInit = {
368
- method: 'POST',
369
- body: JSON.stringify(body),
370
- headers: {
371
- 'content-type': 'application/json',
372
- },
373
- };
374
- if (this._fetcher) {
375
- return this._fetcher(this._endpoint, reqInit);
376
- }
377
- return fetch(this._endpoint, reqInit);
378
- }
379
- /**
380
- * Determine whether we should refetch the query based on the
381
- * current value of the query, and the options passed to the query
382
- */
383
- _shouldRefetchQuery() {
384
- //
385
- }
386
- /**
387
- * "Garbage collection" for existing operations. If they have
388
- * a TTL or are invalidated by other operations, and aren't mounted,
389
- * then we can go ahead and sweep out any data we might have for them
390
- */
391
- _gcOperations() {
392
- //
393
- }
394
- }
395
- function unwrapMeta(meta) {
396
- if (!meta)
397
- return meta;
398
- const o = {};
399
- for (const [key, val] of Object.entries(meta)) {
400
- if (typeof val === 'string') {
401
- o[key] = isBase64(val) ? JSON.parse(fromBase64(val)) : JSON.parse(val);
402
- }
403
- else {
404
- o[key] = val;
405
- }
406
- }
407
- return o;
408
- }
409
- function isBase64(str) {
410
- if (typeof Buffer !== 'undefined') {
411
- return Buffer.from(str, 'base64').toString('base64') === str;
412
- }
413
- try {
414
- window.btoa(str);
415
- return true;
416
- }
417
- catch {
418
- return false;
419
- }
420
- }
421
- function fromBase64(str) {
422
- if (typeof Buffer !== 'undefined') {
423
- return Buffer.from(str, 'base64').toString('utf8');
424
- }
425
- return window.atob(str);
426
- }
427
- function noop() { }
package/mjs/context.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import type { GraphQLQueryCache } from './GraphQLQueryCache.js';
3
- /**
4
- * Provides an initialized `GraphQLQueryCache` for use by hooks throughout
5
- * the rest of the application.
6
- *
7
- * @example
8
- * <GraphQLQueryProvider cache={cache}>
9
- * <App />
10
- * </GraphQLQueryProvider>
11
- */
12
- export declare const GraphQLQueryProvider: React.FC<{
13
- cache: GraphQLQueryCache;
14
- children: React.ReactNode | React.ReactNode[];
15
- }>;
16
- /**
17
- * Hook returning the initialized GraphQL Query Cache
18
- *
19
- * Throws if accessed outside of a `GraphQLQueryProvider`
20
- */
21
- export declare const useGraphQLQueryCache: () => GraphQLQueryCache;
package/mjs/context.js DELETED
@@ -1,27 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext } from 'react';
3
- const GraphQLQueryContext = createContext(null);
4
- /**
5
- * Provides an initialized `GraphQLQueryCache` for use by hooks throughout
6
- * the rest of the application.
7
- *
8
- * @example
9
- * <GraphQLQueryProvider cache={cache}>
10
- * <App />
11
- * </GraphQLQueryProvider>
12
- */
13
- export const GraphQLQueryProvider = ({ cache, children }) => {
14
- return _jsx(GraphQLQueryContext.Provider, { value: cache, children: children });
15
- };
16
- /**
17
- * Hook returning the initialized GraphQL Query Cache
18
- *
19
- * Throws if accessed outside of a `GraphQLQueryProvider`
20
- */
21
- export const useGraphQLQueryCache = () => {
22
- const ctx = useContext(GraphQLQueryContext);
23
- if (!ctx) {
24
- throw new Error(`useGraphQLQueryCache must be nested inside a GraphQLQueryProvider`);
25
- }
26
- return ctx;
27
- };
package/mjs/errors.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export declare class GraphQLQueryError extends Error {
2
- }
3
- /**
4
- * Thrown in situations where we are expecting graphql-normalize metadata
5
- * to be available, but it isn't yet available.
6
- */
7
- export declare class MissingMetaError extends Error {
8
- constructor(queryName: string);
9
- }
10
- export declare class UnknownOperationError extends Error {
11
- constructor(operationName: string, operationType: string);
12
- }
13
- export declare class MissingNormalizeMetaError extends Error {
14
- constructor(operationName: string, operationType: string);
15
- }
16
- export declare class ExpectedPreloadedQueryError extends GraphQLQueryError {
17
- constructor(queryName: string);
18
- }
19
- export declare function assertOperationHash(hash: string | undefined, operationType: 'query' | 'mutation' | 'subscription', operationName: string): void;
package/mjs/errors.js DELETED
@@ -1,31 +0,0 @@
1
- export class GraphQLQueryError extends Error {
2
- }
3
- /**
4
- * Thrown in situations where we are expecting graphql-normalize metadata
5
- * to be available, but it isn't yet available.
6
- */
7
- export class MissingMetaError extends Error {
8
- constructor(queryName) {
9
- super(`Cannot readQuery('${queryName}') without graphql-normalize metadata.`);
10
- }
11
- }
12
- export class UnknownOperationError extends Error {
13
- constructor(operationName, operationType) {
14
- super(`Unknown ${operationType} operation ${operationName}, not found in the hash of operations`);
15
- }
16
- }
17
- export class MissingNormalizeMetaError extends Error {
18
- constructor(operationName, operationType) {
19
- super(`extensions.graphqlNormalizeMeta is was expected for the ${operationName} ${operationType}.\n You must configure your GraphQLQueryCache with the "meta" property, or add this as part of your repsonse payload`);
20
- }
21
- }
22
- export class ExpectedPreloadedQueryError extends GraphQLQueryError {
23
- constructor(queryName) {
24
- super(`Expected query ${queryName} to be preloaded with preloadQuery`);
25
- }
26
- }
27
- export function assertOperationHash(hash, operationType, operationName) {
28
- if (!hash) {
29
- throw new UnknownOperationError(operationName, operationType);
30
- }
31
- }
@@ -1,31 +0,0 @@
1
- import './types';
2
- type Pretty<O> = {
3
- [K in keyof O]: O[K];
4
- } & {};
5
- type UnwrapFragment<T> = T extends Array<infer U> ? Array<UnwrapFragment<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<ReadonlyArray<U>> : T extends object ? T extends {
6
- ' $fragmentRefs'?: infer Refs;
7
- } ? Pretty<{
8
- [K in keyof T as K extends ' $fragmentName' | ' $fragmentRefs' ? never : K]: UnwrapFragment<T[K]>;
9
- } & {
10
- [K in keyof Refs]: UnwrapFragment<Refs[K]>;
11
- }[keyof Refs]> : {
12
- [K in keyof T as K extends ' $fragmentName' ? never : K]: UnwrapFragment<T[K]>;
13
- } : T;
14
- export type FragmentType<Frag extends keyof GraphQLQuery.FragmentRegistry> = GraphQLQuery.FragmentRegistry[Frag] extends infer FragType ? FragType extends {
15
- ' $fragmentName'?: infer TKey;
16
- } ? TKey extends string ? {
17
- ' $fragmentRefs'?: {
18
- [key in TKey]: FragType;
19
- };
20
- } : never : never : never;
21
- export type FragmentTypeUnwrapped<Frag extends keyof GraphQLQuery.FragmentRegistry> = GraphQLQuery.FragmentRegistry[Frag] extends infer FragType ? FragType extends object ? UnwrapFragment<FragType> : never : never;
22
- export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag>): GraphQLQuery.FragmentRegistry[Frag];
23
- export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag> | null | undefined): GraphQLQuery.FragmentRegistry[Frag] | null | undefined;
24
- export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>>): ReadonlyArray<GraphQLQuery.FragmentRegistry[Frag]>;
25
- export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>> | null | undefined): ReadonlyArray<GraphQLQuery.FragmentRegistry[Frag]> | null | undefined;
26
- export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag>): FragmentTypeUnwrapped<Frag>;
27
- export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag> | null | undefined): FragmentTypeUnwrapped<Frag> | null | undefined;
28
- export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>>): ReadonlyArray<FragmentTypeUnwrapped<Frag>>;
29
- export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>> | null | undefined): ReadonlyArray<FragmentTypeUnwrapped<Frag>> | null | undefined;
30
- export declare function castFragmentData<F extends keyof GraphQLQuery.FragmentRegistry, FT extends FragmentTypeUnwrapped<F>>(_fragmentName: F, data: FT): FragmentType<F>;
31
- export {};
@@ -1,10 +0,0 @@
1
- import './types';
2
- export function unwrapFragment(_fragmentName, fragmentType) {
3
- return fragmentType;
4
- }
5
- export function unwrapFragmentDeep(_fragmentName, fragmentType) {
6
- return fragmentType;
7
- }
8
- export function castFragmentData(_fragmentName, data) {
9
- return data;
10
- }
@@ -1,48 +0,0 @@
1
- import type { GraphQLPreloadedQueryResult, GraphQLQueryLazyResult, GraphQLQueryResult, ExecutionOptions, PersistedQueryOptions, QueryVariables, GraphQLMutationResult, ExecuteMutationOptions } from './types';
2
- /**
3
- * Loads a preloaded query. Like useQuery, except it throws if the
4
- * query does not already exist in the cache.
5
- *
6
- * This hook keeps track of the value of the last render, so we're always guaranteed
7
- * to have data here, even if it's potentially stale.
8
- */
9
- export declare function usePreloadedPersistedQuery<QueryName extends keyof GraphQLQuery.QueryRegistry>(query: QueryName, options: PersistedQueryOptions & QueryVariables<QueryName>): GraphQLPreloadedQueryResult<QueryName>;
10
- /**
11
- * Retrieves the persisted query from the cache,
12
- * creating it from the cache if we don't have a mounted version
13
- *
14
- * Fetches the query if:
15
- *
16
- * 1. We don't already have the operation fetched in the cache
17
- * 2. The query is considered stale based on:
18
- * a) The TTL setting
19
- * b) A mutation which invalidates the query
20
- */
21
- export declare function usePersistedQuery<QueryName extends keyof GraphQLQuery.QueryRegistry>(queryName: QueryName, options: PersistedQueryOptions & QueryVariables<QueryName>): GraphQLQueryResult<QueryName>;
22
- /**
23
- * TODO: Not working yet
24
- * Creates a container for a query that isn't fetched immediately,
25
- * but provides a loadQuery function to call
26
- */
27
- export declare function useLazyPersistedQuery<QueryName extends keyof GraphQLQuery.QueryRegistry>(query: QueryName): GraphQLQueryLazyResult<QueryName>;
28
- /**
29
- * Executes a persisted mutation, keeping track of mutations in-flight to ensure
30
- * we don't execute the same mutation multiple times with the same values
31
- * in the same component
32
- */
33
- export declare function usePersistedMutation<MutationName extends keyof GraphQLQuery.MutationRegistry>(mutationName: MutationName, options?: ExecutionOptions): {
34
- execute: (vars: GraphQLQuery.OperationVariables[MutationName], opts?: ExecuteMutationOptions) => Promise<GraphQLMutationResult<MutationName>>;
35
- isExecuting: boolean;
36
- };
37
- /**
38
- * TODO: Subscription management
39
- */
40
- export declare function usePersistedSubscription<SubscriptionName extends keyof GraphQLQuery.SubscriptionRegistry>(subscriptionName: SubscriptionName): void;
41
- type UseOnMutationFn<M> = () => void;
42
- /**
43
- * Hook called when a mutation is issued, anywhere in the application.
44
- * Useful for one-off situations where we want to subscribe and refetch something
45
- * based on a mutation event
46
- */
47
- export declare function useOnMutation<M extends keyof GraphQLQuery.MutationRegistry | '*'>(mutation: M | Array<M>, fn: UseOnMutationFn<M>): void;
48
- export {};