How to use apollo-boost - 10 common examples

To help you get started, we’ve selected a few apollo-boost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github artsmia / lume / app / apollo / OldIndex.js View on Github external
}

      return {
        headers: {
          ...prevCtx.headers,
          ...authHeaders
        }
      }
    } catch (ex) {
      console.error(ex)
    }
  })

  const link = ApolloLink.from([authLink, stateLink, httpLink])

  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link,
    cache
  })
}
github codica2 / nextjs-graphql-sample / utils / initApollo.ts View on Github external
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
        );

        if (isBrowser && message.includes("not authenticated")) {
          Router.replace("/login");
        }
      });
    }

    if (networkError) {
      console.log(`[Network error]: ${networkError}`);
    }
  });

  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  return new ApolloClient({
    connectToDevTools: isBrowser,
    ssrMode: !isBrowser, // Disables forceFetch on the server (so queries are only run once)
    // link: authLink.concat(httpLink),
    link: ApolloLink.from([errorLink, authLink, httpLink]), // Composing Links
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github prvnbist / expense-app-frontend / src / index.js View on Github external
// Middleware to set the headers
const authLink = new ApolloLink((operation, forward) => {
  if (localStorage.getItem("access_token") !== undefined) {
    const token = localStorage.getItem("access_token");
    operation.setContext({
      headers: {
        authorization: token ? `Bearer ${token}` : ""
      }
    });
    return forward(operation);
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
  fetchOptions: {
    credentials: "include"
  },
  onError: ({ networkError }) => {
    if (networkError) console.log("Network Error", networkError);
  }
});

class App extends Component {
  render() {
    return (
github abhi40308 / instagram-clone / src / components / App.js View on Github external
// get access token
  const getAccessToken = async () => {
    // getTokenSilently() returns a promise
    try {
      const token = await getTokenSilently();
      setAccessToken(token);
      console.log(token);
    } catch (e) {
      console.log(e);
    }
  };
  getAccessToken();

  // for apollo client
  const httpLink = new HttpLink({
    uri: "https://instagram-clone-3.herokuapp.com/v1/graphql"
  });

  const authLink = setContext((_, { headers }) => {
    const token = accessToken;
    if (token) {
      return {
        headers: {
          ...headers,
          authorization: `Bearer ${token}`
        }
      };
    } else {
      return {
        headers: {
          ...headers
github msand / InfiniDraw / lib / init-apollo.js View on Github external
function create(initialState, native) {
  const httpLink = new HttpLink({
    uri: 'https://api.graph.cool/simple/v1/cjh2g1fxn6gsw0108o6ud01ms', // Server URL (must be absolute)
    credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
  });
  const wsLink =
    (process.browser || native) &&
    new WebSocketLink({
      uri: 'wss://subscriptions.graph.cool/v1/cjh2g1fxn6gsw0108o6ud01ms',
      options: {
        reconnect: true,
      },
    });
  const link =
    !process.browser && !native
      ? httpLink
      : split(
          ({ query }) => {
github babel-blade / babel-blade / talks / apollo-demo / src / App.js View on Github external
const LambdaDemo = () => (
  
    
      {({ data }) => {
        console.log("dogQuery", dogQuery);
        const DATA = dogQuery(data); // creates a blade
        return (
          <div>
            A greeting from the server: {DATA.hello}
            <br>
            <img src="{DATA.dogPhotoUrl}" alt="dog">
          </div>
        );
      }}
    
  
);
github birkir / graphql-gatsby / examples / with-next / next.config.js View on Github external
exportPathMap: async (pathMap, options) => {
    if (process.argv[1].match(/next-export$/) && !options.dev) {
      // Wait until server becomes ready in export mode
      await promiseRetry((retry, number) => {
        console.log('waiting for server...', number);
        return fetch(`http://localhost:${port}/graphql?query=%7Bsite%7Bid%7D%7D`)
        .then(res => res.status !== 200 && new Error('Failure'))
        .catch(retry);
      });
      await new Promise(resolve => setTimeout(resolve, 1000)); // shjattlari

      const client = new ApolloClient({ uri: `http://localhost:${port}/graphql` });

      const allMediumPostsQuery = gql`query {
        allMediumPost {
          edges {
            node {
              id
              slug
            }
          }
        }
      }`;
      const res = await client.query({ query: allMediumPostsQuery });

      const posts = [].concat(res.data && res.data.allMediumPost.edges || []).reduce((acc, { node }) => {
        acc[`/post/${node.slug}`] = {
          page: '/post',
github codica2 / nextjs-graphql-sample / utils / initApollo.ts View on Github external
Router.replace("/login");
        }
      });
    }

    if (networkError) {
      console.log(`[Network error]: ${networkError}`);
    }
  });

  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  return new ApolloClient({
    connectToDevTools: isBrowser,
    ssrMode: !isBrowser, // Disables forceFetch on the server (so queries are only run once)
    // link: authLink.concat(httpLink),
    link: ApolloLink.from([errorLink, authLink, httpLink]), // Composing Links
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github nilshartmann / graphql-examples / schema-stitching / frontend / src / main.tsx View on Github external
import * as React from "react";
import * as ReactDOM from "react-dom";

import ApolloClient from "apollo-boost";
import { ApolloProvider } from "react-apollo";

import BeerRatingApp from "./BeerRatingApp";

// Point GraphQL Client to our Schema Stitcher
const client = new ApolloClient({ uri: "http://localhost:9000/graphql" });

const theBeerRatingApp = (
  
    
  
);

const mountNode = document.getElementById("app");
ReactDOM.render(theBeerRatingApp, mountNode);
github mizchi-sandbox / next-graphql-playground-201903 / next / lib / initApolloClient.ts View on Github external
function createApolloClient(initialState: NormalizedCacheObject) {
  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link: new HttpLink({
      // uri: "https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn", // Server URL (must be absolute)
      uri: "http://localhost:3030/graphql"
      // credentials: true
      // credentials: "same-origin" // Additional fetch() options like `credentials` or `headers`
    }),
    cache: new InMemoryCache().restore(initialState)
  });
}