How to use the apollo-client-preset.InMemoryCache function in apollo-client-preset

To help you get started, we’ve selected a few apollo-client-preset 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 graphql-boilerplates / react-fullstack-graphql / advanced / src / index.js View on Github external
})

const link = split(
  // split based on operation type
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query)
    return kind === 'OperationDefinition' && operation === 'subscription'
  },
  wsLink,
  httpLinkAuth,
)

// apollo client setup
const client = new ApolloClient({
  link: ApolloLink.from([link]),
  cache: new InMemoryCache(),
  connectToDevTools: true,
})

const token = localStorage.getItem(AUTH_TOKEN)

ReactDOM.render(
  
    
  ,
  document.getElementById('root'),
)
github realm / my-first-realm-app / react-qbs / src / App / index.tsx View on Github external
});
    // Combine the links in a way that splits based on the operation
    const link = split(
      ({ query }) => {
        const definition = getMainDefinition(query);
        return (
          definition.kind === "OperationDefinition" &&
          definition.operation === "subscription"
        );
      },
      webSocketLink,
      httpLink,
    );
    // Create a client with the combined links
    return new ApolloClient({
      cache: new InMemoryCache(),
      link,
    });
  }
github ahmedlhanafy / guchub / src / utils / setupApollo.js View on Github external
/* @flow */

import { AsyncStorage, Platform } from 'react-native';
import { ApolloClient } from 'apollo-client';
import { HttpLink, InMemoryCache, ApolloLink } from 'apollo-client-preset';
import { CachePersistor } from 'apollo-cache-persist';
import { generateClientStateLink, getSchemaVersion, saveSchemaVersion } from './';
import packageJson from '../../package.json';

const currentSchemaVersion = packageJson.schema_version;

const cache = new InMemoryCache();

const persistor = new CachePersistor({
  cache,
  storage: AsyncStorage,
  trigger: Platform.OS === 'web' ? 'write' : 'background',
});

export default async () => {
  const cacheSchemaVersion = (await getSchemaVersion()) || 0;
  if (currentSchemaVersion === cacheSchemaVersion) {
    await persistor.restore();
  } else {
    await persistor.purge();
    await saveSchemaVersion(currentSchemaVersion);
  }
github arkhn / pyrog / client-v2 / src / app.tsx View on Github external
}
if (process.env.CLEANING_SCRIPTS_URI) {
  links.push(
    new RestLink({
      uri: process.env.CLEANING_SCRIPTS_URI + "/",
      headers: {
        "Content-Type": "application/json"
      }
    })
  );
}
links.push(httpLinkAuth);

// Client
export const client = new ApolloClient({
  cache: new InMemoryCache(),
  connectToDevTools: true,
  link: ApolloLink.from(links)
});

ReactDOM.render(
  
    
      
        
      
    
  ,
  document.getElementById("application-wrapper") ||
    document.createElement("div")
);
github marmelab / react-admin / packages / ra-data-graphql / src / buildApolloClient.js View on Github external
// Create an empty fragment matcher
    // See: https://github.com/apollographql/apollo-client/issues/3397#issuecomment-421433032
    const fragmentMatcher = new IntrospectionFragmentMatcher({
        introspectionQueryResultData: {
            __schema: {
                types: [],
            },
        },
    });

    if (!link && uri) {
        finalLink = new HttpLink({ uri });
    }

    if (!cache) {
        finalCache = new InMemoryCache({ fragmentMatcher }).restore({});
    }

    return new ApolloClient({
        link: finalLink,
        cache: finalCache,
        ...otherOptions,
    });
};
github arkhn / pyrog / client / src / app.tsx View on Github external
}
if (process.env.CLEANING_SCRIPTS_URI) {
  links.push(
    new RestLink({
      uri: process.env.CLEANING_SCRIPTS_URI + "/",
      headers: {
        "Content-Type": "application/json"
      }
    })
  );
}
links.push(coreLink);

// Client
export const client = new ApolloClient({
  cache: new InMemoryCache(),
  connectToDevTools: true,
  link: ApolloLink.from(links)
});

ReactDOM.render(
  
    
      
    
  ,
  document.getElementById("application-wrapper") ||
    document.createElement("div")
);
github Weakky / prisma-ecommerce / mobile / src / graphql / setupApollo.js View on Github external
);

  const httpLinkWithAuth = authMiddleware.concat(httpLink);

  const link = split(
    ({ query }) => {
      const { kind, operation } = getMainDefinition(query);
      return kind === 'OperationDefinition' && operation === 'subscription';
    },
    wsLink,
    httpLinkWithAuth,
  );

  const client = new ApolloClient({
    link,
    cache: new InMemoryCache({ dataIdFromObject: o => o.id }),
    connectToDevTools: true,
  });

  return client;
}
github xiaoyunyang / react-native-travel-app / App.js View on Github external
import React, { Component } from 'react';

import { ApolloProvider } from 'react-apollo';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-client-preset';

import AppContainer from './src/AppContainer';

import ListPage from './src/components/ListPage';

const simpleApi = 'https://api.graph.cool/simple/v1/cjrh62bkka7l501132k2sp85b';
const httpLink = new HttpLink({ uri: simpleApi });

const client = new ApolloClient({
  link: httpLink,
  cache: new InMemoryCache(),
});
export default class App extends Component {
  render() {
    return (
      
        
      
    );
  }
}
github prisma-labs / graphql-yoga / examples / fullstack / frontend / src / index.js View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import registerServiceWorker from './registerServiceWorker'
import { ApolloProvider } from 'react-apollo'
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-client-preset'

const httpLink = new HttpLink({ uri: 'http://localhost:4000' })

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

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