Skip to content

Commit 072283d

Browse files
author
Thomas Draier
authored
QA-14773: Return result from cache if available (#245)
1 parent 1b800b8 commit 072283d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/data-helper/src/hooks/useNodeInfo/useNodeInfo.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const timeoutHandler = (client: ApolloClient<object>) => {
108108
});
109109
};
110110

111-
export const useNodeInfo = (variables: {[key:string]: unknown}, options: NodeInfoOptions, queryOptions: Partial<WatchQueryOptions>) => {
111+
export const useNodeInfo = (variables: {[key:string]: unknown}, options?: NodeInfoOptions, queryOptions?: Partial<WatchQueryOptions>) => {
112112
const [result, setResult] = useState<NodeInfoResult>({
113113
loading: true
114114
});
@@ -134,6 +134,16 @@ export const useNodeInfo = (variables: {[key:string]: unknown}, options: NodeInf
134134
}, [client, currentRequest]);
135135

136136
if (queryHasChanged && !result.loading) {
137+
if (queryOptions?.fetchPolicy !== 'no-cache' && queryOptions?.fetchPolicy !== 'network-only') {
138+
const infoQuery = getQuery(currentRequest.variables, schemaResult, currentRequest.options);
139+
const res = client.readQuery({query: infoQuery.query, variables: infoQuery.generatedVariables});
140+
if (res) {
141+
const result = getResult(res, {}, currentRequest.options, infoQuery.query, infoQuery.generatedVariables);
142+
setResult(result);
143+
return result;
144+
}
145+
}
146+
137147
setResult({
138148
loading: true
139149
});

0 commit comments

Comments
 (0)