mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
a5c02ab405
GitOrigin-RevId: c3858e4ed2f3d544f797ee159bd03b458d9cf82e
52 lines
1.1 KiB
JavaScript
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"
|
|
}
|
|
});
|
|
}
|