Giter VIP home page Giter VIP logo

Comments (4)

lukadriel7 avatar lukadriel7 commented on May 27, 2024 2

I currently do not have acces to a graphql server so i wrote it as I though but you can try the following:

Code for the link in separate file:

import { HttpLink } from "apollo-link-http";
import { split } from "apollo-link";
import { WebSocketLink } from "apollo-link-ws";
import { getMainDefinition } from "apollo-utilities";
import fetch from "node-fetch";
import { w3cwebsocket } from "websocket";

const onServer = process.env.SERVER;
const httpLinkConfig = {
  uri: "https://countries.trevorblades.com/"
};

const wsLinkConfig = {
  uri: "ws://localhost:3000/subscriptions",
  options: {
    reconnect: true
  }
};

if (onServer) {
  httpLinkConfig.fetch = fetch;
  wsLinkConfig.webSocketImpl = w3cwebsocket;
}
// Create the http link
const httpLink = new HttpLink(httpLinkConfig);

// Create the subscription websocket link
const wsLink = new WebSocketLink(wsLinkConfig);

const link = split(
  // split based on operation type
  ({ query }) => {
    const definition = getMainDefinition(query);
    return (
      definition.kind === "OperationDefinition" &&
      definition.operation === "subscription"
    );
  },
  wsLink,
  httpLink
);

export { link };

Code in the hook file:

import { link } from "../js/apollo";

export function apolloClientBeforeCreate({ apolloClientConfigObj }) {
  apolloClientConfigObj.link = link;
  // if needed you can modify here the config object used for apollo client
  // instantiation
}

export function apolloClientAfterCreate(/* { apolloClient, app, router, store, ssrContext, urlPath, redirect } */) {
  // if needed you can modify here the created apollo client
}

P.S.: Do not forget to install all dependencies and change the urls to match your endpoint.
Also please let me know how it went

from app-extension-apollo.

ejez avatar ejez commented on May 27, 2024 1

Thanks @lukadriel7 , the provided hooks allow full customization of the client.

from app-extension-apollo.

lukadriel7 avatar lukadriel7 commented on May 27, 2024

Hello, I haven't tried it personally but I think using the apolloClientBeforeCreate hook located in src/quasar-app-extension-apollo/apollo-client-hooks.js, you are able to change the link of the apolloClient at your convenience before it's creation. You could setup a link in a different js file following this guide, and import it in the apollo-client-hooks to replace the default link. I created my own link using apollo-upload-client that way and it seems to work. Maybe try and let us know how it went.

from app-extension-apollo.

lukadriel7 avatar lukadriel7 commented on May 27, 2024

@ejez Happy it worked out

from app-extension-apollo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.