Skip to content

Commit

Permalink
feat(core): Improved handling of ShopAPI activeOrder mutations
Browse files Browse the repository at this point in the history
Relates to #557.

BREAKING CHANGE: The Shop API mutations `setOrderShippingAddress`, `setOrderBillingAddress`
`setOrderCustomFields` now return a union type which includes a new `NoActiveOrderError`.
Code which refers to these mutations will need to be updated to account for the union
with the fragment spread syntax `...on Order {...}`.
  • Loading branch information
michaelbromley committed Dec 23, 2020
1 parent bb1878f commit 958af1a
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 98 deletions.
38 changes: 30 additions & 8 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ export type Mutation = {
/** Transitions an Order to a new state. Valid next states can be found by querying `nextOrderStates` */
transitionOrderToState?: Maybe<TransitionOrderToStateResult>;
/** Sets the shipping address for this order */
setOrderShippingAddress?: Maybe<Order>;
setOrderShippingAddress: ActiveOrderResult;
/** Sets the billing address for this order */
setOrderBillingAddress?: Maybe<Order>;
setOrderBillingAddress: ActiveOrderResult;
/** Allows any custom fields to be set for the active order */
setOrderCustomFields?: Maybe<Order>;
setOrderCustomFields: ActiveOrderResult;
/** Sets the shipping method by id, which can be obtained with the `eligibleShippingMethods` query */
setOrderShippingMethod: SetOrderShippingMethodResult;
/** Add a Payment to the Order */
addPaymentToOrder?: Maybe<AddPaymentToOrderResult>;
addPaymentToOrder: AddPaymentToOrderResult;
/** Set the Customer for the Order. Required only if the Customer is not currently logged in */
setCustomerForOrder?: Maybe<SetCustomerForOrderResult>;
setCustomerForOrder: SetCustomerForOrderResult;
/** Authenticates the user using the native authentication strategy. This mutation is an alias for `authenticate({ native: { ... }})` */
login: NativeAuthenticationResult;
/** Authenticates the user using a named authentication strategy */
Expand Down Expand Up @@ -544,6 +544,7 @@ export enum ErrorCode {
PASSWORD_RESET_TOKEN_INVALID_ERROR = 'PASSWORD_RESET_TOKEN_INVALID_ERROR',
PASSWORD_RESET_TOKEN_EXPIRED_ERROR = 'PASSWORD_RESET_TOKEN_EXPIRED_ERROR',
NOT_VERIFIED_ERROR = 'NOT_VERIFIED_ERROR',
NO_ACTIVE_ORDER_ERROR = 'NO_ACTIVE_ORDER_ERROR',
}

export enum LogicalOperator {
Expand Down Expand Up @@ -2448,6 +2449,16 @@ export type NotVerifiedError = ErrorResult & {
message: Scalars['String'];
};

/**
* Returned when invoking a mutation which depends on there being an active Order on the
* current session.
*/
export type NoActiveOrderError = ErrorResult & {
__typename?: 'NoActiveOrderError';
errorCode: ErrorCode;
message: Scalars['String'];
};

export type RegisterCustomerInput = {
emailAddress: Scalars['String'];
title?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -2486,7 +2497,11 @@ export type UpdateOrderItemsResult =

export type RemoveOrderItemsResult = Order | OrderModificationError;

export type SetOrderShippingMethodResult = Order | OrderModificationError | IneligibleShippingMethodError;
export type SetOrderShippingMethodResult =
| Order
| OrderModificationError
| IneligibleShippingMethodError
| NoActiveOrderError;

export type ApplyCouponCodeResult =
| Order
Expand All @@ -2499,11 +2514,16 @@ export type AddPaymentToOrderResult =
| OrderPaymentStateError
| PaymentFailedError
| PaymentDeclinedError
| OrderStateTransitionError;
| OrderStateTransitionError
| NoActiveOrderError;

export type TransitionOrderToStateResult = Order | OrderStateTransitionError;

export type SetCustomerForOrderResult = Order | AlreadyLoggedInError | EmailAddressConflictError;
export type SetCustomerForOrderResult =
| Order
| AlreadyLoggedInError
| EmailAddressConflictError
| NoActiveOrderError;

export type RegisterCustomerAccountResult = Success | MissingPasswordError | NativeAuthStrategyError;

Expand Down Expand Up @@ -2547,6 +2567,8 @@ export type NativeAuthenticationResult =

export type AuthenticationResult = CurrentUser | InvalidCredentialsError | NotVerifiedError;

export type ActiveOrderResult = Order | NoActiveOrderError;

export type CollectionListOptions = {
skip?: Maybe<Scalars['Int']>;
take?: Maybe<Scalars['Int']>;
Expand Down
142 changes: 95 additions & 47 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ export type Mutation = {
/** Transitions an Order to a new state. Valid next states can be found by querying `nextOrderStates` */
transitionOrderToState?: Maybe<TransitionOrderToStateResult>;
/** Sets the shipping address for this order */
setOrderShippingAddress?: Maybe<Order>;
setOrderShippingAddress: ActiveOrderResult;
/** Sets the billing address for this order */
setOrderBillingAddress?: Maybe<Order>;
setOrderBillingAddress: ActiveOrderResult;
/** Allows any custom fields to be set for the active order */
setOrderCustomFields?: Maybe<Order>;
setOrderCustomFields: ActiveOrderResult;
/** Sets the shipping method by id, which can be obtained with the `eligibleShippingMethods` query */
setOrderShippingMethod: SetOrderShippingMethodResult;
/** Add a Payment to the Order */
addPaymentToOrder?: Maybe<AddPaymentToOrderResult>;
addPaymentToOrder: AddPaymentToOrderResult;
/** Set the Customer for the Order. Required only if the Customer is not currently logged in */
setCustomerForOrder?: Maybe<SetCustomerForOrderResult>;
setCustomerForOrder: SetCustomerForOrderResult;
/** Authenticates the user using the native authentication strategy. This mutation is an alias for `authenticate({ native: { ... }})` */
login: NativeAuthenticationResult;
/** Authenticates the user using a named authentication strategy */
Expand Down Expand Up @@ -530,6 +530,7 @@ export enum ErrorCode {
PASSWORD_RESET_TOKEN_INVALID_ERROR = 'PASSWORD_RESET_TOKEN_INVALID_ERROR',
PASSWORD_RESET_TOKEN_EXPIRED_ERROR = 'PASSWORD_RESET_TOKEN_EXPIRED_ERROR',
NOT_VERIFIED_ERROR = 'NOT_VERIFIED_ERROR',
NO_ACTIVE_ORDER_ERROR = 'NO_ACTIVE_ORDER_ERROR',
}

export enum LogicalOperator {
Expand Down Expand Up @@ -2339,6 +2340,15 @@ export type NotVerifiedError = ErrorResult & {
message: Scalars['String'];
};

/**
* Returned when invoking a mutation which depends on there being an active Order on the
* current session.
*/
export type NoActiveOrderError = ErrorResult & {
errorCode: ErrorCode;
message: Scalars['String'];
};

export type RegisterCustomerInput = {
emailAddress: Scalars['String'];
title?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -2377,7 +2387,11 @@ export type UpdateOrderItemsResult =

export type RemoveOrderItemsResult = Order | OrderModificationError;

export type SetOrderShippingMethodResult = Order | OrderModificationError | IneligibleShippingMethodError;
export type SetOrderShippingMethodResult =
| Order
| OrderModificationError
| IneligibleShippingMethodError
| NoActiveOrderError;

export type ApplyCouponCodeResult =
| Order
Expand All @@ -2390,11 +2404,16 @@ export type AddPaymentToOrderResult =
| OrderPaymentStateError
| PaymentFailedError
| PaymentDeclinedError
| OrderStateTransitionError;
| OrderStateTransitionError
| NoActiveOrderError;

export type TransitionOrderToStateResult = Order | OrderStateTransitionError;

export type SetCustomerForOrderResult = Order | AlreadyLoggedInError | EmailAddressConflictError;
export type SetCustomerForOrderResult =
| Order
| AlreadyLoggedInError
| EmailAddressConflictError
| NoActiveOrderError;

export type RegisterCustomerAccountResult = Success | MissingPasswordError | NativeAuthStrategyError;

Expand Down Expand Up @@ -2438,6 +2457,8 @@ export type NativeAuthenticationResult =

export type AuthenticationResult = CurrentUser | InvalidCredentialsError | NotVerifiedError;

export type ActiveOrderResult = Order | NoActiveOrderError;

export type CollectionListOptions = {
skip?: Maybe<Scalars['Int']>;
take?: Maybe<Scalars['Int']>;
Expand Down Expand Up @@ -2899,7 +2920,8 @@ export type SetShippingMethodMutation = {
setOrderShippingMethod:
| TestOrderFragmentFragment
| Pick<OrderModificationError, 'errorCode' | 'message'>
| Pick<IneligibleShippingMethodError, 'errorCode' | 'message'>;
| Pick<IneligibleShippingMethodError, 'errorCode' | 'message'>
| Pick<NoActiveOrderError, 'errorCode' | 'message'>;
};

export type ActiveOrderCustomerFragment = Pick<Order, 'id'> & {
Expand All @@ -2912,11 +2934,11 @@ export type SetCustomerForOrderMutationVariables = Exact<{
}>;

export type SetCustomerForOrderMutation = {
setCustomerForOrder?: Maybe<
setCustomerForOrder:
| ActiveOrderCustomerFragment
| Pick<AlreadyLoggedInError, 'errorCode' | 'message'>
| Pick<EmailAddressConflictError, 'errorCode' | 'message'>
>;
| Pick<NoActiveOrderError, 'errorCode' | 'message'>;
};

export type GetOrderByCodeQueryVariables = Exact<{
Expand Down Expand Up @@ -2956,45 +2978,49 @@ export type SetShippingAddressMutationVariables = Exact<{
}>;

export type SetShippingAddressMutation = {
setOrderShippingAddress?: Maybe<{
shippingAddress?: Maybe<
Pick<
OrderAddress,
| 'fullName'
| 'company'
| 'streetLine1'
| 'streetLine2'
| 'city'
| 'province'
| 'postalCode'
| 'country'
| 'phoneNumber'
>
>;
}>;
setOrderShippingAddress:
| {
shippingAddress?: Maybe<
Pick<
OrderAddress,
| 'fullName'
| 'company'
| 'streetLine1'
| 'streetLine2'
| 'city'
| 'province'
| 'postalCode'
| 'country'
| 'phoneNumber'
>
>;
}
| Pick<NoActiveOrderError, 'errorCode' | 'message'>;
};

export type SetBillingAddressMutationVariables = Exact<{
input: CreateAddressInput;
}>;

export type SetBillingAddressMutation = {
setOrderBillingAddress?: Maybe<{
billingAddress?: Maybe<
Pick<
OrderAddress,
| 'fullName'
| 'company'
| 'streetLine1'
| 'streetLine2'
| 'city'
| 'province'
| 'postalCode'
| 'country'
| 'phoneNumber'
>
>;
}>;
setOrderBillingAddress:
| {
billingAddress?: Maybe<
Pick<
OrderAddress,
| 'fullName'
| 'company'
| 'streetLine1'
| 'streetLine2'
| 'city'
| 'province'
| 'postalCode'
| 'country'
| 'phoneNumber'
>
>;
}
| Pick<NoActiveOrderError, 'errorCode' | 'message'>;
};

export type TestOrderWithPaymentsFragment = {
Expand All @@ -3012,13 +3038,13 @@ export type AddPaymentToOrderMutationVariables = Exact<{
}>;

export type AddPaymentToOrderMutation = {
addPaymentToOrder?: Maybe<
addPaymentToOrder:
| TestOrderWithPaymentsFragment
| Pick<OrderPaymentStateError, 'errorCode' | 'message'>
| Pick<PaymentFailedError, 'errorCode' | 'message' | 'paymentErrorMessage'>
| Pick<PaymentDeclinedError, 'errorCode' | 'message' | 'paymentErrorMessage'>
| Pick<OrderStateTransitionError, 'errorCode' | 'message' | 'transitionError'>
>;
| Pick<NoActiveOrderError, 'errorCode' | 'message'>;
};

export type GetActiveOrderPaymentsQueryVariables = Exact<{ [key: string]: never }>;
Expand Down Expand Up @@ -3450,17 +3476,39 @@ export namespace SetShippingAddress {
export type Variables = SetShippingAddressMutationVariables;
export type Mutation = SetShippingAddressMutation;
export type SetOrderShippingAddress = NonNullable<SetShippingAddressMutation['setOrderShippingAddress']>;
export type OrderInlineFragment = DiscriminateUnion<
NonNullable<SetShippingAddressMutation['setOrderShippingAddress']>,
{ __typename?: 'Order' }
>;
export type ShippingAddress = NonNullable<
NonNullable<SetShippingAddressMutation['setOrderShippingAddress']>['shippingAddress']
DiscriminateUnion<
NonNullable<SetShippingAddressMutation['setOrderShippingAddress']>,
{ __typename?: 'Order' }
>['shippingAddress']
>;
export type ErrorResultInlineFragment = DiscriminateUnion<
NonNullable<SetShippingAddressMutation['setOrderShippingAddress']>,
{ __typename?: 'ErrorResult' }
>;
}

export namespace SetBillingAddress {
export type Variables = SetBillingAddressMutationVariables;
export type Mutation = SetBillingAddressMutation;
export type SetOrderBillingAddress = NonNullable<SetBillingAddressMutation['setOrderBillingAddress']>;
export type OrderInlineFragment = DiscriminateUnion<
NonNullable<SetBillingAddressMutation['setOrderBillingAddress']>,
{ __typename?: 'Order' }
>;
export type BillingAddress = NonNullable<
NonNullable<SetBillingAddressMutation['setOrderBillingAddress']>['billingAddress']
DiscriminateUnion<
NonNullable<SetBillingAddressMutation['setOrderBillingAddress']>,
{ __typename?: 'Order' }
>['billingAddress']
>;
export type ErrorResultInlineFragment = DiscriminateUnion<
NonNullable<SetBillingAddressMutation['setOrderBillingAddress']>,
{ __typename?: 'ErrorResult' }
>;
}

Expand Down
Loading

0 comments on commit 958af1a

Please sign in to comment.