Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-client-mux

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-client-mux

multiple GraphQL endpoints within a single Apollo Client instance

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
134
decreased by-18.79%
Maintainers
1
Weekly downloads
 
Created
Source

Apollo Client Mux

apollo-client-mux is a library designed to handle multiple GraphQL endpoints within a single Apollo Client instance. It allows you to set different caches and links for different endpoints.

Usage

Step 1: add @endpoint directive to operation documents

// codegen.<yourEndpointName>.ts
import type { CodegenConfig } from "@graphql-codegen/cli";
import { addEndpointDirectiveForCodegen } from "apollo-client-mux/transform";

const config: CodegenConfig = {
  // ...
  generates: {
    "src/gql/<yourEndpoint>/": { // <- use your endopint name
      preset: "client",
      documentTransforms: [
        {
          transform: addEndpointDirectiveForCodegen({
            endpointName: "yourEndpoint", // <- use your endopint name
          }),
        },
      ],
    },
  },
};

export default config;
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { ApolloCacheMux, withCacheMux } from "apollo-client-mux";

// create ApolloCache
const InMemoryCacheMux = withCacheMux(InMemoryCache);
const yourEndpointCache = new InMemoryCache();
const cache = new InMemoryCacheMux({
  mux:{
    caches: {
      yourEndpoint: yourEndpointCache, // <-- use your endopint name
    },
  }
  // ... options for default cache
});

// create ApolloLink
const yourEndpointHttpLinnk = new HttpLink({ /* ... */ });
const defaultHttpLinnk = new HttpLink({ /* ... */ });
const link = createApolloLinkMux({
  links: {
    yourEndpoint: yourEndpointHttpLink, // <-- use your endopint name
  },
  defaultLink: defaultHttpLink;
});

// create Apollo Client
const client = new ApolloClient({
  cache,
  link,
});

Keywords

FAQs

Package last updated on 27 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc