Skip to content

gql.tada / TadaDocumentNode types are not automatically infered #207

Open
@Subwaytime

Description

@Subwaytime

Essentially when using useQuery or useMutation, any query/mutation type does not get infered for the data object.

import { graphql } from 'gql.tada';
import { useQuery } from 'villus';

const getBooksQuery = graphql(`
  query GetBooks {
    books {
      id
      title
    }
  }
`);

const { data, error } = useQuery({
  query: getBooksQuery
});

data // globalThis.Ref<any>

This can be fixed if we provide the types directly

import { graphql } from 'gql.tada';
import { useQuery } from 'villus';

const getBooksQuery = graphql(`
  query GetBooks {
    books {
      id
      title
    }
  }
`);

const { data, error } = useQuery<typeof getBooksQuery>({
  query: getBooksQuery
});

However it would be great if these are automatically set, similiar to
https://villus.logaretm.com/guide/typescript-codgen/#using-typed-document.

Not sure if this would be possible!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions