logaretm / villus

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

Typescript issue in subscription forwarder #210

Closed JarvisH closed 3 months ago

JarvisH commented 4 months ago

Hello again and thanks for all the hard work on this project!

Using the following example from the documentation:

const subscriptionsHandler = handleSubscriptions(operation => {
  return {
    subscribe: obs => {
      wsClient.subscribe(
        {
          query: operation.query,
          variables: operation.variables,
        },
        obs
      );
      return {
        unsubscribe: () => {
          // No OP
        },
      };
    },
  };
});

operation.query is typed as follows:

interface Operation<TData, TVars> {
    query: string | DocumentNode | DocumentDecoration<TData, TVars>;
    variables?: TVars;
}

wsClient.subscribe however expects the query option to always be a string, and indeed the type coming from Villus IS a string. It appears to be a pure TS issue.