Skip to content

Commit

Permalink
feat(cart)!: type magento driver queries (#2551)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `MagentoMergeCartResponse` -> `MagentoMergeCartsResponse`
  • Loading branch information
griest024 committed Aug 23, 2023
1 parent e9ff895 commit 4889b40
Show file tree
Hide file tree
Showing 116 changed files with 360 additions and 163 deletions.
4 changes: 1 addition & 3 deletions libs/cart/driver/magento/src/cart-billing-address.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import {
getBillingAddress,
updateBillingAddress,
updateBillingAddressWithEmail,
} from './queries/public_api';
import {
MagentoGetBillingAddressResponse,
MagentoUpdateBillingAddressResponse,
MagentoUpdateBillingAddressWithEmailResponse,
} from './queries/responses/public_api';
} from './queries/public_api';
import { DaffMagentoBillingAddressInputTransformer } from './transforms/inputs/billing-address.service';
import { DaffMagentoBillingAddressTransformer } from './transforms/outputs/billing-address.service';
import { DaffMagentoCartTransformer } from './transforms/outputs/cart.service';
Expand Down
4 changes: 1 addition & 3 deletions libs/cart/driver/magento/src/cart-coupon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import {
listCartCoupons,
applyCoupon,
removeAllCoupons,
} from './queries/public_api';
import {
MagentoListCartCouponsResponse,
MagentoApplyCouponResponse,
MagentoRemoveAllCouponsResponse,
} from './queries/responses/public_api';
} from './queries/public_api';
import { daffMagentoCouponTransform } from './transforms/outputs/cart-coupon';
import { DaffMagentoCartTransformer } from './transforms/outputs/cart.service';

