setup custom fetcher and auth hooks

This commit is contained in:
Greg Hoskin
2021-03-27 15:54:32 -06:00
parent 753234dc51
commit ee1d8ed461
37 changed files with 299 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
import { ShopifyConfig } from '../api'
import { SwellConfig } from '../api'
import { CollectionEdge } from '../schema'
import getSiteCollectionsQuery from './queries/get-all-collections-query'
@@ -8,7 +8,7 @@ export type Category = {
path: string
}
const getCategories = async (config: ShopifyConfig): Promise<Category[]> => {
const getCategories = async (config: SwellConfig): Promise<Category[]> => {
const { data } = await config.fetch(getSiteCollectionsQuery, {
variables: {
first: 250,

View File

@@ -1,4 +1,4 @@
import { ShopifyConfig } from '../api'
import { SwellConfig } from '../api'
import fetchAllProducts from '../api/utils/fetch-all-products'
import getAllProductVendors from './queries/get-all-product-vendors-query'
@@ -13,7 +13,7 @@ export type BrandEdge = {
export type Brands = BrandEdge[]
const getVendors = async (config: ShopifyConfig): Promise<BrandEdge[]> => {
const getVendors = async (config: SwellConfig): Promise<BrandEdge[]> => {
const vendors = await fetchAllProducts({
config,
query: getAllProductVendors,

View File

@@ -11,15 +11,16 @@ export async function getAsyncError(res: Response) {
}
const handleFetchResponse = async (res: Response) => {
if (res.ok) {
const { data, errors } = await res.json()
// if (res.ok) {
// const { data, errors } = await res.json()
if (errors && errors.length) {
throw getError(errors, res.status)
}
// if (errors && errors.length) {
// throw getError(errors, res.status)
// }
return data
}
// return data
// }
if (res) return res
throw await getAsyncError(res)
}

View File

@@ -1,4 +1,5 @@
import { Product } from '@commerce/types'
import { Customer } from '@commerce/types'
import {
Product as ShopifyProduct,
@@ -11,7 +12,7 @@ import {
ProductOption,
} from '../schema'
import type { Cart, LineItem } from '../types'
import type { Cart, LineItem, SwellCustomer } from '../types'
const money = ({ amount, currencyCode }: MoneyV2) => {
return {
@@ -121,6 +122,15 @@ export function normalizeCart(checkout: Checkout): Cart {
}
}
export function normalizeCustomer(customer: SwellCustomer): Customer {
const { first_name: firstName, last_name: lastName } = customer
return {
...customer,
firstName,
lastName,
}
}
function normalizeLineItem({
node: { id, title, variant, quantity },
}: CheckoutLineItemEdge): LineItem {