Fix build errors

This commit is contained in:
cond0r
2021-05-13 16:10:09 +03:00
parent e7d0f56e85
commit bff94e73ae
22 changed files with 87 additions and 458 deletions

View File

@@ -1,22 +1,27 @@
import { Fetcher } from '@commerce/utils/types'
import { handleFetchResponse } from './utils'
import { swellConfig } from './index'
import { CommerceError } from '@commerce/utils/errors'
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)
const response = await swell[query!][method](arg1, arg2)
return handleFetchResponse(response)
} else {
const response = await swell[query][method](variables)
const response = await swell[query!][method](variables)
return handleFetchResponse(response)
}
}
if (query in swell) {
if (query && query in swell) {
return await callSwell()
} else {
throw new CommerceError({ message: 'Invalid query argument!' })
}
}