How to use the apollo-boost.HttpLink function in apollo-boost

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 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 Answart / next-store / client / lib / init-apollo.js View on Github external
function createApolloClient(initialState, options) {
  if (!!options.getHeaders) headers = options.getHeaders();
  const data = !!initialState && (typeof initialState.cartOpen != 'undefined')
    ? initialState
    : {
        cartOpen: false,
        me: null,
      };
  const cache = new InMemoryCache().restore(data);
  const client = new ApolloClient({
    connectToDevTools: !!process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    fetch,
    link: new HttpLink({
      uri,
      credentials: 'include',
      headers,
      request: operation => {
        operation.setContext({
          fetchOptions: {
            credentials: 'include',
          },
          headers,
        });
      },
    }),
    cache,
    resolvers: {
      Mutation: {
        toggleCart: (_, variables, { cache }) => {
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)
  });
}
github nice-boys / product-boilerplate / web / components / WithApollo / client.ts View on Github external
function create(
  initialState?: NormalizedCacheObject,
  cookie?: string,
  host?: string
) {
  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link: new HttpLink({
      uri: `${host || ""}/api/graphql`,
      credentials: "include",
      headers: cookie && {
        Cookie: cookie
      }
    }),
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github hanford / trends / packages / www / helpers / init-apollo.tsx View on Github external
function create(host: string, initialState: NormalizedCacheObject | null) {
  const url =
    process.env.NODE_ENV === "production"
      ? `https://${host}`
      : "http://localhost:2999";

  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link: new HttpLink({
      uri: `${url}/api/graphql`,
      credentials: "same-origin"
    }),
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github artsmia / lume / app / apollo / OldIndex.js View on Github external
function create(initialState) {
  const httpLink = new HttpLink({
    uri: process.env.API_URL
  })

  const cache = new InMemoryCache().restore(initialState || {})

  const stateLink = withClientState({
    resolvers,
    defaults,
    typeDefs,
    cache
  })

  const authLink = setContext(async (req, prevCtx) => {
    try {
      let authHeaders = {}
      if (process.browser) {
github ZolaApp / zola-app / src / higherOrders / withApolloClient / initApollo.js View on Github external
const create = (initialState: any) =>
  new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser,
    link: new HttpLink({
      uri: process.env.API_URL,
      credentials: 'same-origin',
      fetch
    }),
    cache: new InMemoryCache().restore(initialState || {})
  })
github ohbarye / goofi / helpers / initApollo.ts View on Github external
function create(initialState, nowUrl) {
  const url = process.env.api ? process.env.api : nowUrl;

  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser,
    link: new HttpLink({
      uri: `${url}/api/graphql`,
      credentials: "same-origin"
    }),
    cache: new InMemoryCache().restore(initialState || {})
  });
}