Skip to content

Commit

Permalink
Reorder fragments (#833)
Browse files Browse the repository at this point in the history
* Reorder fragments so that we don't get the EOF error

* Create happy-pets-hide.md

* remove accidental comment
  • Loading branch information
frehner authored May 1, 2023
1 parent d5a7ed0 commit fc3c3eb
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-pets-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'demo-store': patch
---

Move GraphQL fragments from the beginning of the template literal to the end of it, so that we don't get the EOF error in VSCode.
8 changes: 4 additions & 4 deletions templates/demo-store/app/routes/($lang)._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default function Homepage() {
}

const COLLECTION_CONTENT_FRAGMENT = `#graphql
${MEDIA_FRAGMENT}
fragment CollectionContent on Collection {
id
handle
Expand All @@ -206,10 +205,10 @@ const COLLECTION_CONTENT_FRAGMENT = `#graphql
}
}
}
${MEDIA_FRAGMENT}
`;

const HOMEPAGE_SEO_QUERY = `#graphql
${COLLECTION_CONTENT_FRAGMENT}
query collectionContent($handle: String, $country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
hero: collection(handle: $handle) {
Expand All @@ -220,21 +219,21 @@ const HOMEPAGE_SEO_QUERY = `#graphql
description
}
}
${COLLECTION_CONTENT_FRAGMENT}
`;

const COLLECTION_HERO_QUERY = `#graphql
${COLLECTION_CONTENT_FRAGMENT}
query collectionContent($handle: String, $country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
hero: collection(handle: $handle) {
...CollectionContent
}
}
${COLLECTION_CONTENT_FRAGMENT}
`;

// @see: https://shopify.dev/api/storefront/2023-04/queries/products
export const HOMEPAGE_FEATURED_PRODUCTS_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query homepageFeaturedProducts($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
products(first: 8) {
Expand All @@ -243,6 +242,7 @@ export const HOMEPAGE_FEATURED_PRODUCTS_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;

// @see: https://shopify.dev/api/storefront/2023-04/queries/collections
Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/($lang).api.products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export async function loader({request, context: {storefront}}: LoaderArgs) {
}

const PRODUCTS_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query (
$query: String
$count: Int
Expand All @@ -77,6 +76,7 @@ const PRODUCTS_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;

// no-op
Expand Down
4 changes: 2 additions & 2 deletions templates/demo-store/app/routes/($lang).cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ export async function cartRemove({
}

const LINES_UPDATE_MUTATION = `#graphql
${LINES_CART_FRAGMENT}
${USER_ERROR_FRAGMENT}
mutation ($cartId: ID!, $lines: [CartLineUpdateInput!]!, $language: LanguageCode, $country: CountryCode)
@inContext(country: $country, language: $language) {
cartLinesUpdate(cartId: $cartId, lines: $lines) {
Expand All @@ -373,6 +371,8 @@ const LINES_UPDATE_MUTATION = `#graphql
}
}
}
${LINES_CART_FRAGMENT}
${USER_ERROR_FRAGMENT}
`;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export default function Collection() {
}

const COLLECTION_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query CollectionDetails(
$handle: String!
$country: CountryCode
Expand Down Expand Up @@ -230,6 +229,7 @@ const COLLECTION_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;

function getSortValuesFromParam(sortParam: SortParam | null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export async function getFeaturedData(
}

const FEATURED_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query homepage($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
featuredCollections: collections(first: 3, sortKey: UPDATED_AT) {
Expand All @@ -55,4 +54,5 @@ const FEATURED_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,6 @@ const PRODUCT_VARIANT_FRAGMENT = `#graphql
`;

const PRODUCT_QUERY = `#graphql
${MEDIA_FRAGMENT}
${PRODUCT_VARIANT_FRAGMENT}
query Product(
$country: CountryCode
$language: LanguageCode
Expand Down Expand Up @@ -590,10 +588,11 @@ const PRODUCT_QUERY = `#graphql
}
}
}
${MEDIA_FRAGMENT}
${PRODUCT_VARIANT_FRAGMENT}
`;

const RECOMMENDED_PRODUCTS_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query productRecommendations(
$productId: ID!
$count: Int
Expand All @@ -609,6 +608,7 @@ const RECOMMENDED_PRODUCTS_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;

async function getRecommendedProducts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export default function AllProducts() {
}

const ALL_PRODUCTS_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query AllProducts(
$country: CountryCode
$language: LanguageCode
Expand All @@ -175,4 +174,5 @@ const ALL_PRODUCTS_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/($lang).search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ export async function getNoResultRecommendations(
}

const SEARCH_NO_RESULTS_QUERY = `#graphql
${PRODUCT_CARD_FRAGMENT}
query searchNoResult(
$country: CountryCode
$language: LanguageCode
Expand All @@ -224,4 +223,5 @@ const SEARCH_NO_RESULTS_QUERY = `#graphql
}
}
}
${PRODUCT_CARD_FRAGMENT}
`;

0 comments on commit fc3c3eb

Please sign in to comment.