2020-07-07 10:14:12 +00:00
|
|
|
import { fragmentAddress } from "@saleor/fragments/address";
|
|
|
|
import {
|
|
|
|
customerAddressesFragment,
|
|
|
|
customerDetailsFragment
|
|
|
|
} from "@saleor/fragments/customers";
|
|
|
|
import { accountErrorFragment } from "@saleor/fragments/errors";
|
2019-06-19 14:40:52 +00:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
|
|
|
|
import { TypedMutation } from "../mutations";
|
|
|
|
import {
|
|
|
|
BulkRemoveCustomers,
|
|
|
|
BulkRemoveCustomersVariables
|
|
|
|
} from "./types/BulkRemoveCustomers";
|
|
|
|
import {
|
|
|
|
CreateCustomer,
|
|
|
|
CreateCustomerVariables
|
|
|
|
} from "./types/CreateCustomer";
|
|
|
|
import {
|
|
|
|
CreateCustomerAddress,
|
|
|
|
CreateCustomerAddressVariables
|
|
|
|
} from "./types/CreateCustomerAddress";
|
|
|
|
import {
|
|
|
|
RemoveCustomer,
|
|
|
|
RemoveCustomerVariables
|
|
|
|
} from "./types/RemoveCustomer";
|
|
|
|
import {
|
|
|
|
RemoveCustomerAddress,
|
|
|
|
RemoveCustomerAddressVariables
|
|
|
|
} from "./types/RemoveCustomerAddress";
|
|
|
|
import {
|
|
|
|
SetCustomerDefaultAddress,
|
|
|
|
SetCustomerDefaultAddressVariables
|
|
|
|
} from "./types/SetCustomerDefaultAddress";
|
|
|
|
import {
|
|
|
|
UpdateCustomer,
|
|
|
|
UpdateCustomerVariables
|
|
|
|
} from "./types/UpdateCustomer";
|
|
|
|
import {
|
|
|
|
UpdateCustomerAddress,
|
|
|
|
UpdateCustomerAddressVariables
|
|
|
|
} from "./types/UpdateCustomerAddress";
|
|
|
|
|
|
|
|
const updateCustomer = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
${customerDetailsFragment}
|
|
|
|
mutation UpdateCustomer($id: ID!, $input: CustomerInput!) {
|
|
|
|
customerUpdate(id: $id, input: $input) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
user {
|
|
|
|
...CustomerDetailsFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedUpdateCustomerMutation = TypedMutation<
|
|
|
|
UpdateCustomer,
|
|
|
|
UpdateCustomerVariables
|
|
|
|
>(updateCustomer);
|
|
|
|
|
|
|
|
const createCustomer = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CreateCustomer($input: UserCreateInput!) {
|
|
|
|
customerCreate(input: $input) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
user {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedCreateCustomerMutation = TypedMutation<
|
|
|
|
CreateCustomer,
|
|
|
|
CreateCustomerVariables
|
|
|
|
>(createCustomer);
|
|
|
|
|
|
|
|
const removeCustomer = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation RemoveCustomer($id: ID!) {
|
|
|
|
customerDelete(id: $id) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedRemoveCustomerMutation = TypedMutation<
|
|
|
|
RemoveCustomer,
|
|
|
|
RemoveCustomerVariables
|
|
|
|
>(removeCustomer);
|
|
|
|
|
|
|
|
const setCustomerDefaultAddress = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
${customerAddressesFragment}
|
|
|
|
mutation SetCustomerDefaultAddress(
|
|
|
|
$addressId: ID!
|
|
|
|
$userId: ID!
|
|
|
|
$type: AddressTypeEnum!
|
|
|
|
) {
|
|
|
|
addressSetDefault(addressId: $addressId, userId: $userId, type: $type) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
user {
|
|
|
|
...CustomerAddressesFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedSetCustomerDefaultAddressMutation = TypedMutation<
|
|
|
|
SetCustomerDefaultAddress,
|
|
|
|
SetCustomerDefaultAddressVariables
|
|
|
|
>(setCustomerDefaultAddress);
|
|
|
|
|
|
|
|
const createCustomerAddress = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
${customerAddressesFragment}
|
|
|
|
${fragmentAddress}
|
|
|
|
mutation CreateCustomerAddress($id: ID!, $input: AddressInput!) {
|
|
|
|
addressCreate(userId: $id, input: $input) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
address {
|
|
|
|
...AddressFragment
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
...CustomerAddressesFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedCreateCustomerAddressMutation = TypedMutation<
|
|
|
|
CreateCustomerAddress,
|
|
|
|
CreateCustomerAddressVariables
|
|
|
|
>(createCustomerAddress);
|
|
|
|
|
|
|
|
const updateCustomerAddress = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
${fragmentAddress}
|
|
|
|
mutation UpdateCustomerAddress($id: ID!, $input: AddressInput!) {
|
|
|
|
addressUpdate(id: $id, input: $input) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
address {
|
|
|
|
...AddressFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedUpdateCustomerAddressMutation = TypedMutation<
|
|
|
|
UpdateCustomerAddress,
|
|
|
|
UpdateCustomerAddressVariables
|
|
|
|
>(updateCustomerAddress);
|
|
|
|
|
|
|
|
const removeCustomerAddress = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
${customerAddressesFragment}
|
|
|
|
mutation RemoveCustomerAddress($id: ID!) {
|
|
|
|
addressDelete(id: $id) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
user {
|
|
|
|
...CustomerAddressesFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedRemoveCustomerAddressMutation = TypedMutation<
|
|
|
|
RemoveCustomerAddress,
|
|
|
|
RemoveCustomerAddressVariables
|
|
|
|
>(removeCustomerAddress);
|
|
|
|
|
|
|
|
export const bulkRemoveCustomers = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation BulkRemoveCustomers($ids: [ID]!) {
|
|
|
|
customerBulkDelete(ids: $ids) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedBulkRemoveCustomers = TypedMutation<
|
|
|
|
BulkRemoveCustomers,
|
|
|
|
BulkRemoveCustomersVariables
|
|
|
|
>(bulkRemoveCustomers);
|