From 63ffcb6e60c1ec154bca09c90ba1c7fced653c8a Mon Sep 17 00:00:00 2001 From: Jeremy Gabriel <63984091+jeremyagabriel@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:19:19 -0700 Subject: [PATCH] chore: graphql query cleanup --- app/data/queries/article.queries.ts | 2 +- app/data/queries/blog.queries.ts | 2 +- app/data/queries/cart.queries.ts | 2 +- app/data/queries/collection.queries.ts | 12 +-- app/data/queries/pack.queries.ts | 2 +- app/data/queries/page.queries.ts | 2 +- app/data/queries/product.queries.ts | 100 ++++++----------------- app/data/queries/search.queries.ts | 12 +-- app/data/queries/sellingPlans.queries.ts | 4 +- app/data/queries/shop.queries.ts | 22 ++--- app/lib/utils/server.utils.ts | 2 +- 11 files changed, 56 insertions(+), 106 deletions(-) diff --git a/app/data/queries/article.queries.ts b/app/data/queries/article.queries.ts index 39cad70..0373b28 100644 --- a/app/data/queries/article.queries.ts +++ b/app/data/queries/article.queries.ts @@ -32,7 +32,7 @@ export const ARTICLE_QUERY = `#graphql } sections(first: 25, after: $cursor) { nodes { - ...section + ...SectionFragment } pageInfo { hasNextPage diff --git a/app/data/queries/blog.queries.ts b/app/data/queries/blog.queries.ts index b4f876d..3f8a1d8 100644 --- a/app/data/queries/blog.queries.ts +++ b/app/data/queries/blog.queries.ts @@ -22,7 +22,7 @@ export const BLOG_QUERY = `#graphql } sections(first: 25) { nodes { - ...section + ...SectionFragment } pageInfo { hasNextPage diff --git a/app/data/queries/cart.queries.ts b/app/data/queries/cart.queries.ts index d2cff41..2c2f232 100644 --- a/app/data/queries/cart.queries.ts +++ b/app/data/queries/cart.queries.ts @@ -95,7 +95,7 @@ export const CART_LINE_FRAGMENT = `#graphql } } options { - ...option + ...OptionFragment } images(first: 20) { nodes { diff --git a/app/data/queries/collection.queries.ts b/app/data/queries/collection.queries.ts index c1de2ef..54270e9 100644 --- a/app/data/queries/collection.queries.ts +++ b/app/data/queries/collection.queries.ts @@ -14,7 +14,7 @@ export const COLLECTION_PAGE_QUERY = `#graphql status sections(first: 25) { nodes { - ...section + ...SectionFragment } pageInfo { hasNextPage @@ -71,7 +71,7 @@ export const CMS_COLLECTIONS_QUERY = `#graphql // Docs: https://shopify.dev/docs/api/storefront/latest/queries/collection const COLLECTION_FRAGMENT = `#graphql - fragment collectionFragment on Collection { + fragment CollectionFragment on Collection { id title description @@ -126,7 +126,7 @@ const COLLECTION_FRAGMENT = `#graphql } nodes { ... on Product { - ...productItemFragment + ...ProductItemFragment } } } @@ -139,7 +139,7 @@ const COLLECTION_FRAGMENT = `#graphql ` as const; export const COLLECTION_QUERY = `#graphql - query CollectionDetails( + query Collection( $handle: String!, $country: CountryCode, $language: LanguageCode @@ -153,7 +153,7 @@ export const COLLECTION_QUERY = `#graphql ) @inContext(country: $country, language: $language) { collection(handle: $handle) { ... on Collection { - ...collectionFragment + ...CollectionFragment } } } @@ -161,7 +161,7 @@ export const COLLECTION_QUERY = `#graphql ` as const; export const COLLECTION_FILTERS_QUERY = `#graphql - query CollectionDetails( + query CollectionFilters( $handle: String!, $country: CountryCode, $language: LanguageCode diff --git a/app/data/queries/pack.queries.ts b/app/data/queries/pack.queries.ts index ce1d131..15d2f0a 100644 --- a/app/data/queries/pack.queries.ts +++ b/app/data/queries/pack.queries.ts @@ -53,7 +53,7 @@ export const PRODUCT_GROUPINGS_QUERY = `#graphql ` as const; export const SECTION_FRAGMENT = `#graphql - fragment section on Section { + fragment SectionFragment on Section { id title status diff --git a/app/data/queries/page.queries.ts b/app/data/queries/page.queries.ts index f28fe16..03d0b02 100644 --- a/app/data/queries/page.queries.ts +++ b/app/data/queries/page.queries.ts @@ -22,7 +22,7 @@ export const PAGE_QUERY = `#graphql } sections(first: 25, after: $cursor) { nodes { - ...section + ...SectionFragment } pageInfo { hasNextPage diff --git a/app/data/queries/product.queries.ts b/app/data/queries/product.queries.ts index c919517..137b370 100644 --- a/app/data/queries/product.queries.ts +++ b/app/data/queries/product.queries.ts @@ -17,7 +17,7 @@ export const PRODUCT_PAGE_QUERY = `#graphql status sections(first: 25) { nodes { - ...section + ...SectionFragment } pageInfo { hasNextPage @@ -78,7 +78,7 @@ export const CMS_PRODUCTS_QUERY = `#graphql // Docs: https://shopify.dev/docs/api/storefront/latest/queries/product export const OPTION_FRAGMENT = `#graphql - fragment option on ProductOption { + fragment OptionFragment on ProductOption { id name optionValues { @@ -104,7 +104,7 @@ export const OPTION_FRAGMENT = `#graphql `; export const METAFIELD_FRAGMENT = `#graphql -fragment metafield on Metafield { +fragment MetafieldFragment on Metafield { createdAt description id @@ -117,7 +117,7 @@ fragment metafield on Metafield { `; export const VARIANT_FRAGMENT = `#graphql - fragment variantFragment on ProductVariant { + fragment VariantFragment on ProductVariant { id title availableForSale @@ -139,7 +139,7 @@ export const VARIANT_FRAGMENT = `#graphql edges { node { ... on SellingPlanAllocation { - ...sellingPlanAllocation + ...SellingPlanAllocationFragment } } } @@ -164,7 +164,7 @@ export const VARIANT_FRAGMENT = `#graphql ` as const; export const PRODUCT_FRAGMENT = `#graphql - fragment productFragment on Product { + fragment ProductFragment on Product { id title handle @@ -251,18 +251,18 @@ export const PRODUCT_FRAGMENT = `#graphql } } options { - ...option + ...OptionFragment } selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions) { ... on ProductVariant { - ...variantFragment + ...VariantFragment } } sellingPlanGroups(first: 10) { edges { node { ... on SellingPlanGroup { - ...sellingPlanGroup + ...SellingPlanGroupFragment } } } @@ -270,7 +270,7 @@ export const PRODUCT_FRAGMENT = `#graphql variants(first: 250) { nodes { ... on ProductVariant { - ...variantFragment + ...VariantFragment } } } @@ -285,7 +285,7 @@ export const PRODUCT_FRAGMENT = `#graphql ` as const; export const PRODUCT_ITEM_FRAGMENT = `#graphql - fragment productItemFragment on Product { + fragment ProductItemFragment on Product { id title handle @@ -340,13 +340,13 @@ export const PRODUCT_ITEM_FRAGMENT = `#graphql } } options { - ...option + ...OptionFragment } sellingPlanGroups(first: 10) { edges { node { ... on SellingPlanGroup { - ...sellingPlanGroup + ...SellingPlanGroupFragment } } } @@ -354,7 +354,7 @@ export const PRODUCT_ITEM_FRAGMENT = `#graphql variants(first: 100) { nodes { ... on ProductVariant { - ...variantFragment + ...VariantFragment } } } @@ -365,7 +365,7 @@ export const PRODUCT_ITEM_FRAGMENT = `#graphql ` as const; export const PRODUCT_QUERY = `#graphql - query product( + query Product( $handle: String! $country: CountryCode $language: LanguageCode @@ -373,7 +373,7 @@ export const PRODUCT_QUERY = `#graphql ) @inContext(country: $country, language: $language) { product(handle: $handle) { ... on Product { - ...productFragment + ...ProductFragment } } } @@ -381,14 +381,14 @@ export const PRODUCT_QUERY = `#graphql ` as const; export const PRODUCT_ITEM_QUERY = `#graphql - query product( + query ProductItem( $handle: String! $country: CountryCode $language: LanguageCode ) @inContext(country: $country, language: $language) { product(handle: $handle) { ... on Product { - ...productItemFragment + ...ProductItemFragment } } } @@ -396,7 +396,7 @@ export const PRODUCT_ITEM_QUERY = `#graphql ` as const; export const PRODUCT_METAFIELDS_QUERY = `#graphql - query product( + query ProductMetafields( $handle: String! $key: String! $namespace: String @@ -405,63 +405,13 @@ export const PRODUCT_METAFIELDS_QUERY = `#graphql ) @inContext(country: $country, language: $language) { product(handle: $handle) { metafields(identifiers: {key: $key, namespace: $namespace}) { - ...metafield + ...MetafieldFragment } } } ${METAFIELD_FRAGMENT} ` as const; -export const GROUPING_PRODUCT_QUERY = `#graphql - query product( - $handle: String! - $country: CountryCode - $language: LanguageCode - ) @inContext(country: $country, language: $language) { - product(handle: $handle) { - id - title - handle - productType - options { - ...option - } - variants(first: 100) { - nodes { - id - title - availableForSale - sku - image { - altText - height - id - url - width - } - price { - currencyCode - amount - } - compareAtPrice { - currencyCode - amount - } - selectedOptions { - name - value - } - product { - handle - id - } - } - } - } - } - ${OPTION_FRAGMENT} -` as const; - export const PRODUCTS_QUERY = `#graphql query Products( $query: String @@ -481,7 +431,7 @@ export const PRODUCTS_QUERY = `#graphql } nodes { ... on Product { - ...productItemFragment + ...ProductItemFragment } } } @@ -490,7 +440,7 @@ export const PRODUCTS_QUERY = `#graphql ` as const; export const PRODUCT_FEED_QUERY = `#graphql - query Products( + query ProductsFeed( $first: Int! $cursor: String $country: CountryCode @@ -503,7 +453,7 @@ export const PRODUCT_FEED_QUERY = `#graphql } nodes { ... on Product { - ...productItemFragment + ...ProductItemFragment } } } @@ -512,7 +462,7 @@ export const PRODUCT_FEED_QUERY = `#graphql ` as const; export const PRODUCT_RECOMMENDATIONS_QUERY = `#graphql - query productRecommendations( + query ProductRecommendations( $productId: ID! $intent: ProductRecommendationIntent $country: CountryCode @@ -520,7 +470,7 @@ export const PRODUCT_RECOMMENDATIONS_QUERY = `#graphql ) @inContext(country: $country, language: $language) { productRecommendations(productId: $productId, intent: $intent) { ... on Product { - ...productItemFragment + ...ProductItemFragment } } } diff --git a/app/data/queries/search.queries.ts b/app/data/queries/search.queries.ts index c27478e..aadbd2b 100644 --- a/app/data/queries/search.queries.ts +++ b/app/data/queries/search.queries.ts @@ -30,7 +30,7 @@ export const PRODUCTS_SEARCH_QUERY = `#graphql ) { nodes { ... on Product { - ...productItemFragment + ...ProductItemFragment } } filters: productFilters { @@ -100,7 +100,7 @@ export const PRODUCTS_SEARCH_FILTERS_QUERY = `#graphql ` as const; const PREDICTIVE_COLLECTION_FRAGMENT = `#graphql - fragment PredictiveCollection on Collection { + fragment PredictiveCollectionFragment on Collection { __typename id title @@ -115,7 +115,7 @@ const PREDICTIVE_COLLECTION_FRAGMENT = `#graphql ` as const; const PREDICTIVE_QUERY_FRAGMENT = `#graphql - fragment PredictiveQuery on SearchQuerySuggestion { + fragment PredictiveQueryFragment on SearchQuerySuggestion { __typename text styledText @@ -123,7 +123,7 @@ const PREDICTIVE_QUERY_FRAGMENT = `#graphql ` as const; export const PREDICTIVE_SEARCH_QUERY = `#graphql - query predictiveSearch( + query PredictiveSearch( $country: CountryCode $language: LanguageCode $limit: Int! @@ -138,10 +138,10 @@ export const PREDICTIVE_SEARCH_QUERY = `#graphql types: $types, ) { collections { - ...PredictiveCollection + ...PredictiveCollectionFragment } queries { - ...PredictiveQuery + ...PredictiveQueryFragment } } } diff --git a/app/data/queries/sellingPlans.queries.ts b/app/data/queries/sellingPlans.queries.ts index 97d36dc..5f8f4d0 100644 --- a/app/data/queries/sellingPlans.queries.ts +++ b/app/data/queries/sellingPlans.queries.ts @@ -1,5 +1,5 @@ export const SELLING_PLAN_ALLOCATION_FRAGMENT = `#graphql - fragment sellingPlanAllocation on SellingPlanAllocation { + fragment SellingPlanAllocationFragment on SellingPlanAllocation { sellingPlan { id name @@ -52,7 +52,7 @@ export const SELLING_PLAN_ALLOCATION_FRAGMENT = `#graphql `; export const SELLING_PLAN_GROUP_FRAGMENT = `#graphql - fragment sellingPlanGroup on SellingPlanGroup { + fragment SellingPlanGroupFragment on SellingPlanGroup { name appName options { diff --git a/app/data/queries/shop.queries.ts b/app/data/queries/shop.queries.ts index a583a80..7948092 100644 --- a/app/data/queries/shop.queries.ts +++ b/app/data/queries/shop.queries.ts @@ -5,7 +5,7 @@ // Docs: https://shopify.dev/docs/api/storefront/latest/objects/Shop export const LAYOUT_QUERY = `#graphql - query layout { + query Layout { shop { id name @@ -22,7 +22,7 @@ export const LAYOUT_QUERY = `#graphql ` as const; const COUNTRY_FRAGMENT = `#graphql - fragment Country on Country { + fragment CountryFragment on Country { currency { isoCode name @@ -35,7 +35,7 @@ const COUNTRY_FRAGMENT = `#graphql ` as const; const POLICY_FRAGMENT = `#graphql - fragment Policy on ShopPolicy { + fragment PolicyFragment on ShopPolicy { handle id title @@ -45,7 +45,7 @@ const POLICY_FRAGMENT = `#graphql ` as const; export const SHOP_QUERY = `#graphql - query ($country: CountryCode, $language: LanguageCode) @inContext(country: $country, language: $language) { + query Shop($country: CountryCode, $language: LanguageCode) @inContext(country: $country, language: $language) { shop { description moneyFormat @@ -65,17 +65,17 @@ export const SHOP_QUERY = `#graphql url } privacyPolicy { - ...Policy + ...PolicyFragment } refundPolicy { - ...Policy + ...PolicyFragment } shippingPolicy { - ...Policy + ...PolicyFragment } shipsToCountries termsOfService { - ...Policy + ...PolicyFragment } } } @@ -85,7 +85,7 @@ export const SHOP_QUERY = `#graphql // Docs: https://shopify.dev/docs/api/storefront/latest/queries/localization export const LOCALIZATION_QUERY = `#graphql - query ($country: CountryCode, $language: LanguageCode) @inContext(country: $country, language: $language) { + query Localization($country: CountryCode, $language: LanguageCode) @inContext(country: $country, language: $language) { shop { paymentSettings { enabledCurrencies: enabledPresentmentCurrencies @@ -93,10 +93,10 @@ export const LOCALIZATION_QUERY = `#graphql } localization { availableCountries { - ...Country + ...CountryFragment } country { - ...Country + ...CountryFragment } } } diff --git a/app/lib/utils/server.utils.ts b/app/lib/utils/server.utils.ts index 8d96d6b..40b9dfb 100644 --- a/app/lib/utils/server.utils.ts +++ b/app/lib/utils/server.utils.ts @@ -264,7 +264,7 @@ export const getMetafields = async ( metafields_${index}: metafields( identifiers: {key: "${key}", namespace: "${namespace}"} ) { - ...metafield + ...MetafieldFragment } `, )}