mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
refactor: move query into get-product-query
This commit is contained in:
@@ -39,3 +39,19 @@ export const getProductQuery = /* GraphQL */ `
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
export const getProductDetailQuery = /* GraphQL */ `
|
||||||
|
query GetProductDetail($slug: String! = "hand-trowel") {
|
||||||
|
product(slug: $slug) {
|
||||||
|
name
|
||||||
|
description
|
||||||
|
variants {
|
||||||
|
price
|
||||||
|
priceWithTax
|
||||||
|
}
|
||||||
|
assets {
|
||||||
|
preview
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
@@ -1,30 +1,15 @@
|
|||||||
import { GetProductQuery } from '@framework/schema'
|
import { GetProductQuery } from '@framework/schema'
|
||||||
import { gql } from 'graphql-request'
|
import { getProductDetailQuery } from '@framework/utils/queries/get-product-query';
|
||||||
import gglFetcher from 'src/utils/gglFetcher'
|
import gglFetcher from 'src/utils/gglFetcher'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
const query = gql`
|
|
||||||
query GetProductDetail($slug: String! = "hand-trowel") {
|
|
||||||
product(slug: $slug) {
|
|
||||||
name
|
|
||||||
description
|
|
||||||
variants {
|
|
||||||
price
|
|
||||||
priceWithTax
|
|
||||||
}
|
|
||||||
assets {
|
|
||||||
preview
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
interface ProductDetail {
|
interface ProductDetail {
|
||||||
slug: string
|
slug: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const useProductDetail = () => {
|
const useProductDetail = () => {
|
||||||
const { data, ...rest } = useSWR<GetProductQuery>([query],gglFetcher)
|
const { data, ...rest } = useSWR<GetProductQuery>([getProductDetailQuery],gglFetcher)
|
||||||
return { productDetail: data?.product, ...rest }
|
return { productDetail: data?.product, ...rest }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user