Created
November 25, 2019 19:04
-
-
Save gje4/c5e2dd5b3b72629d8f6b6fa2c9e2ff6e 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
/* 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