Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update cache after shop mutations

dominik-zeglen49f94aa2a12c
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index db8169fd40..4dc72a51a2 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -209,11 +209,13 @@ type AuthorizationKey {
type AuthorizationKeyAdd {
errors: [Error]
authorizationKey: AuthorizationKey
+ shop: Shop
}
type AuthorizationKeyDelete {
errors: [Error]
authorizationKey: AuthorizationKey
+ shop: Shop
}
input AuthorizationKeyInput {
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 9fec85239f..715e1af381 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -1,6 +1,6 @@
import CssBaseline from "@material-ui/core/CssBaseline";
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
-import { InMemoryCache } from "apollo-cache-inmemory";
+import { defaultDataIdFromObject, InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient, ApolloError } from "apollo-client";
import { setContext } from "apollo-link-context";
import { ErrorResponse, onError } from "apollo-link-error";
@@ -68,7 +68,14 @@ const uploadLink = createUploadLink({
});
const apolloClient = new ApolloClient({
- cache: new InMemoryCache(),
+ cache: new InMemoryCache({
+ dataIdFromObject: (obj: any) => {
+ if (obj.__typename === "Shop") {
+ return "shop";
+ }
+ return defaultDataIdFromObject(obj);
+ }
+ }),
link: invalidTokenLink.concat(authLink.concat(uploadLink))
});
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx
index 2d78db06e1..6bc4af271e 100644
--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx
@@ -18,13 +18,14 @@ import {
renderCollection,
translatedAuthorizationKeyTypes
} from "../../../misc";
+import { AuthorizationKeyType } from "../../../types/globalTypes";
import { SiteSettings_shop_authorizationKeys } from "../../types/SiteSettings";
interface SiteSettingsKeysProps {
disabled: boolean;
keys: SiteSettings_shop_authorizationKeys[];
onAdd: () => void;
- onRemove: (name: string) => void;
+ onRemove: (name: AuthorizationKeyType) => void;
}
const decorate = withStyles(theme => ({
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
index f1741fa7e7..2e704039fa 100644
--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
@@ -8,6 +8,7 @@ import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
+import { AuthorizationKeyType } from "../../../types/globalTypes";
import { SiteSettings_shop } from "../../types/SiteSettings";
import SiteSettingsDetails from "../SiteSettingsDetails/SiteSettingsDetails";
import SiteSettingsKeys from "../SiteSettingsKeys/SiteSettingsKeys";
@@ -22,7 +23,7 @@ export interface SiteSettingsPageProps {
disabled: boolean;
shop: SiteSettings_shop;
onKeyAdd: () => void;
- onKeyRemove: (name: string) => void;
+ onKeyRemove: (keyType: AuthorizationKeyType) => void;
onSubmit: (data: SiteSettingsPageFormData) => void;
}
diff --git a/saleor/static/dashboard-next/siteSettings/mutations.ts b/saleor/static/dashboard-next/siteSettings/mutations.ts
index b5682c1da6..31b531d852 100644
--- a/saleor/static/dashboard-next/siteSettings/mutations.ts
+++ b/saleor/static/dashboard-next/siteSettings/mutations.ts
@@ -6,12 +6,17 @@ import {
AuthorizationKeyAdd,
AuthorizationKeyAddVariables
} from "./types/AuthorizationKeyAdd";
+import {
+ AuthorizationKeyDelete,
+ AuthorizationKeyDeleteVariables
+} from "./types/AuthorizationKeyDelete";
import {
ShopSettingsUpdate,
ShopSettingsUpdateVariables
} from "./types/ShopSettingsUpdate";
const authorizationKeyAdd = gql`
+ ${shopFragment}
mutation AuthorizationKeyAdd(
$input: AuthorizationKeyInput!
$keyType: AuthorizationKeyType!
@@ -21,6 +26,9 @@ const authorizationKeyAdd = gql`
field
message
}
+ shop {
+ ...ShopFragment
+ }
}
}
`;
@@ -29,6 +37,25 @@ export const TypedAuthorizationKeyAdd = TypedMutation<
AuthorizationKeyAddVariables
>(authorizationKeyAdd);
+const authorizationKeyDelete = gql`
+ ${shopFragment}
+ mutation AuthorizationKeyDelete($keyType: AuthorizationKeyType!) {
+ authorizationKeyDelete(keyType: $keyType) {
+ errors {
+ field
+ message
+ }
+ shop {
+ ...ShopFragment
+ }
+ }
+ }
+`;
+export const TypedAuthorizationKeyDelete = TypedMutation<
+ AuthorizationKeyDelete,
+ AuthorizationKeyDeleteVariables
+>(authorizationKeyDelete);
+
const shopSettingsUpdate = gql`
${shopFragment}
mutation ShopSettingsUpdate(
diff --git a/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyAdd.ts b/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyAdd.ts
index d0b092c9d0..ffcf0a0390 100644
--- a/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyAdd.ts
+++ b/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyAdd.ts
@@ -13,9 +13,29 @@ export interface AuthorizationKeyAdd_authorizationKeyAdd_errors {
message: string | null;
}
+export interface AuthorizationKeyAdd_authorizationKeyAdd_shop_authorizationKeys {
+ __typename: "AuthorizationKey";
+ key: string;
+ name: AuthorizationKeyType;
+}
+
+export interface AuthorizationKeyAdd_authorizationKeyAdd_shop_domain {
+ __typename: "Domain";
+ host: string;
+}
+
+export interface AuthorizationKeyAdd_authorizationKeyAdd_shop {
+ __typename: "Shop";
+ authorizationKeys: (AuthorizationKeyAdd_authorizationKeyAdd_shop_authorizationKeys | null)[];
+ description: string | null;
+ domain: AuthorizationKeyAdd_authorizationKeyAdd_shop_domain;
+ name: string;
+}
+
export interface AuthorizationKeyAdd_authorizationKeyAdd {
__typename: "AuthorizationKeyAdd";
errors: (AuthorizationKeyAdd_authorizationKeyAdd_errors | null)[] | null;
+ shop: AuthorizationKeyAdd_authorizationKeyAdd_shop | null;
}
export interface AuthorizationKeyAdd {
diff --git a/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyDelete.ts b/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyDelete.ts
new file mode 100644
index 0000000000..8a6f95ec6d
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/types/AuthorizationKeyDelete.ts
@@ -0,0 +1,47 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { AuthorizationKeyType } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: AuthorizationKeyDelete
+// ====================================================
+
+export interface AuthorizationKeyDelete_authorizationKeyDelete_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface AuthorizationKeyDelete_authorizationKeyDelete_shop_authorizationKeys {
+ __typename: "AuthorizationKey";
+ key: string;
+ name: AuthorizationKeyType;
+}
+
+export interface AuthorizationKeyDelete_authorizationKeyDelete_shop_domain {
+ __typename: "Domain";
+ host: string;
+}
+
+export interface AuthorizationKeyDelete_authorizationKeyDelete_shop {
+ __typename: "Shop";
+ authorizationKeys: (AuthorizationKeyDelete_authorizationKeyDelete_shop_authorizationKeys | null)[];
+ description: string | null;
+ domain: AuthorizationKeyDelete_authorizationKeyDelete_shop_domain;
+ name: string;
+}
+
+export interface AuthorizationKeyDelete_authorizationKeyDelete {
+ __typename: "AuthorizationKeyDelete";
+ errors: (AuthorizationKeyDelete_authorizationKeyDelete_errors | null)[] | null;
+ shop: AuthorizationKeyDelete_authorizationKeyDelete_shop | null;
+}
+
+export interface AuthorizationKeyDelete {
+ authorizationKeyDelete: AuthorizationKeyDelete_authorizationKeyDelete | null;
+}
+
+export interface AuthorizationKeyDeleteVariables {
+ keyType: AuthorizationKeyType;
+}
diff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsx
index 7e68791e03..2fed4d2eca 100644
--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx
+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx
@@ -6,84 +6,100 @@ import { AuthorizationKeyType } from "../../types/globalTypes";
import SiteSettingsKeyDialog, {
SiteSettingsKeyDialogForm
} from "../components/SiteSettingsKeyDialog";
-import SiteSettingsPage, {SiteSettingsPageFormData} from "../components/SiteSettingsPage";
+import SiteSettingsPage, {
+ SiteSettingsPageFormData
+} from "../components/SiteSettingsPage";
import {
TypedAuthorizationKeyAdd,
+ TypedAuthorizationKeyDelete,
TypedShopSettingsUpdate
} from "../mutations";
import { TypedSiteSettingsQuery } from "../queries";
export const SiteSettings: React.StatelessComponent<{}> = () => (
- <TypedSiteSettingsQuery>
- {siteSettings => (
- <TypedAuthorizationKeyAdd>
- {(addAuthorizationKey, addAuthorizationKeyOpts) => (
- <TypedShopSettingsUpdate>
- {(updateShopSettings, updateShopSettingsOpts) => {
- const loading =
- siteSettings.loading ||
- addAuthorizationKeyOpts.loading ||
- updateShopSettingsOpts.loading;
+ <Toggle>
+ {(openedAddKeyDialog, { toggle: toggleAddKeyDialog }) => {
+ return (
+ <TypedSiteSettingsQuery>
+ {siteSettings => (
+ <TypedAuthorizationKeyAdd>
+ {(addAuthorizationKey, addAuthorizationKeyOpts) => (
+ <TypedAuthorizationKeyDelete>
+ {(deleteAuthorizationKey, _) => (
+ <TypedShopSettingsUpdate>
+ {(updateShopSettings, updateShopSettingsOpts) => {
+ const loading =
+ siteSettings.loading ||
+ addAuthorizationKeyOpts.loading ||
+ updateShopSettingsOpts.loading;
- const handleAuthenticationKeyAdd = (
- data: SiteSettingsKeyDialogForm
- ) =>
- addAuthorizationKey({
- variables: {
- input: {
- key: data.key,
- password: data.password
- },
- keyType: data.type
- }
- });
- const handleUpdateShopSettings = (data: SiteSettingsPageFormData) => updateShopSettings({
- variables: {
- shopDomainInput: {
- domain: data.domain
- },
- shopSettingsInput: {
- description: data.description,
- headerText: data.name
- }
- }
- })
- return (
- <Toggle>
- {(openedAddKeyDialog, { toggle: toggleAddKeyDialog }) => (
- <>
- <SiteSettingsPage
- disabled={loading}
- shop={maybe(() => siteSettings.data.shop)}
- onKeyAdd={toggleAddKeyDialog}
- onKeyRemove={() => undefined}
- onSubmit={handleUpdateShopSettings}
- />
- <SiteSettingsKeyDialog
- errors={maybe(
- () =>
- addAuthorizationKeyOpts.data.authorizationKeyAdd
- .errors,
- []
- )}
- initial={{
- key: "",
- password: "",
- type: AuthorizationKeyType.FACEBOOK
- }}
- open={openedAddKeyDialog}
- onClose={toggleAddKeyDialog}
- onSubmit={handleAuthenticationKeyAdd}
- />
- </>
+ const handleAuthenticationKeyAdd = (
+ data: SiteSettingsKeyDialogForm
+ ) =>
+ addAuthorizationKey({
+ variables: {
+ input: {
+ key: data.key,
+ password: data.password
+ },
+ keyType: data.type
+ }
+ });
+ const handleUpdateShopSettings = (
+ data: SiteSettingsPageFormData
+ ) =>
+ updateShopSettings({
+ variables: {
+ shopDomainInput: {
+ domain: data.domain
+ },
+ shopSettingsInput: {
+ description: data.description,
+ headerText: data.name
+ }
+ }
+ });
+ return (
+ <>
+ <SiteSettingsPage
+ disabled={loading}
+ shop={maybe(() => siteSettings.data.shop)}
+ onKeyAdd={toggleAddKeyDialog}
+ onKeyRemove={keyType =>
+ deleteAuthorizationKey({
+ variables: { keyType }
+ })
+ }
+ onSubmit={handleUpdateShopSettings}
+ />
+ <SiteSettingsKeyDialog
+ errors={maybe(
+ () =>
+ addAuthorizationKeyOpts.data
+ .authorizationKeyAdd.errors,
+ []
+ )}
+ initial={{
+ key: "",
+ password: "",
+ type: AuthorizationKeyType.FACEBOOK
+ }}
+ open={openedAddKeyDialog}
+ onClose={toggleAddKeyDialog}
+ onSubmit={handleAuthenticationKeyAdd}
+ />
+ </>
+ );
+ }}
+ </TypedShopSettingsUpdate>
)}
- </Toggle>
- );
- }}
- </TypedShopSettingsUpdate>
- )}
- </TypedAuthorizationKeyAdd>
- )}
- </TypedSiteSettingsQuery>
+ </TypedAuthorizationKeyDelete>
+ )}
+ </TypedAuthorizationKeyAdd>
+ )}
+ </TypedSiteSettingsQuery>
+ );
+ }}
+ </Toggle>
);
export default SiteSettings;