58
loading...
This website collects cookies to deliver better user experience
npx create-react-app project-name
, then cd into project-name
and npm install @apollo/client graphql
. Open the file in code editor of choice.index.js
initialize ApolloClient by importing:import {
ApolloClient,
InMemoryCache,
ApolloProvider,
HttpLink,
ApolloLink,
} from "@apollo/client";
.env
file in the root of the project. .env
file and create two variables:REACT_APP_KEY=
(paste 'x-hasura-admin-key' here)REACT_APP_URI=
(paste 'GraphQL Endpoint' here)index.js
use env variables to connect to the API.App.js
and import:import { useQuery, gql } from '@apollo/client'
gql
tag.useQuery(GET_TODOS)
.useQuery
returns an object from Apollo Client that contains loading, error, and data properties you can use to render your UI.console.log
'loading, error, data' to see your data on the front end in devtools.