Skip to content

Instantly share code, notes, and snippets.

@feus4177
Created October 1, 2017 02:43
Show Gist options
  • Save feus4177/d489e714a5fd3cf30fe4953d8b124484 to your computer and use it in GitHub Desktop.
Save feus4177/d489e714a5fd3cf30fe4953d8b124484 to your computer and use it in GitHub Desktop.
Example environment configuration for RelayJS.
import fetch from 'isomorphic-fetch';
import {Environment, Network, RecordSource, Store, RecordSourceInspector} from 'relay-runtime';
const source = new RecordSource();
const store = new Store(source);
const inspector = new RecordSourceInspector(source);
const network = Network.create((operation, variables) => (
fetch('http://localhost/api/v2/graphql/'), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: operation.text,
variables,
}),
}).then((response) => response.json())
));
const environment = new Environment({
network,
store,
});
export {inspector};
export default environment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment