graphql-persisted 0.0.5 → 0.0.6

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.
@@ -66,6 +66,7 @@ function usePersistedQuery(queryName, options) {
66
66
  // or it is refetched
67
67
  (0, react_1.useEffect)(() => {
68
68
  return cache.subscribeToQuery({
69
+ queryResult,
69
70
  queryName,
70
71
  variables: variableString,
71
72
  onUpdate: setQueryResult,
@@ -91,8 +92,15 @@ function useLazyPersistedQuery(query) {
91
92
  const [fetched, setIsFetched] = (0, react_1.useState)(false);
92
93
  const [loading, setIsLoading] = (0, react_1.useState)(false);
93
94
  const loadQuery = (0, react_1.useCallback)((variables) => {
94
- return new Promise((resolve) => {
95
- cache.readOrFetchQuery({ queryName: query, variables: (0, helpers_1.serializeVariables)(variables), options: {} });
95
+ return new Promise((resolve, reject) => {
96
+ const result = cache.readOrFetchQuery({
97
+ queryName: query,
98
+ variables: (0, helpers_1.serializeVariables)(variables),
99
+ options: {},
100
+ });
101
+ // if ('then' in result && typeof result.then === 'function') {
102
+ // Promise.resolve(result).then(resolve, reject)
103
+ // }
96
104
  });
97
105
  }, [cache, query]);
98
106
  const errors = undefined;
package/cjs/types.d.ts CHANGED
@@ -167,7 +167,7 @@ export interface SubscribeToQueryArgs<Q extends keyof GraphQLQuery.QueryRegistry
167
167
  /**
168
168
  * The result of readQuery, used to check whether the query is stale
169
169
  */
170
- queryResult?: GraphQLQuery.QueryRegistry[Q];
170
+ queryResult?: GraphQLOperationResult<Q>;
171
171
  /**
172
172
  * Invoked when the values for this query are updated
173
173
  */
@@ -1,10 +1,33 @@
1
- import type { GraphQLCacheShape, GraphQLMutationResult, GraphQLOperationResult, GraphQLQueryCacheConfig, GraphQLQueryResult, InvalidateQueryArgs, MaybePromise, ExecutionOptions, ReadQueryArgs, SerializedVariables, SubscribeToQueryArgs, PreloadQueryOptions } from './types';
1
+ import { NormalizeMetaShape } from 'graphql-normalize';
2
+ import type { GraphQLCacheShape, GraphQLMutationResult, GraphQLOperationResult, GraphQLQueryCacheConfig, GraphQLQueryResult, GraphQLRequestBody, InvalidateQueryArgs, MaybePromise, ExecutionOptions, PersistedQueryOptions, ReadQueryArgs, SerializedVariables, SubscribeToQueryArgs, PreloadQueryOptions } from './types';
2
3
  /**
3
4
  * Manages the cached normalized state, and the execution of
4
5
  * data accessed by different components
5
6
  */
6
7
  export declare class GraphQLQueryCache {
7
- #private;
8
+ /**
9
+ * If an alterative fetch is provided, we will use that for operations
10
+ * Otherwise we'll use the native 'fetch'
11
+ */
12
+ private _fetcher?;
13
+ /**
14
+ * GraphQL API endpoint
15
+ * @default /graphql
16
+ */
17
+ private _endpoint;
18
+ private _persistedOperations;
19
+ private _persistedDocuments?;
20
+ private _configMeta?;
21
+ private _subscribedQueries;
22
+ private _inFlight;
23
+ private _cacheStore;
24
+ private _runtimeCache;
25
+ private _queryInvalidation;
26
+ private _mutationInvalidation;
27
+ /**
28
+ * A list of all "effects" that have run, used to keep track of
29
+ */
30
+ private _effectsIssued;
8
31
  constructor(config: GraphQLQueryCacheConfig);
9
32
  /**
10
33
  * Invalidates a query by name or predicate fn
@@ -53,10 +76,31 @@ export declare class GraphQLQueryCache {
53
76
  */
54
77
  executeQuery<Q extends keyof GraphQLQuery.QueryRegistry>(queryName: Q, variables: SerializedVariables | GraphQLQuery.OperationVariables[Q]): Promise<GraphQLQueryResult<Q>>;
55
78
  executeSubscription(): Promise<void>;
79
+ _getKey(operationName: string, variables: SerializedVariables | object): string;
56
80
  /**
57
81
  * "Subscribes" to a query, meaning that when there are updates to fields in the
58
82
  * field cache, we'll re-materialize the known value of the query. We'll also
59
83
  * process based on configuration options, such as TTL, invalidateOnMutation
60
84
  */
61
85
  subscribeToQuery<Q extends keyof GraphQLQuery.QueryRegistry>(args: SubscribeToQueryArgs<Q>): () => void;
86
+ _executeOperation<QueryName extends keyof GraphQLQuery.QueryRegistry>(operationType: 'query', operationName: QueryName, variables: SerializedVariables | GraphQLQuery.OperationVariables[QueryName], options?: PersistedQueryOptions): Promise<GraphQLQueryResult<QueryName>>;
87
+ _executeOperation<MutationName extends keyof GraphQLQuery.MutationRegistry>(operationType: 'mutation', operationName: MutationName, variables: SerializedVariables | object, options?: ExecutionOptions): Promise<GraphQLMutationResult<MutationName>>;
88
+ _getMeta(opName: string): NormalizeMetaShape;
89
+ /**
90
+ * Handles "fetch", ensuring we catch network errors and handle non-200
91
+ * responses properly so we're able to forward these on in a normalized fashion
92
+ */
93
+ _fetch(body: GraphQLRequestBody): Promise<GraphQLOperationResult<any>>;
94
+ _makeFetch(body: GraphQLRequestBody): Promise<Response>;
95
+ /**
96
+ * Determine whether we should refetch the query based on the
97
+ * current value of the query, and the options passed to the query
98
+ */
99
+ _shouldRefetchQuery(): void;
100
+ /**
101
+ * "Garbage collection" for existing operations. If they have
102
+ * a TTL or are invalidated by other operations, and aren't mounted,
103
+ * then we can go ahead and sweep out any data we might have for them
104
+ */
105
+ _gcOperations(): void;
62
106
  }