How to use the apollo-cache-inmemory.InMemoryCache 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 tomitrescak / apollo-mobx / src / testing / index.tsx View on Github external
loadingComponent
}: ApolloProps) {
  // add crap around mocks
  const finalMocks = {
    ...resolvers,
    Mutation: () => mutations || {},
    Query: () => queries || {},
  };

  const schema = makeExecutableSchema({ typeDefs, resolvers: global.globalResolvers });
  addMockFunctionsToSchema({
    mocks: finalMocks,
    schema,
  });

  const apolloCache = new InMemoryCache(global.__APOLLO_STATE_);

  const spyLink = new SpyLink();
  const graphqlClient: ApolloClient = new ApolloClient({
    cache: apolloCache as any,
    context,
    link: ApolloLink.from([
      spyLink,
      new MockLink({ schema }),
    ]),
    loadingComponent
  });
  graphqlClient.spyLink = spyLink;

  return graphqlClient;
}
github orbiting / publikator-frontend / lib / apollo / initApollo.js View on Github external
? ApolloLink.split(
      hasSubscriptionOperation,
      new WebSocketLink({
        uri: API_WS_URL,
        options: {
          reconnect: true,
          timeout: 50000
        }
      }),
      http
    )
    : http

  return new ApolloClient({
    connectToDevTools: process.browser,
    cache: new InMemoryCache({
      fragmentMatcher,
      dataIdFromObject
    }).restore(initialState || {}),
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    link
  })
}
github hasura / graphql-engine / community / sample-apps / react-apollo-todo / src / apollo.js View on Github external
);

  // chose the link to use based on operation
  const link = split(
    // split based on operation type
    ({ query }) => {
      const { kind, operation } = getMainDefinition(query);
      return kind === "OperationDefinition" && operation === "subscription";
    },
    wsLink,
    httpLink
  );

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

  return client;
};
github kyma-project / console / logging / src / app / app.module.ts View on Github external
},
    });

    const link = split(
      // split based on operation type
      ({ query }) => {
        const definition = getMainDefinition(query);
        return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
      },
      ws,
      http,
    );

    apollo.create({
      link,
      cache: new InMemoryCache(),
    });
  }
}
github ammezie / techies / src / main.js View on Github external
// get the authentication token from localstorage if it exists
  const token = localStorage.getItem('USER_TOKEN')

  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      Authorization: token ? `Bearer ${token}` : ''
    }
  }
})

// Create the apollo client
const apolloClient = new ApolloClient({
  link: httpLinkAuth.concat(httpLink),
  cache: new InMemoryCache()
})

// Install the vue plugin
Vue.use(VueApollo)

const apolloProvider = new VueApollo({
  defaultClient: apolloClient
})

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    localStorage.getItem('USER_TOKEN') ? next() : next('/login')
  } else {
    next()
  }
})
github Seolhun / vue-type-graphql-example / client / src / main.ts View on Github external
Vue.prototype.$http = axios;

Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: "ko",
  fallbackLocale: "en",
  messages,
  silentTranslationWarn: true
});

const link = new HttpLink({
  uri: `http://localhost:4000/graphql`
});
const apolloClient = new ApolloClient({
  link,
  cache: new InMemoryCache(),
  connectToDevTools: true
});
const apolloProvider = new VueApollo({
  defaultClient: apolloClient
});

Vue.use(VueApollo);
Vue.use(BootstrapVue);
new Vue({
  el: "#app",
  router,
  store,
  i18n,
  apolloProvider,
  render: h => h(App)
});
github mirego / ember-boilerplate / app / services / apollo.ts View on Github external
cache() {
    const cache = new InMemoryCache({
      dataIdFromObject,
      freezeResults: false
    });

    const cachedContent = this.shoebox.read(
      config.apollo.SSR_CACHE_KEY
    ) as NormalizedCacheObject;

    if (!cachedContent) return cache;

    return cache.restore(cachedContent);
  }
github nmaro / ooth / packages / ooth-client-react-next-apollo / src / index.tsx View on Github external
});
  if (cookies && Object.keys(cookies).length) {
    const middlewareLink = new ApolloLink((operation, forward) => {
      operation.setContext({
        headers: {
          Cookie: Object.keys(cookies)
            .map((key) => `${key}=${cookies[key]}`)
            .join('; '),
        },
      });
      return forward!(operation);
    });
    link = middlewareLink.concat(link);
  }

  const cache = new InMemoryCache(cacheOpts);
  if (initialData) {
    cache.restore(initialData);
  }

  if (linkState) {
    link = ApolloLink.from([link, linkState]);
  }

  return new ApolloClient({
    link,
    cache,
    ssrMode: true,
    ...opts,
  });
};
github mozilla-frontend-infra / codetribute / src / App / index.jsx View on Github external
} from 'apollo-cache-inmemory';
import { persistCache } from 'apollo-cache-persist';
import { MuiThemeProvider, withStyles } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import storage from 'localforage';
import theme from '../theme';
import FontStager from '../components/FontStager/index';
import ErrorPanel from '../components/ErrorPanel/index';
import routes from './routes';
import introspectionQueryResultData from '../fragmentTypes.json';
import Spinner from '../components/Spinner';

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData,
});
const cache = new InMemoryCache({ fragmentMatcher });

persistCache({
  cache,
  storage,
});

@hot(module)
@withStyles({
  '@global': {
    a: {
      color: theme.palette.secondary.dark,
    },
  },
  spinner: {
    marginTop: 60,
  },