4
0
forked from crowetic/commerce
commerce/framework/swell/fetcher.ts
2021-03-27 16:06:07 -06:00

26 lines
733 B
TypeScript

import { Fetcher } from '@commerce/utils/types'
import { handleFetchResponse } from './utils'
import { swellConfig } from './index'
const fetcher: Fetcher = async ({ method = 'get', variables, query }) => {
const { swell } = swellConfig
async function callSwell() {
if (Array.isArray(variables)) {
const arg1 = variables[0]
const arg2 = variables[1]
const response = await swell[query][method](arg1, arg2)
console.log(response)
return handleFetchResponse(response)
} else {
const response = await swell[query][method](variables)
console.log(response)
return handleFetchResponse(response)
}
}
if (query) {
return await callSwell()
}
}
export default fetcher