How to use the react-apollo.ApolloClient function in react-apollo

To help you get started, we’ve selected a few react-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 thebillkidy / MERGE-Stack / GRAPH / client / src / lib / initClient.js View on Github external
// Pass headers here if your graphql server requires them
    }
  });

  networkInterface.use([{
    applyMiddleware(req, next) {
      if (!req.options.headers) {
        req.options.headers = {};  // Create the header object if needed.
      }
      // get the authentication token from local storage if it exists
      req.options.headers.authorization = cookie.load('token') || null;
      next();
    }
  }]);

  return new ApolloClient({
    initialState,
    ssrMode: !process.browser,
    dataIdFromObject: result => result.id || null,
    networkInterface: networkInterface
  })
}
github morajabi / morajabi.im / utils / initApollo.js View on Github external
function create(initialState) {

  const networkInterface = createNetworkInterface({
    uri: SIMPLE_ENDPOINT,
    opts: { // Additional fetch() options like `credentials` or `headers`
      credentials: 'same-origin'
    },
    dataIdFromObject: o => o.id,
  })

  return new ApolloClient({
    initialState,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    networkInterface,
  })
}
github partyparrot / codetours / client / presentation / index.js View on Github external
import Tour from './Tour';

// fancy!
import TOUR_QUERY from './tour.graphql';

const TourWithData = graphql(TOUR_QUERY, {
  options: ({ tourRepository }) => ({ variables: { tourRepository } }),
  props: ({ data: { tour, loading, error } }) => ({
    tour,
    loading,
    error,
  }),
})(Tour);

const client = new ApolloClient({
  networkInterface: createNetworkInterface({
    // === CodeTours GraphQL server
    uri: 'http://localhost:8080/graphql',
  }),
});

export default () =>
  
    
  ;
github alexedev / scz / lib / initClient.js View on Github external
function createClient (headers) {
  return new ApolloClient({
    ssrMode: !process.browser,
    dataIdFromObject: result => result.id || null,
    networkInterface: createNetworkInterface({
      // open this url in browser to see schema
      uri: 'https://api.graph.cool/simple/v1/cj0n21ce5ffo50118z67ao3th',
      opts: {
        credentials: 'same-origin'
        // Pass headers here if your graphql server requires them
      }
    })
  })
}
github wesbos / Advanced-React / .next / dist / lib / initApollo.js View on Github external
// use the auth0IdToken in localStorage for authorized requests
  networkInterface.use([{
    applyMiddleware: function applyMiddleware(req, next) {
      if (!req.options.headers) {
        req.options.headers = {};
      }

      // get the authentication token from local storage if it exists
      if (typeof localStorage !== 'undefined' && localStorage.getItem("auth0IdToken")) {
        req.options.headers.authorization = 'Bearer ' + localStorage.getItem("auth0IdToken");
      }
      next();
    }
  }]);

  return new _reactApollo.ApolloClient({
    initialState: initialState,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    networkInterface: networkInterface
  });
}
github KATT / next-with-apollo-airbnb-auth0-graphcool / lib / initClient.js View on Github external
applyMiddleware(req, next) {
      if (!req.options.headers) {
        req.options.headers = {}; // eslint-disable-line no-param-reassign
      }

      if (userToken) {
        req.options.headers.authorization = `Bearer ${userToken}`; // eslint-disable-line no-param-reassign
      } else if (req.options.headers.authorization) {
        delete req.options.headers.authorization; // eslint-disable-line no-param-reassign
      }

      next();
    },
  }]);

  return new ApolloClient({
    ssrMode: !process.browser,
    dataIdFromObject: result => result.id || null,
    networkInterface,
  });
}
github sebastian-software / edgestack / src / api / common / Apollo.js View on Github external
{
      networkInterface = createNetworkInterface({
        uri: apolloUri,
        opts
      })
    }

    client = new ApolloClient({
      ssrMode,
      queryDeduplication,
      networkInterface
    })
  }
  else
  {
    client = new ApolloClient({
      ssrMode,
      queryDeduplication
    })
  }

  return client
}
github orbiting / crowdfunding-frontend / lib / initClient.js View on Github external
function createClient (headers) {
  return new ApolloClient({
    ssrMode: !process.browser,
    dataIdFromObject: result => result.id || null,
    queryDeduplication: true,
    fragmentMatcher,
    networkInterface: createNetworkInterface({
      uri: `${API_BASE_URL}/graphql`,
      opts: {
        credentials: 'include',
        headers: {
          Authorization: API_AUTHORIZATION_HEADER,
          cookie: headers.cookie
        }
      }
    })
  })
}