How to use apollo-cache-hermes - 7 common examples

To help you get started, we’ve selected a few apollo-cache-hermes 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 Thorium-Sim / thorium / src / helpers / graphqlClient.js View on Github external
mode: "cors",
        },
      }),
]);

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

const cache = new Hermes({
  entityIdForNode(node) {
    if (node.id && node.__typename && node.count) {
      return node.__typename + node.id + node.count;
    }
    if (node.id && node.__typename) {
      return node.__typename + node.id;
    }
    return null;
  },
});

const client = new ApolloClient({
  link: from([headersMiddleware, link]),
  assumeImmutableResults: true,
  // use restore on the cache instead of initialState
  cache: cache.restore(window.__APOLLO_CLIENT__),
github sync / reason-graphql-demo / src / helpers / initApollo.tsx View on Github external
if (networkError) {
      // eslint-disable-next-line no-console
      console.log(`[Network error]: ${networkError}`);
    }
  });

  const transports = [errorLink, httpLink];
  const allLink: any = ApolloLink.from(transports);

  // 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: allLink,
    cache: new Hermes({
      resolverRedirects: {
        Query: {
          node: ({ id }) => id,
        },
      },
      addTypename: true,
      freeze: true,
    }).restore(initialState || {}),
  });
}
github Thorium-Sim / thorium / client / src / helpers / graphqlClient.js View on Github external
mode: "cors"
        }
      })
]);

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

const cache = new Hermes({
  entityIdForNode(node) {
    if (node.id && node.__typename && node.count) {
      return node.__typename + node.id + node.count;
    }
    if (node.id && node.__typename) {
      return node.__typename + node.id;
    }
    return null;
  }
});

const client = new ApolloClient({
  link: from([headersMiddleware, link]),
  assumeImmutableResults: true,
  // use restore on the cache instead of initialState
  cache: cache.restore(window.__APOLLO_CLIENT__),
github Enalmada / next-reason-boilerplate / util / initApollo.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(link),
        cache: new Hermes().restore(initialState || {}),
    });
}
github apollographql / apollo-cache-persist / src / __tests__ / persistCache.ts View on Github external
xit('extracts a previously filled HermesCache from storage', async () => {
      const [client, client2] = await simulateApp({
        operation,
        result,
        persistOptions: {
          cache: new Hermes(),
        },
      });
      expect(client.extract()).toEqual(client2.extract());
    });
  });
github convoyinc / graphql-client-benchmarks / clients / apollo-hermes.ts View on Github external
constructor() {
    super(new Hermes({ strict: false }));
  }
}

apollo-cache-hermes

A cache implementation for Apollo Client, tuned for performance

Apache-2.0
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis

Popular apollo-cache-hermes functions