diff --git a/framework/saleor/auth/use-login.tsx b/framework/saleor/auth/use-login.tsx index 2c784ec91..a2d3bc3e0 100644 --- a/framework/saleor/auth/use-login.tsx +++ b/framework/saleor/auth/use-login.tsx @@ -15,7 +15,7 @@ export default useLogin as UseLogin export const handler: MutationHook = { fetchOptions: { - query: mutation.sessionCreate, + query: mutation.SessionCreate, }, async fetcher({ input: { email, password }, options, fetch }) { if (!(email && password)) { diff --git a/framework/saleor/auth/use-logout.tsx b/framework/saleor/auth/use-logout.tsx index 37aa49188..33c929f5f 100644 --- a/framework/saleor/auth/use-logout.tsx +++ b/framework/saleor/auth/use-logout.tsx @@ -9,7 +9,7 @@ export default useLogout as UseLogout export const handler: MutationHook = { fetchOptions: { - query: mutation.sessionDestroy, + query: mutation.SessionDestroy, }, async fetcher({ options, fetch }) { await fetch({ diff --git a/framework/saleor/auth/use-signup.tsx b/framework/saleor/auth/use-signup.tsx index cff7c0412..c7d5d18f9 100644 --- a/framework/saleor/auth/use-signup.tsx +++ b/framework/saleor/auth/use-signup.tsx @@ -21,7 +21,7 @@ export const handler: MutationHook< AccountRegisterInput > = { fetchOptions: { - query: mutation.accountRegister + query: mutation.AccountCreate }, async fetcher({ input: { email, password }, diff --git a/framework/saleor/cart/use-add-item.tsx b/framework/saleor/cart/use-add-item.tsx index 7f5653fe5..a729b2ad1 100644 --- a/framework/saleor/cart/use-add-item.tsx +++ b/framework/saleor/cart/use-add-item.tsx @@ -17,7 +17,7 @@ import { Mutation, MutationCheckoutLinesAddArgs } from '../schema' export default useAddItem as UseAddItem export const handler: MutationHook = { - fetchOptions: { query: mutation.checkoutLineAdd }, + fetchOptions: { query: mutation.CheckoutLineAdd }, async fetcher({ input: item, options, fetch }) { if ( item.quantity && diff --git a/framework/saleor/cart/use-cart.tsx b/framework/saleor/cart/use-cart.tsx index 1d0737180..45baf60ce 100644 --- a/framework/saleor/cart/use-cart.tsx +++ b/framework/saleor/cart/use-cart.tsx @@ -7,7 +7,7 @@ import useCommerceCart, { import { Cart } from '../types' import { SWRHook } from '@commerce/utils/types' import { checkoutCreate, checkoutToCart, getCheckoutId } from '../utils' -import { getCheckoutQuery } from '../utils/queries' +import * as query from '../utils/queries' export default useCommerceCart as UseCart @@ -18,7 +18,7 @@ export const handler: SWRHook< { isEmpty?: boolean } > = { fetchOptions: { - query: getCheckoutQuery, + query: query.CheckoutOne, }, async fetcher({ input: { cartId: checkoutId }, options, fetch }) { let checkout diff --git a/framework/saleor/cart/use-remove-item.tsx b/framework/saleor/cart/use-remove-item.tsx index e9f8d2b5c..8ff661380 100644 --- a/framework/saleor/cart/use-remove-item.tsx +++ b/framework/saleor/cart/use-remove-item.tsx @@ -29,7 +29,7 @@ export type RemoveItemInput = T extends LineItem export default useRemoveItem as UseRemoveItem export const handler = { - fetchOptions: { query: mutation.checkoutLineDelete }, + fetchOptions: { query: mutation.CheckoutLineDelete }, async fetcher({ input: { itemId }, options, diff --git a/framework/saleor/cart/use-update-item.tsx b/framework/saleor/cart/use-update-item.tsx index d81b407ba..4822b1d9a 100644 --- a/framework/saleor/cart/use-update-item.tsx +++ b/framework/saleor/cart/use-update-item.tsx @@ -26,7 +26,7 @@ export type UpdateItemInput = T extends LineItem export default useUpdateItem as UseUpdateItem export const handler = { - fetchOptions: { query: mutation.checkoutLineUpdate }, + fetchOptions: { query: mutation.CheckoutLineUpdate }, async fetcher({ input: { itemId, item }, options, diff --git a/framework/saleor/common/get-all-pages.ts b/framework/saleor/common/get-all-pages.ts index b3ee07dc2..688c9ae5f 100644 --- a/framework/saleor/common/get-all-pages.ts +++ b/framework/saleor/common/get-all-pages.ts @@ -1,6 +1,6 @@ import { getConfig, SaleorConfig } from '../api' import { PageCountableEdge } from '../schema' -import { getAllPagesQuery } from '../utils/queries' +import * as query from '../utils/queries' type Variables = { first?: number @@ -26,7 +26,7 @@ const getAllPages = async (options?: { let { config, variables = { first: 100 } } = options ?? {} config = getConfig(config) const { locale } = config - const { data } = await config.fetch(getAllPagesQuery, { variables }) + const { data } = await config.fetch(query.PageMany, { variables }) const pages = data.pages?.edges?.map( ({ node: { title: name, slug, ...node } }: PageCountableEdge) => ({ diff --git a/framework/saleor/common/get-page.ts b/framework/saleor/common/get-page.ts index b036a54f5..003504010 100644 --- a/framework/saleor/common/get-page.ts +++ b/framework/saleor/common/get-page.ts @@ -1,7 +1,8 @@ import { getConfig, SaleorConfig } from '../api' -import { getPageQuery } from '../utils/queries' import { Page } from './get-all-pages' +import * as query from '../utils/queries' + type Variables = { id: string } @@ -18,9 +19,7 @@ const getPage = async (options: { config = getConfig(config) const { locale } = config - const { data } = await config.fetch(getPageQuery, { - variables, - }) + const { data } = await config.fetch(query.PageOne, { variables }) const page = data.page return { diff --git a/framework/saleor/customer/get-customer-id.ts b/framework/saleor/customer/get-customer-id.ts index 67ff40976..a9d38e8ba 100644 --- a/framework/saleor/customer/get-customer-id.ts +++ b/framework/saleor/customer/get-customer-id.ts @@ -1,5 +1,5 @@ import { getConfig, SaleorConfig } from '../api' -import { getCustomerIdQuery } from '../utils/queries' +import * as query from '../utils/queries' import Cookies from 'js-cookie' async function getCustomerId({ @@ -11,7 +11,7 @@ async function getCustomerId({ }): Promise { config = getConfig(config) - const { data } = await config.fetch(getCustomerIdQuery, { + const { data } = await config.fetch(query.CustomerOne, { variables: { customerAccesToken: customerAccesToken || Cookies.get(config.customerCookie), diff --git a/framework/saleor/customer/use-customer.tsx b/framework/saleor/customer/use-customer.tsx index 43178ecd0..c8140d82b 100644 --- a/framework/saleor/customer/use-customer.tsx +++ b/framework/saleor/customer/use-customer.tsx @@ -1,13 +1,14 @@ import useCustomer, { UseCustomer } from '@commerce/customer/use-customer' import { Customer } from '@commerce/types' import { SWRHook } from '@commerce/utils/types' -import { getCustomerQuery } from '../utils' + +import * as query from '../utils/queries' export default useCustomer as UseCustomer export const handler: SWRHook = { fetchOptions: { - query: getCustomerQuery, + query: query.CustomerCurrent, }, async fetcher({ options, fetch }) { const data = await fetch({ diff --git a/framework/saleor/product/get-all-collections.ts b/framework/saleor/product/get-all-collections.ts index ff683f4bc..1d6650579 100644 --- a/framework/saleor/product/get-all-collections.ts +++ b/framework/saleor/product/get-all-collections.ts @@ -1,6 +1,6 @@ import { CollectionCountableEdge } from '../schema' import { getConfig, SaleorConfig } from '../api' -import { getSiteCollectionsQuery } from '../utils/queries' +import * as query from '../utils/queries' const getAllCollections = async (options?: { variables?: any @@ -10,7 +10,7 @@ const getAllCollections = async (options?: { let { config, variables = { first: 100 } } = options ?? {} config = getConfig(config) - const { data } = await config.fetch(getSiteCollectionsQuery, { variables }) + const { data } = await config.fetch(query.CollectionMany, { variables }) const edges = data.collections?.edges ?? [] const categories = edges.map( diff --git a/framework/saleor/product/get-all-products.ts b/framework/saleor/product/get-all-products.ts index f4b6ea2c3..69de2e0d3 100644 --- a/framework/saleor/product/get-all-products.ts +++ b/framework/saleor/product/get-all-products.ts @@ -1,9 +1,11 @@ import { GraphQLFetcherResult } from '@commerce/api' +import { Product } from '@commerce/types' + import { getConfig, SaleorConfig } from '../api' import { ProductCountableEdge } from '../schema' -import { getAllProductsQuery } from '../utils/queries' import { normalizeProduct } from '../utils/normalize' -import { Product } from '@commerce/types' + +import * as query from '../utils/queries' type Variables = { first?: number @@ -22,10 +24,7 @@ const getAllProducts = async (options: { let { config, variables = { first: 100 } } = options ?? {} config = getConfig(config) - const { data }: GraphQLFetcherResult = await config.fetch( - getAllProductsQuery, - { variables } - ) + const { data }: GraphQLFetcherResult = await config.fetch(query.ProductMany, { variables }) const products = data.products?.edges?.map(({ node: p }: ProductCountableEdge) => diff --git a/framework/saleor/product/get-product.ts b/framework/saleor/product/get-product.ts index cce96a0d2..6e683512a 100644 --- a/framework/saleor/product/get-product.ts +++ b/framework/saleor/product/get-product.ts @@ -1,6 +1,7 @@ import { GraphQLFetcherResult } from '@commerce/api' import { getConfig, SaleorConfig } from '../api' -import { normalizeProduct, getProductQuery } from '../utils' +import { normalizeProduct } from '../utils' +import * as query from '../utils/queries'; type Variables = { slug: string @@ -18,9 +19,7 @@ const getProduct = async (options: { let { config, variables } = options ?? {} config = getConfig(config) - const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, { - variables, - }) + const { data }: GraphQLFetcherResult = await config.fetch(query.ProductOneBySlug, { variables }) return { product: data?.product ? normalizeProduct(data.product) : null, diff --git a/framework/saleor/product/use-search.tsx b/framework/saleor/product/use-search.tsx index 5a9431384..40bd096a6 100644 --- a/framework/saleor/product/use-search.tsx +++ b/framework/saleor/product/use-search.tsx @@ -1,15 +1,14 @@ import { SWRHook } from '@commerce/utils/types' +import { Product } from '@commerce/types' import useSearch, { UseSearch } from '@commerce/product/use-search' import { ProductCountableEdge } from '../schema' import { - getAllProductsQuery, - getCollectionProductsQuery, getSearchVariables, normalizeProduct, } from '../utils' -import { Product } from '@commerce/types' +import * as query from '../utils/queries' export default useSearch as UseSearch @@ -31,13 +30,13 @@ export const handler: SWRHook< SearchProductsInput > = { fetchOptions: { - query: getAllProductsQuery, + query: query.ProductMany }, async fetcher({ input, options, fetch }) { const { categoryId, brandId } = input const data = await fetch({ - query: categoryId ? getCollectionProductsQuery : options.query, + query: categoryId ? query.CollectionOne : options.query, method: options?.method, variables: getSearchVariables(input), }) diff --git a/framework/saleor/utils/checkout-attach.ts b/framework/saleor/utils/checkout-attach.ts index e032e33b2..af9711ddd 100644 --- a/framework/saleor/utils/checkout-attach.ts +++ b/framework/saleor/utils/checkout-attach.ts @@ -6,7 +6,7 @@ export const checkoutAttach = async ( { variables, headers }: any, ): Promise => { const data = await fetch({ - query: mutation.AttachCheckout, + query: mutation.CheckoutAttach, variables, headers }) diff --git a/framework/saleor/utils/checkout-create.ts b/framework/saleor/utils/checkout-create.ts index 3e634bc9c..fe1c15daa 100644 --- a/framework/saleor/utils/checkout-create.ts +++ b/framework/saleor/utils/checkout-create.ts @@ -7,7 +7,7 @@ import { CHECKOUT_ID_COOKIE } from '@framework/const' export const checkoutCreate = async ( fetch: any ): Promise => { - const data = await fetch({ query: mutation.checkoutCreate }) + const data = await fetch({ query: mutation.CheckoutCreate }) const checkout = data.checkoutCreate?.checkout const checkoutId = checkout?.id const checkoutToken = checkout?.token diff --git a/framework/saleor/utils/queries/get-checkout-query.ts b/framework/saleor/utils/fragments/checkout-details.ts similarity index 67% rename from framework/saleor/utils/queries/get-checkout-query.ts rename to framework/saleor/utils/fragments/checkout-details.ts index 92faab911..bf9370b06 100644 --- a/framework/saleor/utils/queries/get-checkout-query.ts +++ b/framework/saleor/utils/fragments/checkout-details.ts @@ -1,4 +1,4 @@ -export const checkoutDetailsFragment = ` +export const CheckoutDetails = ` id token created @@ -45,14 +45,4 @@ export const checkoutDetailsFragment = ` } } } -` - -export const getCheckoutQuery = /* GraphQL */ ` - query($checkoutId: UUID!) { - checkout(token: $checkoutId) { - ... on Checkout { - ${checkoutDetailsFragment} - } - } - } -` +` \ No newline at end of file diff --git a/framework/saleor/utils/fragments/index.ts b/framework/saleor/utils/fragments/index.ts new file mode 100644 index 000000000..8abf6d39e --- /dev/null +++ b/framework/saleor/utils/fragments/index.ts @@ -0,0 +1,2 @@ +export { ProductConnection } from './product'; +export { CheckoutDetails } from './checkout-details'; \ No newline at end of file diff --git a/framework/saleor/utils/fragments/product.ts b/framework/saleor/utils/fragments/product.ts new file mode 100644 index 000000000..69ad0a6e0 --- /dev/null +++ b/framework/saleor/utils/fragments/product.ts @@ -0,0 +1,29 @@ +export const ProductConnection = /* GraphQL */ ` + fragment ProductConnection on ProductCountableConnection { + pageInfo { + hasNextPage + hasPreviousPage + } + edges { + node { + id + name + description + slug + pricing { + priceRange { + start { + net { + amount + } + } + } + } + media { + url + alt + } + } + } + } +` \ No newline at end of file diff --git a/framework/saleor/utils/get-categories.ts b/framework/saleor/utils/get-categories.ts index 9dd6b84a8..e7394f287 100644 --- a/framework/saleor/utils/get-categories.ts +++ b/framework/saleor/utils/get-categories.ts @@ -1,6 +1,6 @@ import { SaleorConfig } from '../api' import { CollectionCountableEdge } from '../schema' -import { getSiteCollectionsQuery } from './queries/' +import * as query from './queries'; export type Category = { entityId: string @@ -9,7 +9,7 @@ export type Category = { } const getCategories = async (config: SaleorConfig): Promise => { - const { data } = await config.fetch(getSiteCollectionsQuery, { + const { data } = await config.fetch(query.CollectionMany, { variables: { first: 100, }, diff --git a/framework/saleor/utils/get-search-variables.ts b/framework/saleor/utils/get-search-variables.ts index 163328d88..ff40a654b 100644 --- a/framework/saleor/utils/get-search-variables.ts +++ b/framework/saleor/utils/get-search-variables.ts @@ -7,7 +7,7 @@ export const getSearchVariables = ({ categoryId, sort, }: SearchProductsInput) => { - const sortBy = { direction: 'ASC', ...getSortVariables(sort, !!categoryId), channel: "default-channel"}; + const sortBy = { field: "NAME", direction: 'ASC', ...getSortVariables(sort, !!categoryId), channel: "default-channel"}; return { categoryId, filter: { search }, diff --git a/framework/saleor/utils/get-vendors.ts b/framework/saleor/utils/get-vendors.ts index 48ba89404..caae555a8 100644 --- a/framework/saleor/utils/get-vendors.ts +++ b/framework/saleor/utils/get-vendors.ts @@ -1,6 +1,4 @@ import { SaleorConfig } from '../api' -import fetchAllProducts from '../api/utils/fetch-all-products' -import { getAllProductVendors } from './queries' export type Brand = { entityId: string diff --git a/framework/saleor/utils/handle-login.ts b/framework/saleor/utils/handle-login.ts index 39cc804c2..d5f214ed1 100644 --- a/framework/saleor/utils/handle-login.ts +++ b/framework/saleor/utils/handle-login.ts @@ -26,7 +26,7 @@ export const handleAutomaticLogin = async ( Mutation, MutationTokenCreateArgs >({ - query: mutation.sessionCreate, + query: mutation.SessionCreate, variables: { ...input }, }) handleLogin(tokenCreate!) diff --git a/framework/saleor/utils/mutations/customer-create.ts b/framework/saleor/utils/mutations/account-create.ts similarity index 61% rename from framework/saleor/utils/mutations/customer-create.ts rename to framework/saleor/utils/mutations/account-create.ts index 79fed9c1a..f50fe6ddd 100644 --- a/framework/saleor/utils/mutations/customer-create.ts +++ b/framework/saleor/utils/mutations/account-create.ts @@ -1,5 +1,5 @@ -export const accountRegister = /* GraphQL */ ` - mutation customerCreate($input: AccountRegisterInput!) { +export const AccountCreate = /* GraphQL */ ` + mutation AccountCreate($input: AccountRegisterInput!) { accountRegister(input: $input) { errors { code diff --git a/framework/saleor/utils/mutations/attach-checkout.ts b/framework/saleor/utils/mutations/checkout-attach.ts similarity index 60% rename from framework/saleor/utils/mutations/attach-checkout.ts rename to framework/saleor/utils/mutations/checkout-attach.ts index 31247c521..435be0582 100644 --- a/framework/saleor/utils/mutations/attach-checkout.ts +++ b/framework/saleor/utils/mutations/checkout-attach.ts @@ -1,5 +1,5 @@ -export const AttachCheckout = /* GraphQl */ ` - mutation AttachCheckout($checkoutId: ID!) { +export const CheckoutAttach = /* GraphQl */ ` + mutation CheckoutAttach($checkoutId: ID!) { checkoutCustomerAttach(checkoutId: $checkoutId) { errors { message diff --git a/framework/saleor/utils/mutations/checkout-create.ts b/framework/saleor/utils/mutations/checkout-create.ts index ddc4bbb21..155b715fd 100644 --- a/framework/saleor/utils/mutations/checkout-create.ts +++ b/framework/saleor/utils/mutations/checkout-create.ts @@ -1,7 +1,7 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' +import * as fragment from '../fragments' -export const checkoutCreate = /* GraphQL */ ` - mutation createCheckout { +export const CheckoutCreate = /* GraphQL */ ` + mutation CheckoutCreate { checkoutCreate(input: { email: "customer@example.com", lines: [], @@ -13,7 +13,7 @@ export const checkoutCreate = /* GraphQL */ ` message } checkout { - ${checkoutDetailsFragment} + ${fragment.CheckoutDetails} } } } diff --git a/framework/saleor/utils/mutations/checkout-line-add.ts b/framework/saleor/utils/mutations/checkout-line-add.ts new file mode 100644 index 000000000..d44fe5867 --- /dev/null +++ b/framework/saleor/utils/mutations/checkout-line-add.ts @@ -0,0 +1,16 @@ +import * as fragment from '../fragments' + +export const CheckoutLineAdd = /* GraphQL */ ` + mutation CheckoutLineAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) { + checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) { + errors { + code + field + message + } + checkout { + ${fragment.CheckoutDetails} + } + } + } +` diff --git a/framework/saleor/utils/mutations/checkout-line-item-add.ts b/framework/saleor/utils/mutations/checkout-line-item-add.ts deleted file mode 100644 index 9291495c8..000000000 --- a/framework/saleor/utils/mutations/checkout-line-item-add.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -export const checkoutLineAdd = /* GraphQL */ ` - mutation checkoutLineItemAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) { - checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) { - errors { - code - field - message - } - checkout { - ${checkoutDetailsFragment} - } - } - } -` diff --git a/framework/saleor/utils/mutations/checkout-line-item-remove.ts b/framework/saleor/utils/mutations/checkout-line-item-remove.ts deleted file mode 100644 index 8f55cd2a0..000000000 --- a/framework/saleor/utils/mutations/checkout-line-item-remove.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -export const checkoutLineDelete = /* GraphQL */ ` - mutation checkoutLineItemRemove($checkoutId: ID!, $lineId: ID!) { - checkoutLineDelete( - checkoutId: $checkoutId - lineId: $lineId - ) { - errors { - code - field - message - } - checkout { - ${checkoutDetailsFragment} - } - } - } -` diff --git a/framework/saleor/utils/mutations/checkout-line-item-update.ts b/framework/saleor/utils/mutations/checkout-line-item-update.ts deleted file mode 100644 index c23f6c65c..000000000 --- a/framework/saleor/utils/mutations/checkout-line-item-update.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -export const checkoutLineUpdate = /* GraphQL */ ` - mutation checkoutLineItemUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) { - checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) { - errors { - code - field - message - } - checkout { - ${checkoutDetailsFragment} - } - } - } -` diff --git a/framework/saleor/utils/mutations/checkout-line-remove.ts b/framework/saleor/utils/mutations/checkout-line-remove.ts new file mode 100644 index 000000000..dea9379cd --- /dev/null +++ b/framework/saleor/utils/mutations/checkout-line-remove.ts @@ -0,0 +1,19 @@ +import * as fragment from '../fragments' + +export const CheckoutLineDelete = /* GraphQL */ ` + mutation CheckoutLineDelete($checkoutId: ID!, $lineId: ID!) { + checkoutLineDelete( + checkoutId: $checkoutId + lineId: $lineId + ) { + errors { + code + field + message + } + checkout { + ${fragment.CheckoutDetails} + } + } + } +` diff --git a/framework/saleor/utils/mutations/checkout-line-update.ts b/framework/saleor/utils/mutations/checkout-line-update.ts new file mode 100644 index 000000000..e40c790c9 --- /dev/null +++ b/framework/saleor/utils/mutations/checkout-line-update.ts @@ -0,0 +1,16 @@ +import * as fragment from '../fragments'; + +export const CheckoutLineUpdate = /* GraphQL */ ` + mutation CheckoutLineUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) { + checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) { + errors { + code + field + message + } + checkout { + ${fragment.CheckoutDetails} + } + } + } +` diff --git a/framework/saleor/utils/mutations/index.ts b/framework/saleor/utils/mutations/index.ts index dd25b0e5c..a1f3d6089 100644 --- a/framework/saleor/utils/mutations/index.ts +++ b/framework/saleor/utils/mutations/index.ts @@ -1,8 +1,8 @@ -export { accountRegister } from './customer-create' -export { checkoutCreate } from './checkout-create' -export { checkoutLineAdd } from './checkout-line-item-add' -export { checkoutLineUpdate } from './checkout-line-item-update' -export { checkoutLineDelete } from './checkout-line-item-remove' -export { sessionCreate } from './customer-access-token-create' -export { sessionDestroy } from './customer-access-token-delete' -export { AttachCheckout } from './attach-checkout' +export { AccountCreate } from './account-create' +export { CheckoutCreate } from './checkout-create' +export { CheckoutLineAdd } from './checkout-line-add' +export { CheckoutLineUpdate } from './checkout-line-update' +export { CheckoutLineDelete } from './checkout-line-remove' +export { SessionCreate } from './session-create' +export { SessionDestroy } from './session-destroy' +export { CheckoutAttach } from './checkout-attach' diff --git a/framework/saleor/utils/mutations/customer-access-token-create.ts b/framework/saleor/utils/mutations/session-create.ts similarity index 62% rename from framework/saleor/utils/mutations/customer-access-token-create.ts rename to framework/saleor/utils/mutations/session-create.ts index 88dfaf4b8..d3c5a513d 100644 --- a/framework/saleor/utils/mutations/customer-access-token-create.ts +++ b/framework/saleor/utils/mutations/session-create.ts @@ -1,5 +1,5 @@ -export const sessionCreate = /* GraphQL */ ` - mutation tokenCreate($email: String!, $password: String!) { +export const SessionCreate = /* GraphQL */ ` + mutation SessionCreate($email: String!, $password: String!) { tokenCreate(email: $email, password: $password) { token refreshToken diff --git a/framework/saleor/utils/mutations/customer-access-token-delete.ts b/framework/saleor/utils/mutations/session-destroy.ts similarity index 51% rename from framework/saleor/utils/mutations/customer-access-token-delete.ts rename to framework/saleor/utils/mutations/session-destroy.ts index cf308bc44..def3a04ad 100644 --- a/framework/saleor/utils/mutations/customer-access-token-delete.ts +++ b/framework/saleor/utils/mutations/session-destroy.ts @@ -1,5 +1,5 @@ -export const sessionDestroy = /* GraphQL */ ` - mutation customerAccessTokenDelete { +export const SessionDestroy = /* GraphQL */ ` + mutation SessionDestroy { tokensDeactivateAll { errors { field diff --git a/framework/saleor/utils/queries/checkout-one.ts b/framework/saleor/utils/queries/checkout-one.ts new file mode 100644 index 000000000..14f6a9aae --- /dev/null +++ b/framework/saleor/utils/queries/checkout-one.ts @@ -0,0 +1,11 @@ +import * as fragment from '../fragments'; + +export const CheckoutOne = /* GraphQL */ ` + query CheckoutOne($checkoutId: UUID!) { + checkout(token: $checkoutId) { + ... on Checkout { + ${fragment.CheckoutDetails} + } + } + } +` diff --git a/framework/saleor/utils/queries/get-all-collections-query.ts b/framework/saleor/utils/queries/collection-many.ts similarity index 53% rename from framework/saleor/utils/queries/get-all-collections-query.ts rename to framework/saleor/utils/queries/collection-many.ts index 67856c6c5..b556e3faf 100644 --- a/framework/saleor/utils/queries/get-all-collections-query.ts +++ b/framework/saleor/utils/queries/collection-many.ts @@ -1,5 +1,5 @@ -export const getSiteCollectionsQuery = /* GraphQL */ ` - query getSiteCollections($first: Int!, $channel: String = "default-channel") { +export const CollectionMany = /* GraphQL */ ` + query CollectionMany($first: Int!, $channel: String = "default-channel") { collections(first: $first, channel: $channel) { edges { node { diff --git a/framework/saleor/utils/queries/get-collection-products-query.ts b/framework/saleor/utils/queries/collection-one.ts similarity index 58% rename from framework/saleor/utils/queries/get-collection-products-query.ts rename to framework/saleor/utils/queries/collection-one.ts index 09625d290..5771a5aaf 100644 --- a/framework/saleor/utils/queries/get-collection-products-query.ts +++ b/framework/saleor/utils/queries/collection-one.ts @@ -1,6 +1,6 @@ -import { productConnection } from './get-all-products-query' +import * as fragment from '../fragments' -export const getCollectionProductsQuery = /* GraphQL */ ` +export const CollectionOne = /* GraphQL */ ` query getProductsFromCollection( $categoryId: ID! $first: Int = 100 @@ -9,9 +9,9 @@ export const getCollectionProductsQuery = /* GraphQL */ ` collection(id: $categoryId, channel: $channel) { id products(first: $first) { - ...productConnection + ...ProductConnection } } } - ${productConnection} + ${fragment.ProductConnection} ` diff --git a/framework/saleor/utils/queries/customer-current.ts b/framework/saleor/utils/queries/customer-current.ts new file mode 100644 index 000000000..796545198 --- /dev/null +++ b/framework/saleor/utils/queries/customer-current.ts @@ -0,0 +1,11 @@ +export const CustomerCurrent = /* GraphQL */ ` + query CustomerCurrent { + me { + id + email + firstName + lastName + dateJoined + } + } +` diff --git a/framework/saleor/utils/queries/customer-one.ts b/framework/saleor/utils/queries/customer-one.ts new file mode 100644 index 000000000..d35b3f5ff --- /dev/null +++ b/framework/saleor/utils/queries/customer-one.ts @@ -0,0 +1,7 @@ +export const CustomerOne = /* GraphQL */ ` + query CustomerOne($customerAccessToken: String!) { + customer(customerAccessToken: $customerAccessToken) { + id + } + } +` diff --git a/framework/saleor/utils/queries/get-all-products-query.ts b/framework/saleor/utils/queries/get-all-products-query.ts deleted file mode 100644 index 1c3981bf0..000000000 --- a/framework/saleor/utils/queries/get-all-products-query.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const productConnection = /* GraphQL */ ` - fragment productConnection on ProductCountableConnection { - pageInfo { - hasNextPage - hasPreviousPage - } - edges { - node { - id - name - description - slug - pricing { - priceRange { - start { - net { - amount - } - } - } - } - media { - url - alt - } - } - } - } -` - -export const getAllProductsQuery = /* GraphQL */ ` - query getAllProducts( - $first: Int = 100 - $filter: ProductFilterInput - $sortBy: ProductOrder - $channel: String = "default-channel" - ) { - products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) { - ...productConnection - } - } - ${productConnection} -` diff --git a/framework/saleor/utils/queries/get-customer-id-query.ts b/framework/saleor/utils/queries/get-customer-id-query.ts deleted file mode 100644 index 1c197137e..000000000 --- a/framework/saleor/utils/queries/get-customer-id-query.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const getCustomerIdQuery = /* GraphQL */ ` - query getCustomerId($customerAccessToken: String!) { - customer(customerAccessToken: $customerAccessToken) { - id - } - } -` diff --git a/framework/saleor/utils/queries/get-customer-query.ts b/framework/saleor/utils/queries/get-customer-query.ts deleted file mode 100644 index ec77c89d0..000000000 --- a/framework/saleor/utils/queries/get-customer-query.ts +++ /dev/null @@ -1,12 +0,0 @@ -export const getCustomerQuery = /* GraphQL */ ` - query getCustomer { - me { - id - email - firstName - lastName - dateJoined - } - } -` -export default getCustomerQuery diff --git a/framework/saleor/utils/queries/get-page-query.ts b/framework/saleor/utils/queries/get-page-query.ts deleted file mode 100644 index 7cd9f1203..000000000 --- a/framework/saleor/utils/queries/get-page-query.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const getPageQuery = /* GraphQL */ ` - query($id: ID!) { - page(id: $id) { - id - title - slug - } - } -` diff --git a/framework/saleor/utils/queries/index.ts b/framework/saleor/utils/queries/index.ts index 93052314c..542c46f7c 100644 --- a/framework/saleor/utils/queries/index.ts +++ b/framework/saleor/utils/queries/index.ts @@ -1,11 +1,14 @@ -export { getSiteCollectionsQuery } from './get-all-collections-query' -export { getProductQuery } from './get-product-query' -export { getAllProductsQuery } from './get-all-products-query' +export { CollectionMany } from './collection-many' +export { ProductOneBySlug } from './product-one-by-slug' +export { ProductMany } from './product-many' +export { CollectionOne } from './collection-one' +export { CheckoutOne } from './checkout-one' +export { PageMany } from './page-many' +export { PageOne } from './page-one' +export { CustomerCurrent } from './customer-current' + +// getCustomerIdQuery +export { CustomerOne } from './customer-one' + export { getAllProductsPathsQuery } from './get-all-products-paths-query' export { getAllProductVendors } from './get-all-product-vendors-query' -export { getCollectionProductsQuery } from './get-collection-products-query' -export { getCheckoutQuery } from './get-checkout-query' -export { getAllPagesQuery } from './get-all-pages-query' -export { getPageQuery } from './get-page-query' -export { getCustomerQuery } from './get-customer-query' -export { getCustomerIdQuery } from './get-customer-id-query' diff --git a/framework/saleor/utils/queries/get-all-pages-query.ts b/framework/saleor/utils/queries/page-many.ts similarity index 58% rename from framework/saleor/utils/queries/get-all-pages-query.ts rename to framework/saleor/utils/queries/page-many.ts index 879e9202d..7ff0df9b7 100644 --- a/framework/saleor/utils/queries/get-all-pages-query.ts +++ b/framework/saleor/utils/queries/page-many.ts @@ -1,5 +1,5 @@ -export const getAllPagesQuery = /* GraphQL */ ` - query getAllPages($first: Int = 100) { +export const PageMany = /* GraphQL */ ` + query PageMany($first: Int = 100) { pages(first: $first) { edges { node { diff --git a/framework/saleor/utils/queries/page-one.ts b/framework/saleor/utils/queries/page-one.ts new file mode 100644 index 000000000..6d9789a9e --- /dev/null +++ b/framework/saleor/utils/queries/page-one.ts @@ -0,0 +1,9 @@ +export const PageOne = /* GraphQL */ ` + query PageOne($id: ID!) { + page(id: $id) { + id + title + slug + } + } +` diff --git a/framework/saleor/utils/queries/product-many.ts b/framework/saleor/utils/queries/product-many.ts new file mode 100644 index 000000000..2cf416418 --- /dev/null +++ b/framework/saleor/utils/queries/product-many.ts @@ -0,0 +1,15 @@ +import * as fragment from '../fragments'; + +export const ProductMany = /* GraphQL */ ` + query ProductMany( + $first: Int = 100 + $filter: ProductFilterInput + $sortBy: ProductOrder + $channel: String = "default-channel" + ) { + products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) { + ...ProductConnection + } + } + ${fragment.ProductConnection} +` diff --git a/framework/saleor/utils/queries/get-product-query.ts b/framework/saleor/utils/queries/product-one-by-slug.ts similarity index 84% rename from framework/saleor/utils/queries/get-product-query.ts rename to framework/saleor/utils/queries/product-one-by-slug.ts index 7a8b68d6d..fb3c94ffc 100644 --- a/framework/saleor/utils/queries/get-product-query.ts +++ b/framework/saleor/utils/queries/product-one-by-slug.ts @@ -1,5 +1,5 @@ -export const getProductQuery = /* GraphQL */ ` - query getProductBySlug($slug: String!, $channel: String = "default-channel") { +export const ProductOneBySlug = /* GraphQL */ ` + query ProductOneBySlug($slug: String!, $channel: String = "default-channel") { product(slug: $slug, channel: $channel) { id slug