-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
54 lines (50 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
const { ApolloClient } = require("apollo-client");
const { createNetworkInterface } = require("apollo-client");
const gql = require("graphql-tag");
require("es6-promise").polyfill();
require("isomorphic-fetch");
const networkInterface = createNetworkInterface({
uri: "http://localhost:5000/graphql"
});
// networkInterface.use([{
// applyMiddleware(req, next) {
// // we can apply tokens to the header here
// next();
// }
// }]);
const client = new ApolloClient({
initialState: { apollo: "" },
networkInterface: networkInterface
});
function getItems() {
return client
.query({
query: gql `{
viewer {
businesses(first: 5) {
pageInfo {
hasNextPage
}
edges {
node {
name
stars
review_count
}
}
}
}
}`
})
.then(results => {
// console.log(results.data.viewer.businesses.edges);
// console.log(client.store.getState().apollo);
console.log("client fetch done");
return results.data.viewer.businesses.edges;
})
.catch(error => {
console.log("error: ", error);
});
}
window._getItems = getItems;