Expand Down
10 changes: 5 additions & 5 deletions libs/cart/driver/magento/src/cart-item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ import {
} from './injection-tokens/public_api';
import { DaffCartMagentoCartItemTransform } from './interfaces/public_api';
import { MagentoCartItemInput } from './models/requests/cart-item';
import { addCartItem } from './queries/add-cart-item';
import {
MagentoAddCartItemResponse,
MagentoListCartItemsResponse,
MagentoRemoveCartItemResponse,
addCartItem,
listCartItems,
removeCartItem,
updateCartItem,
} from './queries/public_api';
import { MagentoAddCartItemResponse } from './queries/responses/add-cart-item';
import { MagentoListCartItemsResponse } from './queries/responses/list-cart-items';
import { MagentoUpdateCartItemResponse } from './queries/responses/public_api';
import { MagentoRemoveCartItemResponse } from './queries/responses/remove-cart-item';
import { MagentoUpdateCartItemResponse } from './queries/public_api';
import {
transformCompositeCartItem,
transformSimpleCartItem,
Expand Down
6 changes: 4 additions & 2 deletions libs/cart/driver/magento/src/cart-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import { DaffQueuedApollo } from '@daffodil/core/graphql';

import { transformCartMagentoError } from './errors/transform';
import { DAFF_MAGENTO_CART_MUTATION_QUEUE } from './injection-tokens/cart-mutation-queue.token';
import { placeOrder } from './queries/public_api';
import { MagentoPlaceOrderResponse } from './queries/responses/public_api';
import {
placeOrder,
MagentoPlaceOrderResponse,
} from './queries/public_api';

/**
* A service for making Magento GraphQL queries for carts.
Expand Down
6 changes: 4 additions & 2 deletions libs/cart/driver/magento/src/cart-payment-methods.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import { DaffCartPaymentMethodsServiceInterface } from '@daffodil/cart/driver';

import { transformCartMagentoError } from './errors/transform';
import { DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS } from './injection-tokens/public_api';
import { listPaymentMethods } from './queries/public_api';
import { MagentoListPaymentMethodsResponse } from './queries/responses/list-payment-methods';
import {
listPaymentMethods,
MagentoListPaymentMethodsResponse,
} from './queries/public_api';
import { DaffMagentoCartPaymentTransformer } from './transforms/outputs/cart-payment.service';

/**
Expand Down
4 changes: 1 addition & 3 deletions libs/cart/driver/magento/src/cart-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ import {
setSelectedPaymentMethod,
setSelectedPaymentMethodWithBilling,
setSelectedPaymentMethodWithBillingAndEmail,
} from './queries/public_api';
import {
MagentoGetSelectedPaymentMethodResponse,
MagentoSetSelectedPaymentMethodResponse,
MagentoSetSelectedPaymentMethodWithBillingResponse,
MagentoSetSelectedPaymentMethodWithBillingAndEmailResponse,
} from './queries/responses/public_api';
} from './queries/public_api';
import { DaffMagentoBillingAddressInputTransformer } from './transforms/inputs/billing-address.service';
import { DaffMagentoPaymentMethodInputTransformer } from './transforms/inputs/payment-method.service';
import { DaffMagentoCartPaymentTransformer } from './transforms/outputs/cart-payment.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import {
getShippingAddress,
updateShippingAddress,
updateShippingAddressWithEmail,
} from './queries/public_api';
import {
MagentoGetShippingAddressResponse,
MagentoUpdateShippingAddressResponse,
MagentoUpdateShippingAddressWithEmailResponse,
} from './queries/responses/public_api';
} from './queries/public_api';
import { DaffMagentoShippingAddressInputTransformer } from './transforms/inputs/shipping-address.service';
import { DaffMagentoCartTransformer } from './transforms/outputs/cart.service';
import { DaffMagentoShippingAddressTransformer } from './transforms/outputs/shipping-address.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import {
getSelectedShippingMethod,
setSelectedShippingMethod,
listShippingMethods,
} from './queries/public_api';
import {
MagentoGetSelectedShippingMethodResponse,
MagentoSetSelectedShippingMethodResponse,
MagentoListShippingMethodsResponse,
} from './queries/responses/public_api';
} from './queries/public_api';
import { DaffMagentoShippingMethodInputTransformer } from './transforms/inputs/shipping-method.service';
import { DaffMagentoCartShippingRateTransformer } from './transforms/outputs/cart-shipping-rate.service';
import { DaffMagentoCartTransformer } from './transforms/outputs/cart.service';
Expand Down
6 changes: 4 additions & 2 deletions libs/cart/driver/magento/src/cart-shipping-methods.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import { DaffCartShippingMethodsServiceInterface } from '@daffodil/cart/driver';

import { transformCartMagentoError } from './errors/transform';
import { DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS } from './injection-tokens/public_api';
import { listShippingMethods } from './queries/public_api';
import { MagentoListShippingMethodsResponse } from './queries/responses/list-shipping-methods';
import {
listShippingMethods,
MagentoListShippingMethodsResponse,
} from './queries/public_api';
import { DaffMagentoCartShippingRateTransformer } from './transforms/outputs/cart-shipping-rate.service';

/**
Expand Down
4 changes: 2 additions & 2 deletions libs/cart/driver/magento/src/cart.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
createCart,
getCart,
magentoMergeCartsMutation,
MagentoMergeCartResponse,
MagentoMergeCartsResponse,
} from '@daffodil/cart/driver/magento';
import {
MagentoCartFactory,
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('@daffodil/cart/driver/magento | DaffMagentoCartService', () => {
let mockDaffCartItem: DaffCartItem;
let mockCartResponse: MagentoGetCartResponse;
let mockCreateCartResponse: MagentoCreateCartResponse;
let mockMergeCartsResponse: MagentoMergeCartResponse;
let mockMergeCartsResponse: MagentoMergeCartsResponse;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
12 changes: 4 additions & 8 deletions libs/cart/driver/magento/src/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ import {
Injectable,
Inject,
} from '@angular/core';
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';
import { DocumentNode } from 'graphql';
import {
Observable,
throwError,
forkJoin,
of,
merge,
} from 'rxjs';
import {
map,
switchMap,
catchError,
tap,
} from 'rxjs/operators';

import {
Expand All @@ -30,7 +27,6 @@ import {
DaffCartItemServiceInterface,
DaffProductOutOfStockError,
} from '@daffodil/cart/driver';
import { DaffInheritableError } from '@daffodil/core';
import { DaffQueuedApollo } from '@daffodil/core/graphql';
import { DaffDriverResponse } from '@daffodil/driver';

Expand All @@ -44,10 +40,10 @@ import {
getCart,
createCart,
magentoMergeCartsMutation,
MagentoMergeCartResponse,
MagentoMergeCartsResponse,
MagentoCreateCartResponse,
MagentoGetCartResponse,
} from './queries/public_api';
import { MagentoCreateCartResponse } from './queries/responses/create-cart';
import { MagentoGetCartResponse } from './queries/responses/get-cart';
import { DaffMagentoCartTransformer } from './transforms/outputs/cart.service';

export const DAFF_MAGENTO_GET_RECOVERABLE_ERRORS = [
Expand Down Expand Up @@ -126,7 +122,7 @@ export class DaffMagentoCartService implements DaffCartServiceInterface<DaffCart
}

merge(guestCart: DaffCart['id'], customerCart?: DaffCart['id']): Observable<DaffDriverResponse<DaffCart>> {
return this.mutationQueue.mutate<MagentoMergeCartResponse>({
return this.mutationQueue.mutate<MagentoMergeCartsResponse>({
mutation: magentoMergeCartsMutation(this.extraCartFragments),
variables: {
source: guestCart,
Expand Down
3 changes: 3 additions & 0 deletions libs/cart/driver/magento/src/queries/add-item/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
import {
cartFragment,
magentoCartUserError,
} from './fragments/public_api';
} from '../fragments/public_api';
import { MagentoAddCartItemResponse } from './response.type';
import { MagentoCartAddItemQueryVariables } from './variables.type';

export const addCartItem = (extraCartFragments: DocumentNode[] = []) => gql`
export const addCartItem = (extraCartFragments: DocumentNode[] = []) => gql<MagentoAddCartItemResponse, MagentoCartAddItemQueryVariables>`
mutation MagentoAddCartItem($cartId: String!, $input: CartItemInput!) {
addProductsToCart(
cartId: $cartId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MagentoCartUserInputError } from '../../models/public_api';
import { MagentoGetCartResponse } from './get-cart';
import { MagentoGetCartResponse } from '../get-cart/public_api';

interface Response extends MagentoGetCartResponse {
user_errors: MagentoCartUserInputError[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { MagentoCartItemInput } from '../../models/public_api';

export interface MagentoCartAddItemQueryVariables {
cartId: string;
input: MagentoCartItemInput;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { cartFragment } from './fragments/public_api';
import { cartFragment } from '../fragments/public_api';
import { MagentoApplyCouponResponse } from './response.type';
import { MagentoCartApplyCouponQueryVariables } from './variables.type';

export const applyCoupon = (extraCartFragments: DocumentNode[] = []) => gql`
export const applyCoupon = (extraCartFragments: DocumentNode[] = []) => gql<MagentoApplyCouponResponse, MagentoCartApplyCouponQueryVariables>`
mutation MagentoApplyCoupon($cartId: String!, $couponCode: String!) {
applyCouponToCart(
input: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface MagentoCartApplyCouponQueryVariables {
cartId: string;
couponCode: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { gql } from 'apollo-angular';


export const createCart = gql`
mutation MagentoCreateCart {
createEmptyCart
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface MagentoCartCreateCartQueryVariables {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { cartAddressFragment } from './fragments/public_api';
import { cartAddressFragment } from '../fragments/public_api';
import { MagentoGetBillingAddressResponse } from './response.type';
import { MagentoCartGetBillingAddressQueryVariables } from './variables.type';

export const getBillingAddress = (extraCartFragments: DocumentNode[] = []) => gql`
export const getBillingAddress = (extraCartFragments: DocumentNode[] = []) => gql<MagentoGetBillingAddressResponse, MagentoCartGetBillingAddressQueryVariables>`
query MagentoGetBillingAddress($cartId: String!) {
cart(cart_id: $cartId) {
billing_address {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface MagentoCartGetBillingAddressQueryVariables {
cartId: string;
}
3 changes: 3 additions & 0 deletions libs/cart/driver/magento/src/queries/get-cart/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { cartFragment } from './fragments/public_api';
import { cartFragment } from '../fragments/public_api';
import { MagentoGetCartResponse } from './response.type';
import { MagentoCartGetQueryVariables } from './variables.type';

export const getCart = (extraCartFragments: DocumentNode[] = []) => gql`
export const getCart = (extraCartFragments: DocumentNode[] = []) => gql<MagentoGetCartResponse, MagentoCartGetQueryVariables>`
query MagentoGetCart($cartId: String!) {
cart(cart_id: $cartId) {
...cart
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface MagentoCartGetQueryVariables {
cartId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { selectedPaymentMethodFragment } from './fragments/public_api';
import { selectedPaymentMethodFragment } from '../fragments/public_api';
import { MagentoGetSelectedPaymentMethodResponse } from './response.type';
import { MagentoCartGetSelectedPaymentMethodQueryVariables } from './variables.type';

export const getSelectedPaymentMethod = (extraCartFragments: DocumentNode[] = []) => gql`
export const getSelectedPaymentMethod = (extraCartFragments: DocumentNode[] = []) => gql<MagentoGetSelectedPaymentMethodResponse, MagentoCartGetSelectedPaymentMethodQueryVariables>`
query MagentoGetSelectedPaymentMethod($cartId: String!) {
cart(cart_id: $cartId) {
selected_payment_method {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface MagentoCartGetSelectedPaymentMethodQueryVariables {
cartId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { selectedShippingMethodFragment } from './fragments/public_api';
import { selectedShippingMethodFragment } from '../fragments/public_api';
import { MagentoGetSelectedShippingMethodResponse } from './response.type';
import { MagentoCartGetSelectedShippingMethodQueryVariables } from './variables.type';

export const getSelectedShippingMethod = (extraCartFragments: DocumentNode[] = []) => gql`
export const getSelectedShippingMethod = (extraCartFragments: DocumentNode[] = []) => gql<MagentoGetSelectedShippingMethodResponse, MagentoCartGetSelectedShippingMethodQueryVariables>`
query MagentoGetSelectedShippingMethod($cartId: String!) {
cart(cart_id: $cartId) {
shipping_addresses {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface MagentoCartGetSelectedShippingMethodQueryVariables {
cartId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { cartAddressFragment } from './fragments/public_api';
import { cartAddressFragment } from '../fragments/public_api';
import { MagentoGetShippingAddressResponse } from './response.type';
import { MagentoCartGetShippingAddressQueryVariables } from './variables.type';

export const getShippingAddress = (extraCartFragments: DocumentNode[] = []) => gql`
export const getShippingAddress = (extraCartFragments: DocumentNode[] = []) => gql<MagentoGetShippingAddressResponse, MagentoCartGetShippingAddressQueryVariables>`
query MagentoGetShippingAddress($cartId: String!) {
cart(cart_id: $cartId) {
shipping_addresses {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface MagentoCartGetShippingAddressQueryVariables {
cartId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './query';
export * from './variables.type';
export * from './response.type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
daffBuildFragmentDefinition,
} from '@daffodil/core/graphql';

import { cartCouponFragment } from './fragments/public_api';
import { cartCouponFragment } from '../fragments/public_api';
import { MagentoListCartCouponsResponse } from './response.type';
import { MagentoCartListCouponsQueryVariables } from './variables.type';

export const listCartCoupons = (extraCartFragments: DocumentNode[] = []) => gql`
export const listCartCoupons = (extraCartFragments: DocumentNode[] = []) => gql<MagentoListCartCouponsResponse, MagentoCartListCouponsQueryVariables>`
query MagentoListCartCoupons($cartId: String!) {
cart(cart_id: $cartId) {
applied_coupons {
Expand Down
Loading

0 comments on commit 4889b40

Please sign in to comment.