Last active
August 31, 2017 03:14
-
-
Save ronal2do/6db9a097059c7908dbd4476a8dd18406 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @flow | |
*/ | |
import { | |
Environment, | |
Network, | |
RecordSource, | |
Store, | |
} from 'relay-runtime'; | |
// Define a function that fetches the results of an operation (query/mutation/etc) | |
// and returns its results as a Promise: | |
function fetchQuery(operation, variables, cacheConfig, uploadables) { | |
return fetch('http://localhost:5000/graphql', { | |
method: 'POST', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
// Add authentication and other headers here | |
}, | |
body: JSON.stringify({ | |
query: operation.text, // GraphQL text from input | |
variables, | |
}), | |
}).then(response => { | |
return response.json(); | |
}); | |
} | |
// Create a network layer from the fetch function | |
const network = Network.create(fetchQuery); | |
const source = new RecordSource(); | |
const store = new Store(source); | |
const environment = new Environment({ | |
network, | |
store, | |
}); | |
export default environment; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment