Slide 8
Slide 8 text
import {
Environment,
Network,
RecordSource,
Store,
} from 'relay-runtime';
function fetchQuery(
operation,
variables,
) {
return fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: operation.text,
variables,
}),
}).then(response => {
return response.json();
});
}
const environment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
});
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-
inmemory';
const cache = new InMemoryCache();
const httpLink = new HttpLink({
uri: https://api.github.com/graphql,
headers: {
authorization: `Bearer ${
process.env.REACT_APP_GITHUB_PERSONAL_ACCESS_TOKE
N}`,
},
});
const client = new ApolloClient({
link: httpLink,
cache,
});
// relay // apollo