graphql-engine/community/sample-apps/realtime-chat-vue/src/vue-apollo.js
Praveen Durairaju a5c02ab405 community: update sample apps to use hasura cloud and v3 migrations/metadata
GitOrigin-RevId: c3858e4ed2f3d544f797ee159bd03b458d9cf82e
2021-03-02 08:32:37 +00:00

52 lines
1.1 KiB
JavaScript

import Vue from "vue";
import { ApolloClient } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { WebSocketLink } from "apollo-link-ws";
import { getMainDefinition } from "apollo-utilities";
import { split } from "apollo-link";
import VueApollo from "vue-apollo";
// Http endpoint
const httpLink = new HttpLink({
uri: "https://realtime-chat.hasura.app/v1/graphql"
})
const wsLink = new WebSocketLink({
uri: "wss://realtime-chat.hasura.app/v1/graphql",
options: {
reconnect: true
}
});
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
httpLink
);
const apolloClient = new ApolloClient({
link,
cache: new InMemoryCache(),
connectToDevTools: true
});
Vue.use(VueApollo);
// Call this in the Vue app file
export function createProvider() {
return new VueApollo({
defaultClient: apolloClient,
defaultOptions: {
$loadingKey: "loading"
}
});
}