commerce/framework/commercetools/api/utils/fetch-graphql-api.ts
matias-delavega-dg-dmi 716b540966
TEC-252 and TEC-256: Implementing fetchers, products list and search (#5)
* 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>
2021-06-30 10:05:26 -03:00

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