How to use the apollo/configureApolloClient function in apollo

To help you get started, we’ve selected a few apollo 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 drupal-graphql / drupal-decoupled-app / frontend / app / entry / client / index.js View on Github external
// Refs:
// https://stackoverflow.com/questions/40897966/objects-are-not-valid-as-a-react-child-in-internet-explorer-11-for-react-15-4-1#comment69150679_40928047
// https://github.com/facebook/react/issues/8379
import 'babel-polyfill';

import { getUserToken } from 'apollo/tokenStorage';
import configureApolloClient from 'apollo/configureApolloClient';
import Root from './root';

/* eslint-disable no-underscore-dangle,no-undef */
const apiUri = global.__API__;
const initialData = global.__DATA__ || {};

// Load the client's bearer token from browser cookie.
const loadToken = () => getUserToken();
const apolloClient = configureApolloClient(apiUri, loadToken, initialData);

// Find the DOM node generated by the server.
const mountNode = global.document.getElementById('app');

// Encapsulate rendering for hot-reloading.
const render: Function = (Component): void => {
  // $FlowIgnore https://github.com/facebook/flow/pull/5074
  ReactDOM.hydrate(
    ,
    mountNode,
  );
};

if (
  module.hot &&
  module.hot.accept &&
github drupal-graphql / drupal-decoupled-app / frontend / app / entry / server / render.js View on Github external
export default (clientStats: Object) => (
  req: express$Request,
  res: express$Response,
): void => {
  const env: Object = req.app.get('env');
  const apiUri = env.API;

  // Use the cookie from the request object to load the token.
  const loadToken = () => getUserToken(req.headers.cookie);
  const apolloClient = configureApolloClient(apiUri, loadToken);

  const Root: React$Element = (
    
      
        
      
    
  );

  // Start profiling of the react rendering with apollo.
  logger.profile('Rendering with data dependencies');

  // Render the app after loading the graphql data.
  const doRenderFinal = doRender(clientStats, apolloClient);

  // Renders the app component tree into a string.