-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commerce): add Cart module and addToCart method
- Loading branch information
1 parent
0340d9e
commit 6822da4
Showing
7 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ClientType } from '../../../index'; | ||
import { ADD_TO_CART_MUTATION } from '../../../mutations'; | ||
import { CartItemData, CartItemInput } from '../../../types/commerce'; | ||
|
||
export class Cart { | ||
constructor(protected client: ClientType) {} | ||
|
||
public async addToCart(input: CartItemInput): Promise<CartItemData> { | ||
const response = await this.client.mutate({ | ||
mutation: ADD_TO_CART_MUTATION, | ||
variables: { input }, | ||
}); | ||
|
||
return response.data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./cart" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { gql } from '@apollo/client/core'; | ||
|
||
export const ADD_TO_CART_MUTATION = gql` | ||
mutation($input: [CartItemInput!]!) { | ||
addToCart(items: $input) { | ||
id | ||
name | ||
price | ||
quantity | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface CartItemInput { | ||
input: { | ||
quantity: number; | ||
variant_id: number; | ||
}[]; | ||
} | ||
|
||
export interface CartItemData { | ||
data: { | ||
addToCart: { | ||
id: number; | ||
name: string; | ||
price: number; | ||
quantity: number; | ||
}[]; | ||
}; | ||
} |