Git Product home page Git Product logo

apollo-multi-endpoint-link's Introduction

Apollo link which add an api directive to fetch data from multi endpoints

CircleCI Version Size License

Install

   npm i @habx/apollo-multi-endpoint-link

Setup

  new ApolloClient({
    link: ApolloLink.from([
      new MultiAPILink({
          endpoints: {
              housings: 'https://housings.api',
              projects: 'https://projects.api',
              ...
          },
          createHttpLink: () => new HttpLink({ ... }),
        }),
    ])
  })
API
  new MultiAPILink(config, request)
config
Parameter Description Default Required
endpoints Dictionary of endpoints Yes
createHttpLink Function to generate http link like apollo-link-http Yes
createWsLink Function to generate wsLink like apollo-link-ws No
wsSuffix Suffix added to endpoint for subscriptions queries /graphql/subscriptions No
httpSuffix Suffix added to endpoint for http queries /graphql No
getContext Callback function called to set custom context like headers No

Queries

  query projectList @api(name: projects) {
    projects {
      nodes {
        id
        name
      }
    }
  }

Setting custom context

Sometimes you might need to set custom apollo link context like headers for authentication purpose. This link allows it by doing as following.

new MultiAPILink({
    getContext: (endpoint) => {
      if (endpoint === 'yourendpoint-with-auth') {
        return ({
          headers: {
            'Authorization': 'xxxx',
          }
        })
      }
      return {}
    },
    ...
})

We wrote an article about how we did this link if you want more details

apollo-multi-endpoint-link's People

Contributors

dependabot-preview[bot] avatar flaviendelangle avatar habx-auto-merge[bot] avatar habxtech avatar jean9696 avatar samuelcastro avatar

Stargazers

 avatar

Watchers

 avatar

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.