Created
May 29, 2021 13:26
-
-
Save iskenxan/e9c6d66d23706f053254e8760a62f768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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