How to use the apollo-boost.InMemoryCache 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 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 microsoft / vscode-pull-request-github / src / github / credentials.ts View on Github external
if (version === '') {
			// use default github.com schema
			schema = defaultSchema;
		} else {
			schema = enterpriseSchema;
		}

		let graphQLBaseURL = baseUrl;
		if (graphQLBaseURL.endsWith('/api/v3')) {
			// handles github enterprise
			graphQLBaseURL = baseUrl.replace('/v3', '');
		}

		const graphql = new ApolloClient({
			link: link(graphQLBaseURL, creds.token || ''),
			cache: new InMemoryCache,
			defaultOptions: {
				query: {
					fetchPolicy: 'no-cache'
				}
			}
		});

		return {
			octokit,
			graphql,
			schema: schema,
		};
	}
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 DennisKo / perseus / packages / www / 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({
      uri:
        process.env.NODE_ENV === "production"
          ? "/api"
          : "http://localhost:4000/api", // Server URL (must be absolute)
      credentials: "same-origin" // Additional fetch() options like `credentials` or `headers`
    }),
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github alexvcasillas / react-forum-system / frontend / lib / init-apollo.js View on Github external
const authLink = setContext((_, { headers }) => {
    const token = getToken();
    return {
      headers: {
        ...headers,
        authorization: token ? `Bearer ${token}` : '',
      },
    };
  });

  // 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: authLink.concat(httpLink),
    cache: new InMemoryCache().restore(initialState || {}),
  });
}
github open-app / app-hub-mobile / src / utils / ApolloWrapper.js View on Github external
async function getApolloClient() {
  const cache = new InMemoryCache()
  const persistor = new CachePersistor({
    cache,
    storage: AsyncStorage,
    trigger: 'background',
  })
  try {
    const currentVersion = await AsyncStorage.getItem(SCHEMA_VERSION_KEY)
    if (currentVersion === SCHEMA_VERSION) {
      console.log('Restoring cache')
      await persistor.restore()
    } else {
      console.log('Creating cache')
      await persistor.purge()
      await AsyncStorage.setItem(SCHEMA_VERSION_KEY, SCHEMA_VERSION)
    }
  } catch (error) {
github bcgov / devhub-app-web / app-web / wrapWithProvider.js View on Github external
limitations under the License.

Created by Patrick Simonian
*/

import React from 'react';
import { ThemeProvider } from 'emotion-theming';
import { AuthProvider } from './src/AuthContext';
import theme from './theme';
import { ApolloClient, InMemoryCache } from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
import { createHttpLink } from 'apollo-link-http';
import fetch from 'unfetch';
import { SEARCHGATE_API_URL } from './src/constants/api';

const cache = new InMemoryCache();
//this needs to be an enviroment variable later on......
export const client = new ApolloClient({
  link: createHttpLink({
    uri: SEARCHGATE_API_URL,
    fetch: fetch,
  }),
  cache,
});

export default ({ element }) => (
  
    
      {element}
    
  
);
github titan-suite / ide-alpha / src / index.tsx View on Github external
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { ApolloClient, InMemoryCache } from 'apollo-boost'
import { ApolloProvider } from 'react-apollo'
import { createHttpLink } from 'apollo-link-http'
import Index from './pages/index'

const link = createHttpLink({
  uri: 'http://localhost:4000/'
})

const client = new ApolloClient({
  connectToDevTools: true,
  link,
  cache: new InMemoryCache()
})

const WrappedApp = (
  
    
  
)

ReactDOM.render(WrappedApp, document.querySelector('#root'))
github MoonHighway / learning-graphql / chapter-07 / photo-share-client / src / index.js View on Github external
import React from 'react'
import { render } from 'react-dom'
import App from './App'
import { ApolloProvider } from 'react-apollo'
import { 
    InMemoryCache, 
    ApolloLink,
    ApolloClient,
    split
} from 'apollo-boost'
import { WebSocketLink } from 'apollo-link-ws'
import { getMainDefinition } from 'apollo-utilities'
import { persistCache } from 'apollo-cache-persist'
import { createUploadLink } from 'apollo-upload-client'

const cache = new InMemoryCache()
persistCache({
    cache,
    storage: localStorage
})

if (localStorage['apollo-cache-persist']) {
    let cacheData = JSON.parse(localStorage['apollo-cache-persist'])
    cache.restore(cacheData)
}


const httpLink = createUploadLink({ uri: 'http://localhost:4000/graphql' })
const authLink = new ApolloLink((operation, forward) => {
    operation.setContext(context => ({
        headers: {
            ...context.headers,