Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created August 25, 2017 15:23
Show Gist options
  • Save gc-codesnippets/2e261f56ca0c5b8ceb0b34faf1e52b24 to your computer and use it in GitHub Desktop.
Save gc-codesnippets/2e261f56ca0c5b8ceb0b34faf1e52b24 to your computer and use it in GitHub Desktop.
// 1
const {
Environment,
Network,
RecordSource,
Store,
} = require('relay-runtime')
// 2
const store = new Store(new RecordSource())
// 3
const network = Network.create((operation, variables) => {
// 4
return fetch('__RELAY_API_ENDPOINT__', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: operation.text,
variables,
}),
}).then(response => {
return response.json()
})
})
// 5
const environment = new Environment({
network,
store,
})
// 6
export default environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment