4
0
forked from crowetic/commerce
commerce/framework/swell/fetcher.ts
2021-04-04 14:45:48 -06:00

26 lines
804 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]
// console.log('fetcher', query, method, variables);
const response = await swell[query][method](arg1, arg2)
return handleFetchResponse(response)
} else {
// console.log('fetcher', query, method, variables);
const response = await swell[query][method](variables)
return handleFetchResponse(response)
}
}
if (query in swell) {
return await callSwell()
}
}
export default fetcher