- npm install apollo/client graphql
- in index.tsx
import { ApolloClient, InMemoryCache, ApolloProvider} from '@apollo/client';
const client = new ApolloClient({ uri: 'https://rickandmortyapi.com/graphql', cache: new InMemoryCache(), });
-
wrap App in Apollo Provider:
-
Query : import {gql, useQuery} from '@apollo/client';
const useCharacters = () => {
const GET_CHARACTERS = gql`
query getCharacters {
characters{
results{
name
image
}
}
}
`;
const {data, loading, error} = useQuery(GET_CHARACTERS)
return ( { data, loading, error } ) }