@swan-io/graphql-client
Advanced tools
Comparing version 0.1.0-alpha10 to 0.1.0-alpha11
@@ -1188,10 +1188,11 @@ 'use strict'; | ||
const [stableQuery] = react.useState(query); | ||
const [stableVariables, setStableVariables] = react.useState(variables); | ||
const [stableVariables, setStableVariables] = react.useState([variables, variables]); | ||
react.useEffect(() => { | ||
if (!deepEqual(stableVariables, variables)) { | ||
setStableVariables(variables); | ||
const [providedVariables] = stableVariables; | ||
if (!deepEqual(providedVariables, variables)) { | ||
setStableVariables([variables, variables]); | ||
} | ||
}, [stableVariables, variables]); | ||
const getSnapshot = react.useCallback(() => { | ||
return client.readFromCache(stableQuery, stableVariables); | ||
return client.readFromCache(stableQuery, stableVariables[1]); | ||
}, [client, stableQuery, stableVariables]); | ||
@@ -1212,3 +1213,3 @@ const data = react.useSyncExternalStore( | ||
} | ||
const request = client.query(stableQuery, stableVariables, { optimize }); | ||
const request = client.query(stableQuery, stableVariables[1], { optimize }); | ||
return () => request.cancel(); | ||
@@ -1219,3 +1220,3 @@ }, [client, suspense, optimize, stableQuery, stableVariables]); | ||
setIsRefreshing(true); | ||
return client.request(stableQuery, stableVariables).tap(() => setIsRefreshing(false)); | ||
return client.request(stableQuery, stableVariables[1]).tap(() => setIsRefreshing(false)); | ||
}, [client, stableQuery, stableVariables]); | ||
@@ -1225,3 +1226,4 @@ const [isReloading, setIsReloading] = react.useState(false); | ||
setIsReloading(true); | ||
return client.request(stableQuery, stableVariables).tap(() => setIsReloading(false)); | ||
setStableVariables(([stable]) => [stable, stable]); | ||
return client.request(stableQuery, stableVariables[0]).tap(() => setIsReloading(false)); | ||
}, [client, stableQuery, stableVariables]); | ||
@@ -1231,7 +1233,18 @@ const isLoading = isRefreshing || isReloading || asyncData.isLoading(); | ||
if (suspense && asyncDataToExpose.isLoading()) { | ||
throw client.query(stableQuery, stableVariables, { optimize }).toPromise(); | ||
throw client.query(stableQuery, stableVariables[1], { optimize }).toPromise(); | ||
} | ||
return [asyncDataToExpose, { isLoading, refresh, reload }]; | ||
const setVariables = react.useCallback((variables2) => { | ||
setStableVariables((prev) => { | ||
const [prevStable, prevFinal] = prev; | ||
const nextFinal = { ...prevFinal, ...variables2 }; | ||
if (!deepEqual(prevFinal, nextFinal)) { | ||
return [prevStable, nextFinal]; | ||
} else { | ||
return prev; | ||
} | ||
}); | ||
}, []); | ||
return [asyncDataToExpose, { isLoading, refresh, reload, setVariables }]; | ||
}; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,3 @@ import { AsyncData, Result, Future } from '@swan-io/boxed'; | ||
}; | ||
type Query<Data> = readonly [ | ||
type Query<Data, Variables> = readonly [ | ||
AsyncData<Result<Data, ClientError>>, | ||
@@ -18,6 +18,7 @@ { | ||
refresh: () => Future<Result<Data, ClientError>>; | ||
setVariables: (variables: Partial<Variables>) => void; | ||
} | ||
]; | ||
declare const useQuery: <Data, Variables>(query: TypedDocumentNode<Data, Variables>, variables: Variables, { suspense, optimize }?: QueryConfig) => Query<Data>; | ||
declare const useQuery: <Data, Variables>(query: TypedDocumentNode<Data, Variables>, variables: Variables, { suspense, optimize }?: QueryConfig) => Query<Data, Variables>; | ||
export { type Query, type QueryConfig, useQuery }; |
{ | ||
"name": "@swan-io/graphql-client", | ||
"version": "0.1.0-alpha10", | ||
"version": "0.1.0-alpha11", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A simple, typesafe GraphQL client for React", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
284897
2751
0