Last active
October 9, 2019 17:24
-
-
Save Ifmr24/a3ce405e376a9cfc7524c1501026a2b4 to your computer and use it in GitHub Desktop.
Conectarse a la api graphql de shopify y una query simple
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
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() | |
}); |
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
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