Slide 11
Slide 11 text
// apollo-link-http ͷ؆қ࣮ྫ
const httpLink = new ApolloLink(operation => {
return new Observable(observer => {
const key = operation.toKey();
const query = key.slice(0, key.length - ‘|{}|
null'.length);
fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json', },
body: JSON.stringify({
operationName: operation.operationName,
variables: operation.variables,
query,
}),
})
.then(res => res.json())
.then(json => observer.next(json))
.catch(json => observer.error(json))
.finally(() => observer.complete());
});
});