mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
remove graphQL fetcher
This commit is contained in:
parent
96a8c54e21
commit
61592ee3e9
@ -8,7 +8,7 @@ import getCustomerWishlist from './operations/get-customer-wishlist'
|
|||||||
import getAllProductPaths from './operations/get-all-product-paths'
|
import getAllProductPaths from './operations/get-all-product-paths'
|
||||||
import getAllProducts from './operations/get-all-products'
|
import getAllProducts from './operations/get-all-products'
|
||||||
import getProduct from './operations/get-product'
|
import getProduct from './operations/get-product'
|
||||||
import fetchLocal from './utils/fetch-local'
|
import fetchRestApi from './utils/fetch-local'
|
||||||
|
|
||||||
export interface SyliusConfig extends CommerceAPIConfig {
|
export interface SyliusConfig extends CommerceAPIConfig {
|
||||||
fetch: any
|
fetch: any
|
||||||
@ -19,7 +19,7 @@ const config: SyliusConfig = {
|
|||||||
cartCookie: '',
|
cartCookie: '',
|
||||||
customerCookie: '',
|
customerCookie: '',
|
||||||
cartCookieMaxAge: 2592000,
|
cartCookieMaxAge: 2592000,
|
||||||
fetch: fetchLocal.fetchRestApi,
|
fetch: fetchRestApi,
|
||||||
}
|
}
|
||||||
|
|
||||||
const operations = {
|
const operations = {
|
||||||
|
@ -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>(
|
export const fetchRestApi = async <T>(
|
||||||
method: string,
|
method: string,
|
||||||
path: string,
|
path: string,
|
||||||
@ -51,4 +18,4 @@ export const fetchRestApi = async <T>(
|
|||||||
return jsonResponse as T
|
return jsonResponse as T
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { fetchGraphqlApi, fetchRestApi }
|
export default fetchRestApi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user