replace customer query with viewer

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-03-31 17:43:42 +04:00
parent 8d68add81d
commit 49bd38fd82
5 changed files with 32 additions and 23 deletions

View File

@@ -1,20 +1,19 @@
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
import { Customer } from '@commerce/types'
import { SWRHook } from '@commerce/utils/types'
import { getCustomerQuery, getCustomerToken } from '../utils'
import { viewerQuery } from '../utils'
export default useCustomer as UseCustomer<typeof handler>
export const handler: SWRHook<Customer | null> = {
fetchOptions: {
query: getCustomerQuery,
query: viewerQuery,
},
async fetcher({ options, fetch }) {
const data = await fetch<any | null>({
...options,
variables: { customerAccessToken: getCustomerToken() },
})
return data.customer ?? null
return data.viewer ?? null
},
useHook: ({ useData }) => (input) => {
return useData({