Created
June 28, 2017 09:06
-
-
Save idkjs/afc901360dd8d8836228eb0bb1e61cab to your computer and use it in GitHub Desktop.
This file contains 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
"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: "https://3qmw47n5v.lp.gql.zone/graphql" | |
}); | |
// networkInterface.use([{ | |
// applyMiddleware(req, next) { | |
// // we can apply tokens to the header here | |
// next(); | |
// } | |
// }]); | |
const client = new ApolloClient({ | |
initialState: { apollo: "" }, | |
networkInterface: networkInterface | |
}); | |
let query = gql` | |
query ( $limit: Int!, $keyword:String){ | |
businesses(limit:$limit, keyword:$keyword){ | |
name | |
stars | |
review_count | |
} | |
} | |
` | |
function getItems(keyword) { | |
console.log(keyword) | |
client.query({query, | |
variables: { | |
limit: 5, | |
keyword: keyword | |
} | |
}).then((results) => { | |
//do something useful | |
console.log(client.store.getState().apollo); | |
console.log(results) | |
return results.data | |
}) | |
.catch(error => { | |
console.log("error: ", error); | |
}) | |
} | |
window._getItems = getItems; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment