How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import { ApolloClient, HttpLink, ApolloLink, InMemoryCache, concat } from '@apollo/client';
    
    const httpLink = new HttpLink({ uri: '/graphql' });
    
    const authMiddleware = new ApolloLink((operation, forward) => {
      // add the authorization to the headers
      operation.setContext(({ headers = {} }) => ({
        headers: {
          ...headers,
          authorization: localStorage.getItem('token') || null,
        }
      }));
    
      return forward(operation);
    })
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: concat(authMiddleware, httpLink),
    });
    Docs
  • import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client';
    
    const httpLink = new HttpLink({ uri: '/graphql' });
    
    const addDateLink = new ApolloLink((operation, forward) => {
      return forward(operation).map(response => {
        response.data.date = new Date();
        return response;
      });
    });
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: addDateLink.concat(httpLink),
    });
    Docs
  • import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
    import { onError } from '@apollo/client/link/error';
    
    import { logout } from './logout';
    
    const httpLink = new HttpLink({ uri: '/graphql' });
    
    const logoutLink = onError(({ networkError }) => {
      if (networkError.statusCode === 401) logout();
    })
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: logoutLink.concat(httpLink),
    });
    Docs
  • import { HttpLink, InMemoryCache, ApolloClient } from "@apollo/client";
    import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries";
    import { sha256 } from 'crypto-hash';
    
    const httpLink = new HttpLink({ uri: "/graphql" });
    const persistedQueriesLink = createPersistedQueryLink({ sha256 });
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: persistedQueriesLink.concat(httpLink);
    });
    Docs
  • import {
      ApolloClient,
      InMemoryCache,
      HttpLink,
      ApolloLink
    } from "@apollo/client";
    import { asyncMap } from "@apollo/client/utilities";
    
    import { usdToEur } from './currency';
    
    const httpLink = new HttpLink({ uri: '/graphql' });
    
    const usdToEurLink = new ApolloLink((operation, forward) => {
      return asyncMap(forward(operation), async (response) => {
        let data = response.data;
        if (data.price && data.currency === "USD") {
          data.price = await usdToEur(data.price);
          data.currency = "EUR";
        }
        return response;
      });
    });
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: usdToEurLink.concat(httpLink)
    });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples