Skip to content

Instantly share code, notes, and snippets.

@taion taion/runQuery.js
Created Sep 28, 2016

Embed
What would you like to do?
import Relay from 'react-relay';
export default function runQuery(
queryNode,
args,
environment,
forceFetch = false,
) {
const query = Relay.createQuery(queryNode, args);
return new Promise((resolve, reject) => {
function callback({ done, error }) {
if (error) {
reject(error);
return;
}
if (done) {
const [result] = environment.readQuery(query);
resolve(result);
}
}
if (forceFetch) {
environment.forceFetch({ query }, callback);
} else {
environment.primeCache({ query }, callback);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.