Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created May 29, 2021 13:26
Show Gist options
  • Save iskenxan/e9c6d66d23706f053254e8760a62f768 to your computer and use it in GitHub Desktop.
Save iskenxan/e9c6d66d23706f053254e8760a62f768 to your computer and use it in GitHub Desktop.
export const wrapGraphQL = (query) => {
let status = "pending";
let result = null;
const suspender = client
.query({
query,
fetchPolicy: "network-only"
})
.then((response) => {
status = "success";
result = response.data;
})
.catch((err) => {
status = "error";
result = err;
});
return {
read() {
if (status === "pending") {
throw suspender;
} else if (status === "error") {
throw result;
} else {
return result;
}
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment