Skip to content

Instantly share code, notes, and snippets.

@gje4
Created November 25, 2019 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gje4/c5e2dd5b3b72629d8f6b6fa2c9e2ff6e to your computer and use it in GitHub Desktop.
Save gje4/c5e2dd5b3b72629d8f6b6fa2c9e2ff6e to your computer and use it in GitHub Desktop.
/* eslint-disable */
import React from "react";
import ReactDOM from "react-dom";
import PageManager from "../page-manager";
import ApolloClient from "apollo-boost";
import gql from "graphql-tag";
function getProducts(token, productIds) {
const client = new ApolloClient({
headers: { Authorization: `Bearer ${token}` }
});
client
.query({
query: gql`
query MyFirstQuery {
site {
products(entityIds: ${productIds}) {
edges {
node {
name
description
entityId
defaultImage {
url(width: 200)
}
prices {
price {
value
}
}
}
}
}
}
}
`
})
.then(data => console.log(data))
.catch(error => console.error(error));
}
const HelloWorld = props => (
<div>
<p>Hello World from React!</p>
<p>Here are my props:</p>
<pre>{JSON.stringify(props, null, 2)}</pre>
</div>
);
export default class ReactDemo extends PageManager {
async onReady() {
const getProduct = await getProducts(this.context.storefrontAPIToken, [
this.context.category.description
]);
console.log("getProduct", getProduct);
console.log("prder", this.context.category.description);
const container = $("#root")[0];
ReactDOM.render(<HelloWorld context={this.context} />, container);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment