Skip to content

Instantly share code, notes, and snippets.

@koistya
Created August 11, 2017 18:46
Show Gist options
  • Save koistya/59c840bc9d44077f72c29f918a4bce7c to your computer and use it in GitHub Desktop.
Save koistya/59c840bc9d44077f72c29f918a4bce7c to your computer and use it in GitHub Desktop.
Relay Modern client (environment) https://medium.com/p/989c078fa892
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