Created
August 25, 2017 15:23
-
-
Save gc-codesnippets/2e261f56ca0c5b8ceb0b34faf1e52b24 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
// 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