mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
replace customer query with viewer
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
parent
8d68add81d
commit
49bd38fd82
@ -1,20 +1,19 @@
|
|||||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||||
import { Customer } from '@commerce/types'
|
import { Customer } from '@commerce/types'
|
||||||
import { SWRHook } from '@commerce/utils/types'
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
import { getCustomerQuery, getCustomerToken } from '../utils'
|
import { viewerQuery } from '../utils'
|
||||||
|
|
||||||
export default useCustomer as UseCustomer<typeof handler>
|
export default useCustomer as UseCustomer<typeof handler>
|
||||||
|
|
||||||
export const handler: SWRHook<Customer | null> = {
|
export const handler: SWRHook<Customer | null> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: getCustomerQuery,
|
query: viewerQuery,
|
||||||
},
|
},
|
||||||
async fetcher({ options, fetch }) {
|
async fetcher({ options, fetch }) {
|
||||||
const data = await fetch<any | null>({
|
const data = await fetch<any | null>({
|
||||||
...options,
|
...options,
|
||||||
variables: { customerAccessToken: getCustomerToken() },
|
|
||||||
})
|
})
|
||||||
return data.customer ?? null
|
return data.viewer ?? null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook: ({ useData }) => (input) => {
|
||||||
return useData({
|
return useData({
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
export const getCustomerQuery = /* GraphQL */ `
|
export const viewerQuery = /* GraphQL */ `
|
||||||
query getCustomerId($customerAccessToken: String!) {
|
query getCustomerId($customerAccessToken: String!) {
|
||||||
customer(customerAccessToken: $customerAccessToken) {
|
customer(customerAccessToken: $customerAccessToken) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
export default getCustomerQuery
|
export default viewerQuery
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
export const getCustomerQuery = /* GraphQL */ `
|
|
||||||
query getCustomer($customerAccessToken: String!) {
|
|
||||||
customer(customerAccessToken: $customerAccessToken) {
|
|
||||||
id
|
|
||||||
firstName
|
|
||||||
lastName
|
|
||||||
displayName
|
|
||||||
email
|
|
||||||
phone
|
|
||||||
tags
|
|
||||||
acceptsMarketing
|
|
||||||
createdAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
export default getCustomerQuery
|
|
@ -7,4 +7,4 @@ export { default as getCollectionProductsQuery } from './get-collection-products
|
|||||||
export { default as getCheckoutQuery } from './get-checkout-query'
|
export { default as getCheckoutQuery } from './get-checkout-query'
|
||||||
export { default as getAllPagesQuery } from './get-all-pages-query'
|
export { default as getAllPagesQuery } from './get-all-pages-query'
|
||||||
export { default as getPageQuery } from './get-page-query'
|
export { default as getPageQuery } from './get-page-query'
|
||||||
export { default as getCustomerQuery } from './get-customer-query'
|
export { default as viewerQuery } from './viewer-query'
|
||||||
|
26
framework/reactioncommerce/utils/queries/viewer-query.ts
Normal file
26
framework/reactioncommerce/utils/queries/viewer-query.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
export const viewerQuery = /* GraphQL */ `
|
||||||
|
query viewer {
|
||||||
|
viewer {
|
||||||
|
_id
|
||||||
|
addressBook {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
_id
|
||||||
|
isBillingDefault
|
||||||
|
isShippingDefault
|
||||||
|
phone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emailRecords {
|
||||||
|
address
|
||||||
|
}
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
name
|
||||||
|
primaryEmailAddress
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
export default viewerQuery
|
Loading…
x
Reference in New Issue
Block a user