remove graphQL fetcher

This commit is contained in:
DuvCharles 2022-11-29 15:58:55 +01:00
parent 96a8c54e21
commit 61592ee3e9
2 changed files with 3 additions and 36 deletions

View File

@ -8,7 +8,7 @@ import getCustomerWishlist from './operations/get-customer-wishlist'
import getAllProductPaths from './operations/get-all-product-paths'
import getAllProducts from './operations/get-all-products'
import getProduct from './operations/get-product'
import fetchLocal from './utils/fetch-local'
import fetchRestApi from './utils/fetch-local'
export interface SyliusConfig extends CommerceAPIConfig {
fetch: any
@ -19,7 +19,7 @@ const config: SyliusConfig = {
cartCookie: '',
customerCookie: '',
cartCookieMaxAge: 2592000,
fetch: fetchLocal.fetchRestApi,
fetch: fetchRestApi,
}
const operations = {

View File

@ -1,36 +1,3 @@
import { FetcherError } from '@vercel/commerce/utils/errors'
import type { GraphQLFetcher } from '@vercel/commerce/api'
import type { SyliusConfig } from '../index'
import fetch from './fetch'
const fetchGraphqlApi: (getConfig: () => SyliusConfig) => GraphQLFetcher =
(getConfig) =>
async (query: string, { variables, preview } = {}, fetchOptions) => {
const config = getConfig()
const res = await fetch(config.commerceUrl, {
...fetchOptions,
method: 'POST',
headers: {
...fetchOptions?.headers,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
variables,
}),
})
const json = await res.json()
if (json.errors) {
throw new FetcherError({
errors: json.errors ?? [{ message: 'Failed to fetch for API' }],
status: res.status,
})
}
return { data: json.data, res }
}
export const fetchRestApi = async <T>(
method: string,
path: string,
@ -51,4 +18,4 @@ export const fetchRestApi = async <T>(
return jsonResponse as T
}
export default { fetchGraphqlApi, fetchRestApi }
export default fetchRestApi