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

fix: Villus Subscriptions subscriptions-transport-ws breaks Vite #6

Closed
kingkong404 opened this issue Oct 22, 2020 · 4 comments
Closed

Comments

@kingkong404
Copy link

Hey don't know if you have any ideas how to fix but as soon as you want to use Subscriptions in Villus you need to use subscriptions-transport-ws to set up the Websocket client although it does not play nice with Vite.

After running yarn dev in Chrome you get the following error and it crashes Vite.

image

Although once the project is built the error goes away and SubscriptionClient is found, so seems to be something to do with how Vite is hot loading the module.

Don't know if you know any ideas / options in the vite.config.js file we could try.

<script lang="ts">
import { SubscriptionClient } from 'subscriptions-transport-ws';
import { defineComponent, computed } from 'vue';
import { router } from './main';
import { useClient, handleSubscriptions, defaultPlugins, useMutation, createClient } from 'villus';
import { ActionTypes, MutationTypes, useStore } from './store';
import { LoginDocument } from './generated/types';

const subscriptionClient = new SubscriptionClient(
  'wss://xxxxxxxx/graphql',
  { reconnect: true }
);

const subscriptionForwarder = (operation: any) => subscriptionClient.request(operation);

export default defineComponent({
  name: 'Main',
  setup() {
    const store = useStore();

    const client = useClient({
      url: 'http://localhost:4000/graphql',
      // @ts-ignore
      use: [handleSubscriptions(subscriptionForwarder), ...defaultPlugins()],
    });

  },
});
</script>
@lewebsimple
Copy link
Collaborator

Haven't tried subscriptions yet.

vitejs/vite#496 and vitejs/vite#864 might have something to do with this.

@lewebsimple
Copy link
Collaborator

Also vitejs/vite#452 and vitejs/vite#918

@kingkong404
Copy link
Author

Nice looks like potentially they've pushed a fix although they haven't released a new RC for 3 months :/

Hopefully we'll get something soon!

@lewebsimple lewebsimple changed the title Villus Subscriptions subscriptions-transport-ws breaks Vite fix: Villus Subscriptions subscriptions-transport-ws breaks Vite Oct 23, 2020
@lewebsimple
Copy link
Collaborator

This works:

import ws from "subscriptions-transport-ws";
const subscriptionClient = new ws.SubscriptionClient(wsEndpoint, {});

It's fixed in 0.2.0

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