Thinkmill / ts-gql

Write GraphQL queries with a gql tag in TypeScript -> have generated types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement `useLazyQuery`

jesstelford opened this issue · comments

The docs state:

@ts-gql/apollo only exposes a subset of @apollo/client's functionality. For example, it doesn't expose useLazyQuery because we recommend using useApolloClient().query instead. If you disagree with some of the decisions that @ts-gql/apollo makes, you can use ts-gql but write your own type definitions for Apollo or another GraphQL client.

In my experience so far, I've ended up doing a import { useQuery } from '@ts-gql/apollo'; import { useApolloClient } from '@apollo/client' which feels like unnecessary work.

It also means the queries have to use apollo's gql tagged template literal, which means we can't re-use queries across ts-gql and raw apollo.

Hey @jesstelford 👋
@ts-gql/apollo exports useApolloClient with the correct types, so you should be able to do this:

import { useApolloClient, useQuery } from '@ts-gql/apollo';

With the change to use @graphql-typed-document-node/core, you can now use useLazyQuery from @apollo/client and it will work with ts-gql's queries.