How to use the apollo-cache-inmemory function in apollo-cache-inmemory

To help you get started, we’ve selected a few apollo-cache-inmemory 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 okgrow / advanced-graphql / web / src / client.js View on Github external
// http://localhost:8080 is put behind a proxy by webpack (cors)
const uri = '/graphql';

const link = ApolloLink.from([
  errorLink,
  authLink.split(
    hasSubscriptionOperation,
    new WsLink({
      uri: 'ws://localhost:8081/graphql',
      options: { reconnect: true },
    }),
    new HttpLink({ uri })
  ),
]);

const cache = new Cache();

const client = new ApolloClient({
  link,
  cache: cache.restore(window.__APOLLO_STATE__ || {}),
});

export default () => (
  
    
      
    
  
);
github birkir / kvikmyndr-app / src / store / index.js View on Github external
import { ApolloProvider } from 'react-apollo';
import config from '../config';
import UI from './UI';
import Auth from './Auth';

if (__DEV__) { // eslint-disable-line
  const nativeXMLHttpRequest = XMLHttpRequest; // eslint-disable-line
  const devXMLHttpRequest = GLOBAL.originalXMLHttpRequest ? GLOBAL.originalXMLHttpRequest : GLOBAL.XMLHttpRequest; // eslint-disable-line
  GLOBAL.XMLHttpRequest = devXMLHttpRequest;
}

// Create new Apollo client
const link = new Link({
  uri: config.GRAPHQL_ENDPOINT,
});
const cache = new InMemoryCache();
const client = new ApolloClient({
  link,
  cache,
});


export default class Store {
  client = client;
  ui = new UI();
  auth = new Auth();
  
  async setup() {
    return true;
  }
}
github okgrow / advanced-graphql / web / src / server.js View on Github external
app.use(async (req, res) => {
  const context = {};
  const sheet = new ServerStyleSheet();

  try {
    const cache = new Cache();

    const client = new ApolloClient({
      link: new HttpLink({
        uri: `${API_HOST}/graphql`,
      }),
      cache,
    });

    // to be used by react-apollo
    const component = (
github Cerberus / note / src / index.js View on Github external
const link = ApolloLink.split(
  hasSubscriptionOperation,
  new WebSocketLink(
    new SubscriptionClient(process.env.REACT_APP_WEB_SOCKET_URL, {
      reconnect: true,
    }),
  ),
  createHttpLink({
    uri: process.env.REACT_APP_API_URL,
  }),
)

const client = new ApolloClient({
  link,
  cache: new Cache(window.__APOLLO_STATE__),
})

ReactDOM.render(
  
    
  ,
  document.getElementById('root'),
)
registerServiceWorker()

if (module.hot) {
  module.hot.accept()
}
github PCreations / firechat / src / client.js View on Github external
import { ApolloClient } from 'apollo-client';
import InMemoryCache from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { auth } from './firebase';
import { createWebWorkerLink } from 'apollo-link-webworker';

const GraphqlWorker = require('./worker.js');

const worker = new GraphqlWorker();

const webWorkerLink = createWebWorkerLink({ worker });

const dataIdFromObject = result => result.id;

const cache = new InMemoryCache({
  dataIdFromObject,
  connectToDevTools: true,
});

const getAuthContext = () => {
  const authUser = auth.currentUser;
  if (authUser !== null) {
    return {
      auth: {
        uid: authUser.uid,
        credential: window.localStorage.getItem('firechatCredential'),
      },
    };
  }
  return {};
};