mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
* TEC-252: Base integration with commercetools using fetchers for REST and GraphQL endpoints * TEC-252: WIP commenting some components that are failing while we don't have all the hooks defined * add sdk integration * TEC-256: Implementing product search * TEC-256: removing unnecessary env variables * TEC-256: review comments * TEC-256: other remaining review fixes Co-authored-by: nicossosa93 <nicolas.sosa@devgurus.io>
38 lines
881 B
TypeScript
38 lines
881 B
TypeScript
import { FetcherError } from '@commerce/utils/errors'
|
|
import type { GraphQLFetcher } from '@commerce/api'
|
|
import Commercetools from '@framework/utils/commercetools'
|
|
import { provider } from '@framework/api'
|
|
|
|
const fetchGraphqlApi: GraphQLFetcher = async (
|
|
query: string,
|
|
{ variables } = {}
|
|
) => {
|
|
const { config } = provider
|
|
const commercetools = Commercetools({
|
|
clientId: config.clientId,
|
|
clientSecret: config.clientSecret,
|
|
projectKey: config.projectKey,
|
|
host: config.host,
|
|
oauthHost: config.oauthHost,
|
|
concurrency: config.concurrency,
|
|
})
|
|
const { requestExecute } = commercetools
|
|
try {
|
|
const result = await requestExecute
|
|
.graphql()
|
|
.post({
|
|
body: {
|
|
query,
|
|
variables,
|
|
},
|
|
})
|
|
.execute()
|
|
|
|
return result.body
|
|
} catch (err) {
|
|
throw err
|
|
}
|
|
}
|
|
|
|
export default fetchGraphqlApi
|