Skip to content

Instantly share code, notes, and snippets.

@Ifmr24
Last active October 9, 2019 17:24
Show Gist options
  • Save Ifmr24/a3ce405e376a9cfc7524c1501026a2b4 to your computer and use it in GitHub Desktop.
Save Ifmr24/a3ce405e376a9cfc7524c1501026a2b4 to your computer and use it in GitHub Desktop.
Conectarse a la api graphql de shopify y una query simple
import { ApolloClient } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { setContext } from "apollo-link-context";
const middlewareLink = setContext(() => ({
headers: {
"X-Shopify-Storefront-Access-Token": "{Token del storefront}"
}
}));
const httpLink = new HttpLink({
uri: "{link de la tienda}/api/2019-07/graphql.json"
});
const link = middlewareLink.concat(httpLink);
export const client = new ApolloClient({
link,
cache: new InMemoryCache()
});
import React from "react";
import Base from "../layouts/Base";
import gql from "graphql-tag";
import { useQuery } from "@apollo/react-hooks";
const GET_SHOP_INFO = gql`
{
shop {
name
}
}
`;
const Index = () => {
const { loading, error, data } = useQuery(GET_SHOP_INFO);
if (loading) return "Loading..";
if (error) return `Error ${error.message}`;
return (
<Base title="Index Page" description="descripcion de la pagina inicial">
<h1>{data.shop.name}</h1>
</Base>
);
};
export default Index;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment