mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
feat: get blog list
This commit is contained in:
@@ -16,7 +16,7 @@ export default function getAllBlogsOperation({
|
||||
variables?: BlogVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
}): Promise<{ blogs: GetAllBlogsQuery,totalItems:number }>
|
||||
}): Promise<{ blogs: GetAllBlogsQuery[],totalItems:number }>
|
||||
|
||||
async function getAllBlogs({
|
||||
query = getAllBlogsQuery,
|
||||
@@ -27,8 +27,8 @@ export default function getAllBlogsOperation({
|
||||
variables?: BlogVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ blogs: GetAllBlogsQuery | any[] ,totalItems?:number }> {
|
||||
console.log(vars.excludeBlogIds)
|
||||
} = {}): Promise<{ blogs: GetAllBlogsQuery[] | any[] ,totalItems?:number }> {
|
||||
|
||||
const config = commerce.getConfig(cfg)
|
||||
const variables = {
|
||||
excludeBlogIds: vars.excludeBlogIds,
|
||||
|
@@ -5,7 +5,7 @@ import { normalizeSearchResult } from '../../utils/normalize'
|
||||
import { getAllProductsQuery } from '../../utils/queries/get-all-products-query'
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
|
||||
export type ProductVariables = { first?: number, facetValueIds?: string[] }
|
||||
export type ProductVariables = { first?: number, facetValueIds?: string[], collectionSlug?:string, groupByProduct?:boolean }
|
||||
|
||||
export default function getAllProductsOperation({
|
||||
commerce,
|
||||
@@ -31,13 +31,13 @@ export default function getAllProductsOperation({
|
||||
input: {
|
||||
take: vars.first,
|
||||
facetValueIds: vars.facetValueIds,
|
||||
groupByProduct: true,
|
||||
collectionSlug : vars.collectionSlug,
|
||||
groupByProduct: vars.groupByProduct??true,
|
||||
},
|
||||
}
|
||||
const { data } = await config.fetch<GetAllProductsQuery>(query, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
products: data.search.items.map((item) => normalizeSearchResult(item)),
|
||||
totalItems: data.search.totalItems as number,
|
||||
|
@@ -15,7 +15,7 @@ export default function getFeaturedBlogOperation({
|
||||
variables?: BlogVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
}): Promise<{ featuredBlogs: GetFeaturedBlogQuery,totalItems:number }>
|
||||
}): Promise<{ featuredBlogs: GetFeaturedBlogQuery[],totalItems:number }>
|
||||
|
||||
async function getFeaturedBlog({
|
||||
query = getFeatuedBlogQuery,
|
||||
@@ -26,7 +26,7 @@ export default function getFeaturedBlogOperation({
|
||||
variables?: BlogVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ featuredBlogs: GetFeaturedBlogQuery | any[] ,totalItems?:number }> {
|
||||
} = {}): Promise<{ featuredBlogs: GetFeaturedBlogQuery[] | any[] ,totalItems?:number }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const variables = {
|
||||
options: {
|
||||
|
@@ -36,6 +36,7 @@ export default function getProductOperation({
|
||||
})),
|
||||
variants: product.variants.map((v) => ({
|
||||
id: v.id,
|
||||
name:v.name,
|
||||
options: v.options.map((o) => ({
|
||||
// This __typename property is required in order for the correct
|
||||
// variant selection to work, see `components/product/helpers.ts`
|
||||
@@ -54,7 +55,8 @@ export default function getProductOperation({
|
||||
values: og.options.map((o) => ({ label: o.name })),
|
||||
})),
|
||||
facetValueIds: product.facetValues.map(item=> item.id),
|
||||
collectionIds: product.collections.map(item => item.id)
|
||||
collectionIds: product.collections.map(item => item.id),
|
||||
collection:product.collections.map(item => item.name),
|
||||
} as Product
|
||||
}
|
||||
|
||||
|
93
framework/vendure/schema.d.ts
vendored
93
framework/vendure/schema.d.ts
vendored
@@ -1,3 +1,6 @@
|
||||
import { FacetValue, UpdateAddressInput } from './schema.d';
|
||||
import { ResetPassword } from './schema.d';
|
||||
import { requestPasswordReset } from '@framework/schema';
|
||||
import { FacetValue } from './schema.d';
|
||||
export type Maybe<T> = T | null
|
||||
export type Exact<T extends { [key: string]: unknown }> = {
|
||||
@@ -304,6 +307,11 @@ export type MutationResetPasswordArgs = {
|
||||
}
|
||||
|
||||
export type Address = Node & {
|
||||
updateCustomerAddress:
|
||||
| {
|
||||
__typename?: 'Address'
|
||||
id: Scalars['ID']
|
||||
}
|
||||
__typename?: 'Address'
|
||||
id: Scalars['ID']
|
||||
createdAt: Scalars['DateTime']
|
||||
@@ -322,6 +330,9 @@ export type Address = Node & {
|
||||
customFields?: Maybe<Scalars['JSON']>
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export type Asset = Node & {
|
||||
__typename?: 'Asset'
|
||||
id: Scalars['ID']
|
||||
@@ -1459,6 +1470,11 @@ export type CustomerListOptions = {
|
||||
}
|
||||
|
||||
export type Customer = Node & {
|
||||
updateCustomer:
|
||||
| {
|
||||
__typename?: 'Customer'
|
||||
id: Scalars['ID']
|
||||
}
|
||||
__typename?: 'Customer'
|
||||
id: Scalars['ID']
|
||||
createdAt: Scalars['DateTime']
|
||||
@@ -1466,7 +1482,7 @@ export type Customer = Node & {
|
||||
title?: Maybe<Scalars['String']>
|
||||
firstName: Scalars['String']
|
||||
lastName: Scalars['String']
|
||||
phoneNumber?: Maybe<Scalars['String']>
|
||||
phoneNumber?: Maybe<Scalars['String']>
|
||||
emailAddress: Scalars['String']
|
||||
addresses?: Maybe<Array<Address>>
|
||||
orders: OrderList
|
||||
@@ -2344,6 +2360,7 @@ export type GetAllBlogsQuery = PaginatedList & {
|
||||
}
|
||||
}
|
||||
export type GetFeaturedBlogQuery = PaginatedList & {
|
||||
id:string,
|
||||
featuredBlogs: { __typename?: 'BlogList' } & {
|
||||
items: Array<{ __typename?: 'Blog' } & BlogList!>,
|
||||
'totalItems'
|
||||
@@ -3087,7 +3104,7 @@ export type SearchResultFragment = { __typename?: 'SearchResult' } & Pick<
|
||||
SearchResult,
|
||||
'productId' | 'sku' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
|
||||
| 'productAsset' | 'price' | 'priceWithTax' | 'currencyCode'
|
||||
| 'collectionIds' | 'facetValueIds' | 'collectionIds'
|
||||
| 'collectionIds' | 'productVariantId' | 'facetValueIds' | "productVariantName"
|
||||
> & {
|
||||
productAsset?: Maybe<
|
||||
{ __typename?: 'SearchResultAsset' } & Pick<
|
||||
@@ -3174,6 +3191,36 @@ export type LoginMutation = { __typename?: 'Mutation' } & {
|
||||
>)
|
||||
}
|
||||
|
||||
export type ResetPasswordMutation = { __typename?: 'Mutation' } & {
|
||||
resetPassword:
|
||||
| ({ __typename: 'CurrentUser' } & Pick<CurrentUser, 'id'>)
|
||||
| ({ __typename: 'PasswordResetTokenInvalidError' } & Pick<
|
||||
PasswordResetTokenInvalidError,
|
||||
'errorCode' | 'message'
|
||||
>)
|
||||
| ({ __typename: 'PasswordResetTokenExpiredError' } & Pick<
|
||||
PasswordResetTokenExpiredError,
|
||||
'errorCode' | 'message'
|
||||
>)
|
||||
| ({ __typename: 'NativeAuthStrategyError' } & Pick<
|
||||
NativeAuthStrategyError,
|
||||
'errorCode' | 'message'
|
||||
>)
|
||||
}
|
||||
|
||||
export type SignupMutation = { __typename?: 'Mutation' } & {
|
||||
registerCustomerAccount:
|
||||
| ({ __typename: 'Success' } & Pick<Success, 'success'>)
|
||||
| ({ __typename: 'MissingPasswordError' } & Pick<
|
||||
MissingPasswordError,
|
||||
'errorCode' | 'message'
|
||||
>)
|
||||
| ({ __typename: 'NativeAuthStrategyError' } & Pick<
|
||||
NativeAuthStrategyError,
|
||||
'errorCode' | 'message'
|
||||
>)
|
||||
}
|
||||
|
||||
export type VerifyCustomerAccountVariables = Exact<{
|
||||
token: Scalars['String']
|
||||
password?: Maybe<Scalars['String']>
|
||||
@@ -3227,8 +3274,9 @@ export type SignupMutationVariables = Exact<{
|
||||
input: RegisterCustomerInput
|
||||
}>
|
||||
|
||||
export type SignupMutation = { __typename?: 'Mutation' } & {
|
||||
registerCustomerAccount:
|
||||
|
||||
export type RequestPasswordReset = { __typename?: 'Mutation' } & {
|
||||
requestPasswordReset:
|
||||
| ({ __typename: 'Success' } & Pick<Success, 'success'>)
|
||||
| ({ __typename: 'MissingPasswordError' } & Pick<
|
||||
MissingPasswordError,
|
||||
@@ -3240,17 +3288,48 @@ export type SignupMutation = { __typename?: 'Mutation' } & {
|
||||
>)
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type ActiveCustomerQueryVariables = Exact<{ [key: string]: never }>
|
||||
|
||||
export type ActiveCustomerQuery = { __typename?: 'Query' } & {
|
||||
activeCustomer?: Maybe<
|
||||
{ __typename?: 'Customer' } & Pick<
|
||||
Customer,
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress'
|
||||
Favorite,
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'addresses' | 'phoneNumber'| 'orders'
|
||||
>
|
||||
>
|
||||
}
|
||||
|
||||
export type QueryFavorite = {
|
||||
options: FavoriteListOptions
|
||||
}
|
||||
|
||||
export type FavoriteListOptions = {
|
||||
skip?: Maybe<Scalars['Int']>
|
||||
take?: Maybe<Scalars['Int']>
|
||||
}
|
||||
|
||||
export type FavoriteList = PaginatedList & {
|
||||
items: [Favorite!]!
|
||||
totalItems: Int!
|
||||
}
|
||||
|
||||
type Favorite = Node & {
|
||||
id: ID!
|
||||
createdAt: DateTime!
|
||||
updatedAt: DateTime!
|
||||
product: Product
|
||||
customer: Customer!
|
||||
}
|
||||
|
||||
|
||||
|
||||
type FavouriteOption = Customer & {
|
||||
favorites(options: FavoriteListOptions): FavoriteList!
|
||||
}
|
||||
|
||||
export type GetAllProductPathsQueryVariables = Exact<{
|
||||
first?: Maybe<Scalars['Int']>
|
||||
}>
|
||||
@@ -3351,7 +3430,7 @@ export type GetProductQuery = { __typename?: 'Query' } & {
|
||||
variants: Array<
|
||||
{ __typename?: 'ProductVariant' } & Pick<
|
||||
ProductVariant,
|
||||
'id' | 'priceWithTax' | 'currencyCode' | 'price'
|
||||
'id' | 'priceWithTax' | 'currencyCode' | 'price' | "name"
|
||||
> & {
|
||||
options: Array<
|
||||
{ __typename?: 'ProductOption' } & Pick<
|
||||
@@ -3395,7 +3474,7 @@ export type GetProductQuery = { __typename?: 'Query' } & {
|
||||
collections: Array<
|
||||
{ __typename?: 'Collection' } & Pick<
|
||||
Collection,
|
||||
'id'
|
||||
'id'|"name"
|
||||
>
|
||||
>
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ export const searchResultFragment = /* GraphQL */ `
|
||||
slug
|
||||
sku
|
||||
currencyCode
|
||||
productVariantId
|
||||
productVariantName
|
||||
productAsset {
|
||||
id
|
||||
preview
|
||||
|
@@ -0,0 +1,14 @@
|
||||
export const requestPasswordReset = /* GraphQL */ `
|
||||
mutation RequestPasswordReset($emailAddress: String!) {
|
||||
requestPasswordReset(emailAddress: $emailAddress) {
|
||||
__typename
|
||||
...on Success{
|
||||
success
|
||||
}
|
||||
...on ErrorResult{
|
||||
errorCode
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
15
framework/vendure/utils/mutations/reset-password-mutation.ts
Normal file
15
framework/vendure/utils/mutations/reset-password-mutation.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const resetPasswordMutation = /* GraphQL */ `
|
||||
mutation resetPassword($token: String!,$password: String!){
|
||||
resetPassword(token: $token,password: $password){
|
||||
__typename
|
||||
...on CurrentUser{
|
||||
id
|
||||
identifier
|
||||
}
|
||||
...on ErrorResult{
|
||||
errorCode
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -0,0 +1,9 @@
|
||||
export const toggleWishlistMutation = /* GraphQL */ `
|
||||
mutation toggleFavorite($productId:ID!){
|
||||
toggleFavorite(productId:$productId){
|
||||
items{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -0,0 +1,14 @@
|
||||
export const updateCustomerAddress = /* GraphQL */ `
|
||||
mutation updateCustomerAddress($input: UpdateAddressInput!){
|
||||
updateCustomerAddress(input: $input){
|
||||
__typename
|
||||
...on Address{
|
||||
id
|
||||
streetLine1
|
||||
city
|
||||
postalCode
|
||||
province
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -0,0 +1,13 @@
|
||||
export const updateCustomer = /* GraphQL */ `
|
||||
mutation updateCustomer($input: UpdateCustomerInput!){
|
||||
updateCustomer(input:$input){
|
||||
__typename
|
||||
...on Customer{
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
phoneNumber
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -1,6 +1,6 @@
|
||||
import { Cart } from '@commerce/types/cart'
|
||||
import { ProductCard } from '@commerce/types/product'
|
||||
import { CartFragment, SearchResultFragment } from '../schema'
|
||||
import { ProductCard, Product } from '@commerce/types/product'
|
||||
import { CartFragment, SearchResultFragment,Favorite } from '../schema'
|
||||
|
||||
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
return {
|
||||
@@ -10,6 +10,8 @@ export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
imageSrc: item.productAsset?.preview ? item.productAsset?.preview + '?w=800&mode=crop' : '',
|
||||
price: (item.priceWithTax as any).min / 100,
|
||||
currencyCode: item.currencyCode,
|
||||
productVariantId: item.productVariantId,
|
||||
productVariantName:item.productVariantName,
|
||||
facetValueIds: item.facetValueIds,
|
||||
collectionIds: item.collectionIds,
|
||||
|
||||
@@ -21,6 +23,18 @@ export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeFavoriteProductResult(item: Favorite) {
|
||||
return {
|
||||
id: item.product.id,
|
||||
name: item.product.name,
|
||||
slug: item.product.slug,
|
||||
imageSrc: item.product.assets[0].preview ? item.product.assets[0].preview + '?w=800&mode=crop' : '',
|
||||
price: item.product.variants[0].priceWithTax as number / 100,
|
||||
currencyCode: item.product.variants[0].currencyCode,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function normalizeCart(order: CartFragment): Cart {
|
||||
return {
|
||||
id: order.id.toString(),
|
||||
@@ -35,7 +49,7 @@ export function normalizeCart(order: CartFragment): Cart {
|
||||
id: l.id,
|
||||
name: l.productVariant.name,
|
||||
quantity: l.quantity,
|
||||
url: l.productVariant.product.slug,
|
||||
slug: l.productVariant.product.slug,
|
||||
variantId: l.productVariant.id,
|
||||
productId: l.productVariant.productId,
|
||||
images: [{ url: l.featuredAsset?.preview + '?preset=thumb' || '' }],
|
||||
@@ -55,3 +69,18 @@ export function normalizeCart(order: CartFragment): Cart {
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeProductCard(product: Product): ProductCard {
|
||||
return {
|
||||
id: product.id,
|
||||
name: product.name,
|
||||
slug: product.slug,
|
||||
imageSrc: product.images[0].url,
|
||||
price: product.price,
|
||||
currencyCode: product.currencyCode,
|
||||
productVariantId: product.variants?.[0].id.toString(),
|
||||
productVariantName:product.variants?.[0].name,
|
||||
facetValueIds: product.facetValueIds,
|
||||
collectionIds: product.collectionIds,
|
||||
}
|
||||
}
|
@@ -1,10 +1,24 @@
|
||||
export const activeCustomerQuery = /* GraphQL */ `
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
favorites{
|
||||
items{
|
||||
product{
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
phoneNumber
|
||||
addresses{
|
||||
streetLine1
|
||||
city
|
||||
province
|
||||
postalCode
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
@@ -0,0 +1,28 @@
|
||||
export const getFavoriteProductQuery = /* GraphQL */ `
|
||||
query activeCustomer($options: FavoriteListOptions) {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
favorites(options: $options){
|
||||
items{
|
||||
product{
|
||||
id
|
||||
name
|
||||
slug
|
||||
assets{
|
||||
source
|
||||
preview
|
||||
}
|
||||
variants{
|
||||
priceWithTax
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
}
|
||||
totalItems
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
@@ -12,6 +12,7 @@ export const getProductQuery = /* GraphQL */ `
|
||||
}
|
||||
variants {
|
||||
id
|
||||
name
|
||||
priceWithTax
|
||||
currencyCode
|
||||
options {
|
||||
@@ -41,6 +42,7 @@ export const getProductQuery = /* GraphQL */ `
|
||||
}
|
||||
collections {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
framework/vendure/utils/queries/get-user-order-query.ts
Normal file
19
framework/vendure/utils/queries/get-user-order-query.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const getUserOrderQuery = /* GraphQL */ `
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
orders{
|
||||
items{
|
||||
lines{
|
||||
productVariant{
|
||||
name
|
||||
}
|
||||
quantity
|
||||
}
|
||||
total
|
||||
state
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
16
framework/vendure/utils/queries/user-info-query.ts
Normal file
16
framework/vendure/utils/queries/user-info-query.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const userInfoQuery = /* GraphQL */ `
|
||||
query activeCustomer{
|
||||
activeCustomer{
|
||||
lastName
|
||||
firstName
|
||||
emailAddress
|
||||
phoneNumber
|
||||
addresses{
|
||||
streetLine1
|
||||
city
|
||||
province
|
||||
postalCode
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
Reference in New Issue
Block a user