logaretm / villus

🏎 A tiny and fast GraphQL client for Vue.js
https://villus.dev
MIT License
791 stars 31 forks source link

Respect type definitions for executeQuery #128

Closed JarvisH closed 3 years ago

JarvisH commented 3 years ago

In the documentation https://villus.logaretm.com/guide/typescript-codgen/#using-generated-queries it shows the following code example:

const { data } = useQuery<PostsQuery, PostsQueryVariables>({
  query: Posts
  variables: {
    // variables are now typed as PostsQueryVariables
  },
});

data.value; // is now typed as PostsQuery type!

This does not appear to work when using executeQuery instead of useQuery. In the villus.d.ts file the following signature is found:

executeQuery<TData = any, TVars = QueryVariables>(operation: OperationWithCachePolicy<TData, TVars>, queryContext?: QueryExecutionContext): Promise<OperationResult>;

Is it as simple as adding TData to OperationResult?

logaretm commented 3 years ago

Thanks for reporting this, yes you are right it is as you suggested. You should find the updated types in rc.18

JarvisH commented 3 years ago

Thank you for the quick fix, you rock!