Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Subwaytime opened this issue Mar 7, 2024 · 5 comments
Open

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

Subwaytime opened this issue Mar 7, 2024 · 5 comments

Comments

@Subwaytime
Copy link

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!

@logaretm
Copy link
Owner

logaretm commented Mar 8, 2024

They should be working as of 3.4, which version are you on?

@Subwaytime
Copy link
Author

"gql.tada": "^1.3.0",
"@0no-co/graphqlsp": "^1.4.2",
"villus": "^3.4.0"

Could it be the typescript configuration? - I am also using bun, so not sure if that might be a cause..

@logaretm
Copy link
Owner

logaretm commented Mar 9, 2024

Create a repo where this is visible and I will take a look.

@Subwaytime
Copy link
Author

Sure, will try to set something up thats similiar! Might take some time, hopefully thats okay

@Subwaytime
Copy link
Author

https://github.com/Subwaytime/villus-gql-issue - I tried using executeQuery and executeMutation and it has the same result. In the tada.ts is the gql request and data is always a Ref<any>.

Note: The repo is similiar to the actual project aside from the fact that the queries and mutations are usually in an api folder instead of the store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants