Skip to content
Snippets Groups Projects

Add refresh option to getObject

1 file
+ 9
1
Compare changes
  • Side-by-side
  • Inline
+ 9
1
@@ -364,6 +364,7 @@ class DrupalState {
* @param path Path Alias of a specific resource
* @param res response object
* @param query user provided GraphQL query
* @param refresh a boolean value. If true, ignore local state.
* @returns a promise containing deserialized JSON:API data for the requested
* object
*/
@@ -372,6 +373,7 @@ class DrupalState {
path,
res,
query = false,
refresh = false,
}: GetObjectByPathParams): Promise<PartialState<State> | void> {
const currentState = this.getState() as DsState;
const dsPathTranslations = currentState.dsPathTranslations as GenericIndex;
@@ -405,9 +407,14 @@ class DrupalState {
// because `id` will be undefined later.
return;
} else {
const pathTranslationsState = currentState['dsPathTranslations'];
const pathTranslationsState =
currentState.dsPathTranslations as GenericIndex;
if (pathTranslationsState) {
if (refresh && pathTranslationsState[`${path}`]) {
// Remove old response so refreshed response can be used.
delete pathTranslationsState[`${path}`];
}
// If dsPathTranslaitons exists in state, add the new path to it.
const updatedPathTranslationState = {
...pathTranslationsState,
@@ -437,6 +444,7 @@ class DrupalState {
id: id,
res,
query,
refresh,
});
return object;
}
Loading