feat(saleor): Phase 1 - GraphQL Client Setup
- Add Apollo Client for Saleor GraphQL API - Create GraphQL fragments (Product, Variant, Checkout) - Create GraphQL queries (Products, Checkout) - Create GraphQL mutations (Checkout operations) - Add TypeScript types for Saleor entities - Add product helper functions - Install @apollo/client and graphql dependencies Part of WordPress/WooCommerce → Saleor migration
This commit is contained in:
191
src/types/saleor.ts
Normal file
191
src/types/saleor.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
// Saleor GraphQL Types
|
||||
|
||||
export interface Money {
|
||||
amount: number;
|
||||
currency: string;
|
||||
}
|
||||
|
||||
export interface Price {
|
||||
gross: Money;
|
||||
net?: Money;
|
||||
}
|
||||
|
||||
export interface DiscountedPrice {
|
||||
gross: Money;
|
||||
}
|
||||
|
||||
export interface ProductMedia {
|
||||
id: string;
|
||||
url: string;
|
||||
alt: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface ProductAttributeValue {
|
||||
name: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export interface ProductAttribute {
|
||||
attribute: {
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
values: ProductAttributeValue[];
|
||||
}
|
||||
|
||||
export interface ProductVariantPricing {
|
||||
price: Price;
|
||||
onSale: boolean;
|
||||
discount?: DiscountedPrice;
|
||||
}
|
||||
|
||||
export interface ProductVariant {
|
||||
id: string;
|
||||
name: string;
|
||||
sku: string;
|
||||
quantityAvailable: number;
|
||||
weight?: {
|
||||
value: number;
|
||||
unit: string;
|
||||
};
|
||||
media?: ProductMedia[];
|
||||
pricing?: ProductVariantPricing;
|
||||
attributes?: ProductAttribute[];
|
||||
}
|
||||
|
||||
export interface ProductTranslation {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string;
|
||||
seoTitle?: string;
|
||||
seoDescription?: string;
|
||||
}
|
||||
|
||||
export interface Product {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string;
|
||||
seoTitle?: string;
|
||||
seoDescription?: string;
|
||||
translation?: ProductTranslation;
|
||||
variants: ProductVariant[];
|
||||
media: ProductMedia[];
|
||||
category?: {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
metadata?: {
|
||||
key: string;
|
||||
value: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface ProductEdge {
|
||||
node: Product;
|
||||
}
|
||||
|
||||
export interface ProductList {
|
||||
edges: ProductEdge[];
|
||||
pageInfo: {
|
||||
hasNextPage: boolean;
|
||||
endCursor?: string;
|
||||
};
|
||||
}
|
||||
|
||||
// Checkout Types
|
||||
|
||||
export interface Address {
|
||||
id?: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
companyName?: string;
|
||||
streetAddress1: string;
|
||||
streetAddress2?: string;
|
||||
city: string;
|
||||
postalCode: string;
|
||||
country: {
|
||||
code: string;
|
||||
country: string;
|
||||
};
|
||||
countryArea?: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
export interface CheckoutLine {
|
||||
id: string;
|
||||
quantity: number;
|
||||
totalPrice: Price;
|
||||
variant: ProductVariant & {
|
||||
product: {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
media: ProductMedia[];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface ShippingMethod {
|
||||
id: string;
|
||||
name: string;
|
||||
price: Money;
|
||||
}
|
||||
|
||||
export interface PaymentGateway {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Checkout {
|
||||
id: string;
|
||||
token: string;
|
||||
email?: string;
|
||||
isShippingRequired: boolean;
|
||||
lines: CheckoutLine[];
|
||||
shippingPrice: Price;
|
||||
subtotalPrice: Price;
|
||||
totalPrice: Price;
|
||||
shippingAddress?: Address;
|
||||
billingAddress?: Address;
|
||||
shippingMethods: ShippingMethod[];
|
||||
availablePaymentGateways: PaymentGateway[];
|
||||
note?: string;
|
||||
}
|
||||
|
||||
// Order Types
|
||||
|
||||
export interface Order {
|
||||
id: string;
|
||||
number: string;
|
||||
status: string;
|
||||
created: string;
|
||||
total: Price;
|
||||
}
|
||||
|
||||
// API Response Types
|
||||
|
||||
export interface CheckoutCreateResponse {
|
||||
checkoutCreate: {
|
||||
checkout?: Checkout;
|
||||
errors: Array<{
|
||||
field: string;
|
||||
message: string;
|
||||
code: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface CheckoutCompleteResponse {
|
||||
checkoutComplete: {
|
||||
order?: Order;
|
||||
errors: Array<{
|
||||
field: string;
|
||||
message: string;
|
||||
code: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user