Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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__),
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 || {}),
});
}
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__),
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 || {}),
});
}
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());
});
});
constructor() {
super(new Hermes({ strict: true }));
}
}
constructor() {
super(new Hermes({ strict: false }));
}
}