Created
August 11, 2017 18:46
-
-
Save koistya/59c840bc9d44077f72c29f918a4bce7c to your computer and use it in GitHub Desktop.
Relay Modern client (environment) https://medium.com/p/989c078fa892
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
import { Environment, Network, RecordSource, Store } from 'relay-runtime'; | |
function fetchQuery(operation, variables) { | |
return fetch( | |
'https://graphql-demo.kriasoft.com/', | |
{ | |
method: 'POST', | |
headers: { | |
// Add authentication and other headers here | |
'content-type': 'application/json', | |
}, | |
credentials: 'include', | |
body: JSON.stringify({ | |
query: operation.text, // GraphQL text from input | |
variables, | |
}), | |
}, | |
).then(response => response.json()); | |
} | |
export default new Environment({ | |
network: Network.create(fetchQuery), | |
store: new Store(new RecordSource()), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment