Skip to content

Instantly share code, notes, and snippets.

@idkjs
Created June 28, 2017 09:06
Show Gist options
  • Save idkjs/afc901360dd8d8836228eb0bb1e61cab to your computer and use it in GitHub Desktop.
Save idkjs/afc901360dd8d8836228eb0bb1e61cab to your computer and use it in GitHub Desktop.
"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