How to use the apollo-boost.ApolloClient 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 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 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 hasura / graphql-engine / community / sample-apps / nextjs-8-serverless / with-apollo-jwt / app / lib / init-apollo.js View on Github external
function create (initialState) {
  const authMiddleware = new ApolloLink((operation, forward) => {
    // add the authorization to the headers
    operation.setContext({
      headers: {
        authorization: getToken(),
      }
    })

    return forward(operation);
  })
  const httpLink = new HttpLink({
      uri: 'https://my-app.herokuapp.com/v1/graphql', // Server URL (must be absolute)
      credentials: 'same-origin' // Additional fetch() options like `credentials` or `headers`
  })
  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link: concat(authMiddleware, httpLink),
    cache: new InMemoryCache().restore(initialState || {})
  })
}
github KATT / graphql-workshop / web / lib / init-apollo.js View on Github external
function create(initialState) {
  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link: new HttpLink({
      // TODO - replace with env var
      uri: GRAPHQL_URL, // Server URL (must be absolute)
      credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
    }),
    cache: new InMemoryCache().restore(initialState || {}),
  });
}
github brunocrosier / next-with-apollo-auth / frontend / lib / init-apollo.js View on Github external
uri: process.env.NODE_ENV === "production" ? process.env.BACKEND_URI : "http://localhost:4000",
    credentials: "include",
    fetchOptions
  })
  const authLink = setContext((_, { headers }) => {
    const token = Cookies.get('token')
    return {
      headers: {
        ...headers,
        authorization: token ? `Bearer ${token}` : ''
      }
    }
  })
  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  const isBrowser = typeof window !== 'undefined'
  return new ApolloClient({
    connectToDevTools: isBrowser,
    ssrMode: !isBrowser, // Disables forceFetch on the server (so queries are only run once)
    link: authLink.concat(httpLink),
    cache: new InMemoryCache().restore(initialState || {})
  })
}
export default function initApollo (initialState, options) {
github adamsoffer / next-apollo / src / withData.js View on Github external
function createApolloClient(apolloConfig, initialState = {}) {
  const createCache = apolloConfig.createCache || createDefaultCache

  const config = {
    ssrMode: typeof window === 'undefined', // Disables forceFetch on the server (so queries are only run once)
    cache: createCache().restore(initialState || {}),
    ...apolloConfig
  }

  delete config.createCache

  return new ApolloClient(config)
}
github priley86 / how-to-graphql / frontend / utils / init-apollo.js View on Github external
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
    // Use fetch() polyfill on the server
    fetch: !isBrowser && fetch
  });

  const authLink = setContext((_, { headers }) => {
    const token = getToken && getToken();
    return {
      headers: {
        ...headers,
        authorization: token ? `Bearer ${token}` : ''
      }
    };
  });

  return new ApolloClient({
    connectToDevTools: isBrowser,
    ssrMode: !isBrowser, // Disables forceFetch on the server (so queries are only run once)
    link: authLink.concat(httpLink),
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github Maxvien / next-shopify-storefront / services / apis.service.ts View on Github external
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost';
import 'isomorphic-unfetch';
import config from '../apollo.config';

export const shopify = new ApolloClient({
  ssrMode: true,
  link: new HttpLink({
    uri: config.client.service.url,
    headers: config.client.service.headers
  }),
  cache: new InMemoryCache(),
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'no-cache',
      errorPolicy: 'ignore'
    },
    query: {
      fetchPolicy: 'no-cache',
      errorPolicy: 'all'
    },
    mutate: {
github ian13456 / mine.js / src / index.js View on Github external
}
  }),
  httpLink
)

const authLink = setContext((_, { headers }) => {
  const token = getToken()
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : ''
    }
  }
})

const apolloClient = new ApolloClient({
  connectToDevTools: process.browser,
  ssrMode: !process.browser,
  ssrForceFetchDelay: 100,
  link: authLink.concat(link),
  cache: new InMemoryCache().restore({})
})

const main = (
  
    
      <main>
    
  
)

ReactDOM.render(main, document.getElementById('root'))</main>