Skip to content

Commit

Permalink
fix: update apollo configs to always use cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jun 3, 2019
1 parent 219da7c commit 853ec00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/webiny-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webiny-cli",
"version": "2.2.3",
"version": "2.2.4",
"main": "index.js",
"bin": {
"webiny": "./lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,17 @@ import { InMemoryCache } from "apollo-cache-inmemory";
import { createAuthLink } from "webiny-app-security/components";
import { createOmitTypenameLink } from "webiny-app/graphql";

let config;
const isProduction = process.env.NODE_ENV === "production";
const uriPrefix = isProduction ? "" : process.env.REACT_APP_FUNCTIONS_HOST;

const cache = new InMemoryCache({
addTypename: true,
dataIdFromObject: obj => obj.id || null
export default new ApolloClient({
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: uriPrefix + "/function/api" })
]),
cache: new InMemoryCache({
addTypename: true,
dataIdFromObject: obj => obj.id || null
})
});

if (process.env.NODE_ENV === "production") {
config = {
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: "/function/api" })
]),
cache
};
}

if (process.env.NODE_ENV === "development") {
config = {
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: process.env.REACT_APP_FUNCTIONS_HOST + "/function/api" })
]),
cache,
defaultOptions: {
watchQuery: {
fetchPolicy: "network-only",
errorPolicy: "all"
},
query: {
fetchPolicy: "network-only",
errorPolicy: "all"
}
}
};
}

export default new ApolloClient(config);
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,24 @@ import { InMemoryCache } from "apollo-cache-inmemory";
import { createAuthLink } from "webiny-app-security/components";
import { createOmitTypenameLink } from "webiny-app/graphql";

let config;
const isProduction = process.env.NODE_ENV === "production";
const uriPrefix = isProduction ? "" : process.env.REACT_APP_FUNCTIONS_HOST;

const cache = new InMemoryCache({
addTypename: true,
dataIdFromObject: obj => obj.id || null
});

if (process.env.NODE_ENV === "production") {
if (isProduction && process.env.REACT_APP_ENV === "browser") {
// Production build of this app will be rendered using SSR so we need to restore cache from pre-rendered state.
if (process.env.REACT_APP_ENV === "browser") {
cache.restore(window.__APOLLO_STATE__);
}

config = {
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: "/function/api" })
]),
cache
};
}

if (process.env.NODE_ENV === "development") {
config = {
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: process.env.REACT_APP_FUNCTIONS_HOST + "/function/api" })
]),
cache,
defaultOptions: {
watchQuery: {
fetchPolicy: "network-only",
errorPolicy: "all"
},
query: {
fetchPolicy: "network-only",
errorPolicy: "all"
}
}
};
cache.restore(window.__APOLLO_STATE__);
}

export default new ApolloClient(config);
export default new ApolloClient({
link: ApolloLink.from([
createOmitTypenameLink(),
createAuthLink(),
new BatchHttpLink({ uri: uriPrefix + "/function/api" })
]),
cache
});

0 comments on commit 853ec00

Please sign in to comment.