From c153e0db5082cdb7edf7bb8c30a556967eb581ec Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Fri, 12 Dec 2025 13:56:51 +0000 Subject: [PATCH] Merged in chore/delete-unused-files (pull request #3346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore: Delete unused files * Delete unused files Ignore design-system for now Approved-by: Joakim Jäderberg --- apps/partner-sas/hooks/useIsUserLoggedIn.ts | 6 - .../ContentType/StaticPages/index.tsx | 110 ------ .../StaticPages/staticPage.module.css | 112 ------ .../ContentType/StaticPages/staticPage.ts | 14 - .../ContentType/StaticPages/variants.ts | 15 - apps/scandic-web/components/Hero/hero.ts | 9 - .../MyPages/Profile/MembershipCards/index.tsx | 102 ----- .../membershipCards.module.css | 27 -- .../components/Section/Link/link.ts | 9 - .../components/hotelPage/previewImages.ts | 6 - .../types/components/myPages/friend.ts | 4 - .../types/components/myPages/points.ts | 5 - .../Header/Actions/DownloadInvoice.tsx | 34 -- .../actions/downloadInvoice.ts | 5 - .../booking-flow/lib/types/stores/rates.ts | 88 ----- .../Fragments/Aside/Contact.graphql.ts | 19 - .../graphql/Fragments/Aside/Puff.graphql.ts | 12 - .../graphql/Fragments/Blocks/List.graphql.ts | 39 -- .../graphql/Fragments/Blocks/Puff.graphql.ts | 18 - .../graphql/Fragments/Blocks/Text.graphql.ts | 23 -- .../Breadcrumbs/CurrentBlocksPage.graphql.ts | 13 - .../Breadcrumbs/PromoCampaignPage.graphql.ts | 32 -- .../lib/graphql/Fragments/Contact.graphql.ts | 71 ---- .../CurrentFooter/AppDownloads.graphql.ts | 32 -- .../Fragments/CurrentFooter/Logo.graphql.ts | 16 - .../CurrentFooter/MainLinks.graphql.ts | 33 -- .../CurrentFooter/Navigation.graphql.ts | 13 - .../CurrentFooter/Refs/MainLinks.graphql.ts | 31 -- .../Refs/SecondaryLinks.graphql.ts | 33 -- .../CurrentFooter/SecondaryLinks.graphql.ts | 24 -- .../CurrentFooter/SocialMedia.graphql.ts | 21 - .../CurrentFooter/TripAdvisor.graphql.ts | 19 - .../Footer/Refs/TertiaryLinks.graphql.ts | 29 -- .../lib/graphql/Fragments/Grid.graphql.ts | 21 - .../lib/graphql/Fragments/Hero.graphql.ts | 17 - .../PageLink/CurrentBlocksPageLink.graphql.ts | 14 - .../CurrentContentPageLink.graphql.ts | 14 - .../lib/graphql/Fragments/Preamble.graphql.ts | 22 -- .../lib/graphql/Fragments/Puff.graphql.ts | 25 -- .../trpc/lib/graphql/Query/Rewards.graphql.ts | 19 - scripts/README-convert-graphql-to-ts.md | 150 ------- scripts/convert-graphql-to-ts.ts | 373 ------------------ 42 files changed, 1679 deletions(-) delete mode 100644 apps/partner-sas/hooks/useIsUserLoggedIn.ts delete mode 100644 apps/scandic-web/components/ContentType/StaticPages/index.tsx delete mode 100644 apps/scandic-web/components/ContentType/StaticPages/staticPage.module.css delete mode 100644 apps/scandic-web/components/ContentType/StaticPages/staticPage.ts delete mode 100644 apps/scandic-web/components/ContentType/StaticPages/variants.ts delete mode 100644 apps/scandic-web/components/Hero/hero.ts delete mode 100644 apps/scandic-web/components/MyPages/Profile/MembershipCards/index.tsx delete mode 100644 apps/scandic-web/components/MyPages/Profile/MembershipCards/membershipCards.module.css delete mode 100644 apps/scandic-web/components/Section/Link/link.ts delete mode 100644 apps/scandic-web/types/components/hotelPage/previewImages.ts delete mode 100644 apps/scandic-web/types/components/myPages/friend.ts delete mode 100644 apps/scandic-web/types/components/myPages/points.ts delete mode 100644 packages/booking-flow/lib/components/BookingConfirmation/Header/Actions/DownloadInvoice.tsx delete mode 100644 packages/booking-flow/lib/types/components/bookingConfirmation/actions/downloadInvoice.ts delete mode 100644 packages/booking-flow/lib/types/stores/rates.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Aside/Contact.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Aside/Puff.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Blocks/List.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Blocks/Puff.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Blocks/Text.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Breadcrumbs/CurrentBlocksPage.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Breadcrumbs/PromoCampaignPage.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Contact.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/Logo.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/MainLinks.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/Navigation.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/MainLinks.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/SecondaryLinks.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/SecondaryLinks.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/SocialMedia.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Footer/Refs/TertiaryLinks.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Grid.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Hero.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/PageLink/CurrentBlocksPageLink.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/PageLink/CurrentContentPageLink.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Preamble.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Fragments/Puff.graphql.ts delete mode 100644 packages/trpc/lib/graphql/Query/Rewards.graphql.ts delete mode 100644 scripts/README-convert-graphql-to-ts.md delete mode 100644 scripts/convert-graphql-to-ts.ts diff --git a/apps/partner-sas/hooks/useIsUserLoggedIn.ts b/apps/partner-sas/hooks/useIsUserLoggedIn.ts deleted file mode 100644 index 21a386b63..000000000 --- a/apps/partner-sas/hooks/useIsUserLoggedIn.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { useBookingFlowContext } from "@scandic-hotels/booking-flow/hooks/useBookingFlowContext" - -export function useIsUserLoggedIn() { - const { isLoggedIn } = useBookingFlowContext() - return isLoggedIn -} diff --git a/apps/scandic-web/components/ContentType/StaticPages/index.tsx b/apps/scandic-web/components/ContentType/StaticPages/index.tsx deleted file mode 100644 index 9104a20f8..000000000 --- a/apps/scandic-web/components/ContentType/StaticPages/index.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import { Suspense } from "react" - -import ButtonLink from "@scandic-hotels/design-system/ButtonLink" -import { Typography } from "@scandic-hotels/design-system/Typography" -import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK" - -import Blocks from "@/components/Blocks" -import HeaderDynamicContent from "@/components/Headers/DynamicContent" -import Hero from "@/components/Hero" -import { HeroVideo } from "@/components/HeroVideo" -import MeetingPackageWidget from "@/components/MeetingPackageWidget" -import Sidebar from "@/components/Sidebar" -import SidebarSkeleton from "@/components/Sidebar/SidebarSkeleton" -import LinkChips from "@/components/TempDesignSystem/LinkChips" - -import { staticPageVariants } from "./variants" - -import styles from "./staticPage.module.css" - -import type { StaticPageProps } from "./staticPage" - -export default async function StaticPage({ - content, - tracking, - pageType, -}: StaticPageProps) { - const { blocks, hero_image, hero_video, header, meeting_package } = content - - return ( - <> -
-
-
- {header ? ( - <> -
- -

{header.heading}

-
- -

{header.preamble}

-
-
- {header.top_primary_button?.url ? ( - - {header.top_primary_button.title} - - ) : null} - {header.navigation_links ? ( - - ) : null} - {"dynamic_content" in header && - header.dynamic_content !== null && - header.dynamic_content !== undefined ? ( - - ) : null} - - ) : null} -
-
- - {hero_video || hero_image ? ( -
- {hero_video ? ( - - ) : null} - {!hero_video && hero_image ? ( - - ) : null} -
- ) : null} - -
-
- {pageType === "collection" && meeting_package?.show_widget && ( - - )} - {blocks ? : null} -
- - {"sidebar" in content && content.sidebar?.length ? ( - }> - - - ) : null} -
-
- - - ) -} diff --git a/apps/scandic-web/components/ContentType/StaticPages/staticPage.module.css b/apps/scandic-web/components/ContentType/StaticPages/staticPage.module.css deleted file mode 100644 index 8f9cf496c..000000000 --- a/apps/scandic-web/components/ContentType/StaticPages/staticPage.module.css +++ /dev/null @@ -1,112 +0,0 @@ -.page { - padding-bottom: var(--Space-x9); -} - -.header { - background-color: var(--Base-Surface-Subtle-Normal); - padding-bottom: var(--Space-x4); -} - -.headerContent { - display: grid; - gap: var(--Space-x3); - max-width: var(--max-width-content); - margin: 0 auto; -} - -.headerIntro { - display: grid; - max-width: var(--max-width-text-block); - gap: var(--Space-x3); -} - -.heading { - color: var(--Text-Heading); - text-wrap: balance; - hyphens: auto; -} - -.heroWrapper { - padding: var(--Space-x4) var(--Space-x2); -} - -.heroImage, -.heroVideo { - max-width: var(--max-width-content); - margin: 0 auto; - display: flex; -} - -.contentContainer { - width: 100%; - padding: var(--Space-x4) var(--Space-x2) 0; -} - -.content .contentContainer { - display: grid; - grid-template-areas: - "main" - "sidebar"; - gap: var(--Space-x4); - align-items: start; -} - -.mainContent { - display: grid; - width: 100%; - gap: var(--Space-x6); - margin: 0 auto; - max-width: var(--max-width-content); -} - -.content .mainContent { - grid-area: main; -} - -.meetingPackageWidget { - border-radius: var(--Corner-radius-lg); - overflow: hidden; -} - -.button { - width: fit-content; -} - -@media (min-width: 768px) { - .contentContainer { - padding: var(--Space-x4) 0; - max-width: var(--max-width-content); - margin: 0 auto; - } - - .heroContainer { - padding: var(--Space-x4) 0; - } - - .headerIntro { - gap: var(--Space-x3); - } -} - -/* Meeting booking widget changes design at 948px */ -@media screen and (min-width: 948px) { - .meetingPackageWidget { - background-color: var(--Base-Surface-Primary-light-Normal); - box-shadow: 0px 4px 24px 0px rgba(0, 0, 0, 0.05); - } -} - -@media (min-width: 1367px) { - .content .contentContainer { - grid-template-areas: "main sidebar"; - grid-template-columns: var(--max-width-text-block) 1fr; - gap: var(--Space-x9); - } - - .mainContent { - gap: var(--Space-x9); - padding: 0; - max-width: none; - margin: 0; - } -} diff --git a/apps/scandic-web/components/ContentType/StaticPages/staticPage.ts b/apps/scandic-web/components/ContentType/StaticPages/staticPage.ts deleted file mode 100644 index c526f88ca..000000000 --- a/apps/scandic-web/components/ContentType/StaticPages/staticPage.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { TrackingSDKPageData } from "@scandic-hotels/tracking/types" -import type { CollectionPage } from "@scandic-hotels/trpc/types/collectionPage" -import type { ContentPage } from "@scandic-hotels/trpc/types/contentPage" -import type { VariantProps } from "class-variance-authority" - -import type { staticPageVariants } from "./variants" - -export interface StaticPageProps - extends Omit, "content">, - VariantProps { - pageType?: "collection" | "content" - content: CollectionPage["collection_page"] | ContentPage["content_page"] - tracking: TrackingSDKPageData -} diff --git a/apps/scandic-web/components/ContentType/StaticPages/variants.ts b/apps/scandic-web/components/ContentType/StaticPages/variants.ts deleted file mode 100644 index 4d59bc641..000000000 --- a/apps/scandic-web/components/ContentType/StaticPages/variants.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { cva } from "class-variance-authority" - -import styles from "./staticPage.module.css" - -export const staticPageVariants = cva(styles.page, { - variants: { - pageType: { - collection: styles.collection, - content: styles.content, - }, - }, - defaultVariants: { - pageType: "content", - }, -}) diff --git a/apps/scandic-web/components/Hero/hero.ts b/apps/scandic-web/components/Hero/hero.ts deleted file mode 100644 index 4dc1b1dfb..000000000 --- a/apps/scandic-web/components/Hero/hero.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { FocalPoint } from "@scandic-hotels/common/utils/imageVault" -import type { Image } from "@scandic-hotels/trpc/types/image" - -export interface HeroProps { - alt: string - src: string - focalPoint?: FocalPoint - dimensions?: Image["dimension"] -} diff --git a/apps/scandic-web/components/MyPages/Profile/MembershipCards/index.tsx b/apps/scandic-web/components/MyPages/Profile/MembershipCards/index.tsx deleted file mode 100644 index d06232491..000000000 --- a/apps/scandic-web/components/MyPages/Profile/MembershipCards/index.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" -import Link from "@scandic-hotels/design-system/OldDSLink" -import { Typography } from "@scandic-hotels/design-system/Typography" - -import { getMembershipCards } from "@/lib/trpc/memoizedRequests" - -import { getIntl } from "@/i18n" - -import styles from "./membershipcards.module.css" - -export default async function MembershipCardSlot() { - const intl = await getIntl() - const membershipCards = await getMembershipCards() - - return ( -
-
- -

- {intl.formatMessage({ - id: "myPages.myMembershipCards", - defaultMessage: "My membership cards", - })} -

-
-
- {(membershipCards || []).map((card, idx) => ( -
- -

- {intl.formatMessage( - { - id: "myPages.nameWithCardMembershipType", - defaultMessage: "Name: {cardMembershipType}", - }, - { - cardMembershipType: card.membershipType, - } - )} -

-
- - {intl.formatMessage( - { - id: "myPages.currentPointsWithPoints", - defaultMessage: "Current Points: {points, number}", - }, - { points: card.currentPoints } - )} - - - {intl.formatMessage( - { - id: "myPages.memberSinceWithValue", - defaultMessage: "Member Since: {value}", - }, - { - value: card.memberSince, - } - )} - - - {intl.formatMessage( - { - id: "myPages.numberWithValue", - defaultMessage: "Number: {membershipNumber}", - }, - { - membershipNumber: card.membershipNumber, - } - )} - - - {intl.formatMessage( - { - id: "myPages.expirationDateWithDate", - defaultMessage: "Expiration Date: {expirationDate}", - }, - { - expirationDate: card.expirationDate?.split("T")[0], - } - )} - -
- ))} - - - -

- {intl.formatMessage({ - id: "myPages.addNewCard", - defaultMessage: "Add new card", - })} -

-
- -
- ) -} diff --git a/apps/scandic-web/components/MyPages/Profile/MembershipCards/membershipCards.module.css b/apps/scandic-web/components/MyPages/Profile/MembershipCards/membershipCards.module.css deleted file mode 100644 index 6919d3d8b..000000000 --- a/apps/scandic-web/components/MyPages/Profile/MembershipCards/membershipCards.module.css +++ /dev/null @@ -1,27 +0,0 @@ -.container { - display: grid; - gap: var(--Space-x3); - max-width: 510px; -} - -.content { - display: grid; - gap: var(--Space-x1); -} - -.card { - margin-top: var(--Space-x4); - display: grid; - grid-template-columns: repeat(2, 1fr); - grid-template-rows: repeat(3, auto); - gap: var(--Space-x1); -} - -.subTitle { - grid-column: span 2; -} - -.addNewCardText { - text-decoration: underline; - color: var(--Scandic-Brand-Burgundy); -} diff --git a/apps/scandic-web/components/Section/Link/link.ts b/apps/scandic-web/components/Section/Link/link.ts deleted file mode 100644 index 0cde53a5b..000000000 --- a/apps/scandic-web/components/Section/Link/link.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { VariantProps } from "class-variance-authority" - -import type { linkVariants } from "./variants" - -export interface SectionLinkProps - extends React.PropsWithChildren>, - VariantProps { - link?: { href: string; text: string } -} diff --git a/apps/scandic-web/types/components/hotelPage/previewImages.ts b/apps/scandic-web/types/components/hotelPage/previewImages.ts deleted file mode 100644 index df632a35e..000000000 --- a/apps/scandic-web/types/components/hotelPage/previewImages.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { ApiImage } from "@scandic-hotels/trpc/types/hotel" - -export type PreviewImagesProps = { - images: ApiImage[] - hotelName: string -} diff --git a/apps/scandic-web/types/components/myPages/friend.ts b/apps/scandic-web/types/components/myPages/friend.ts deleted file mode 100644 index 5cce78b4b..000000000 --- a/apps/scandic-web/types/components/myPages/friend.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { User } from "@scandic-hotels/trpc/types/user" - -export interface FriendProps - extends React.PropsWithChildren> {} diff --git a/apps/scandic-web/types/components/myPages/points.ts b/apps/scandic-web/types/components/myPages/points.ts deleted file mode 100644 index 33721f483..000000000 --- a/apps/scandic-web/types/components/myPages/points.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type PointsColumnProps = { - title: string - subtitle?: string - value?: number | null -} diff --git a/packages/booking-flow/lib/components/BookingConfirmation/Header/Actions/DownloadInvoice.tsx b/packages/booking-flow/lib/components/BookingConfirmation/Header/Actions/DownloadInvoice.tsx deleted file mode 100644 index 7121d03e9..000000000 --- a/packages/booking-flow/lib/components/BookingConfirmation/Header/Actions/DownloadInvoice.tsx +++ /dev/null @@ -1,34 +0,0 @@ -"use client" -import { useIntl } from "react-intl" -import { useReactToPrint } from "react-to-print" - -import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" -import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton" - -import type { DownloadInvoiceProps } from "../../../../types/components/bookingConfirmation/actions/downloadInvoice" - -export default function DownloadInvoice({ mainRef }: DownloadInvoiceProps) { - const intl = useIntl() - const reactToPrintFn = useReactToPrint({ contentRef: mainRef }) - - function downloadBooking() { - reactToPrintFn() - } - - return ( - - ) -} diff --git a/packages/booking-flow/lib/types/components/bookingConfirmation/actions/downloadInvoice.ts b/packages/booking-flow/lib/types/components/bookingConfirmation/actions/downloadInvoice.ts deleted file mode 100644 index 6d4570893..000000000 --- a/packages/booking-flow/lib/types/components/bookingConfirmation/actions/downloadInvoice.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { MutableRefObject } from "react" - -export interface DownloadInvoiceProps { - mainRef: MutableRefObject -} diff --git a/packages/booking-flow/lib/types/stores/rates.ts b/packages/booking-flow/lib/types/stores/rates.ts deleted file mode 100644 index 32b37199c..000000000 --- a/packages/booking-flow/lib/types/stores/rates.ts +++ /dev/null @@ -1,88 +0,0 @@ -import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency" -import type { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter" -import type { Room } from "@scandic-hotels/trpc/types/hotel" -import type { Package, PackageEnum } from "@scandic-hotels/trpc/types/packages" -import type { - Product, - RoomConfiguration, - RoomsAvailability, -} from "@scandic-hotels/trpc/types/roomAvailability" - -import type { BookingCodeFilterEnum } from "../../stores/bookingCode-filter" -import type { - Rate, - Room as RoomBooking, - SelectRateBooking, -} from "../components/selectRate/selectRate" - -export interface AvailabilityError { - details: string - error: string -} - -interface Actions { - appendRegularRates: ( - roomConfigurations: RoomConfiguration[] | undefined - ) => void - closeSection: () => void - modifyRate: () => void - removeSelectedPackage: (code: PackageEnum) => void - removeSelectedPackages: () => void - selectFilter: (filter: BookingCodeFilterEnum) => void - selectPackages: (codes: PackageEnum[]) => void - selectRate: (rate: SelectedRate, isUserLoggedIn: boolean) => void - updateRooms: (rooms: RoomConfiguration[] | undefined) => void -} - -export interface SelectedRate { - features: RoomConfiguration["features"] - product: Product - roomType: RoomConfiguration["roomType"] - roomTypeCode: RoomConfiguration["roomTypeCode"] -} - -export interface SelectedRoom { - actions: Actions - bookingRoom: RoomBooking - isFetchingAdditionalRate: boolean - isFetchingPackages: boolean - rooms: RoomConfiguration[] - selectedFilter: BookingCodeFilterEnum | undefined - selectedPackages: Package[] - selectedRate: SelectedRate | null -} - -interface DefaultFilterOptions { - code: RoomPackageCodeEnum - description: string -} - -export interface RatesState { - activeRoom: number - booking: SelectRateBooking - hotelType: string | undefined - isRedemptionBooking: boolean - packageOptions: DefaultFilterOptions[] - rateSummary: Array - rooms: SelectedRoom[] - roomCategories: Room[] - roomConfigurations: RoomConfiguration[][] - roomsPackages: Package[][] - roomsAvailability: (RoomsAvailability | AvailabilityError)[] | undefined - vat: number - defaultCurrency: CurrencyEnum -} - -export interface InitialState - extends Pick< - RatesState, - "booking" | "hotelType" | "roomCategories" | "roomsAvailability" | "vat" - > { - initialActiveRoom?: number - pathname: string - labels: { - accessibilityRoom: string - allergyRoom: string - petRoom: string - } -} diff --git a/packages/trpc/lib/graphql/Fragments/Aside/Contact.graphql.ts b/packages/trpc/lib/graphql/Fragments/Aside/Contact.graphql.ts deleted file mode 100644 index 0b3f4f325..000000000 --- a/packages/trpc/lib/graphql/Fragments/Aside/Contact.graphql.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { gql } from "graphql-tag" - -import { Contact } from "../Contact.graphql" - -export const ContactAside = gql` - fragment ContactAside on CurrentBlocksPageAsideContact { - contact { - contactConnection { - edges { - node { - ...Contact - } - } - totalCount - } - } - } - ${Contact} -` diff --git a/packages/trpc/lib/graphql/Fragments/Aside/Puff.graphql.ts b/packages/trpc/lib/graphql/Fragments/Aside/Puff.graphql.ts deleted file mode 100644 index 6744f4621..000000000 --- a/packages/trpc/lib/graphql/Fragments/Aside/Puff.graphql.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { gql } from "graphql-tag" - -import { Puff } from "../Puff.graphql" - -export const PuffAside = gql` - fragment PuffAside on CurrentBlocksPageAsidePuff { - puff { - ...Puff - } - } - ${Puff} -` diff --git a/packages/trpc/lib/graphql/Fragments/Blocks/List.graphql.ts b/packages/trpc/lib/graphql/Fragments/Blocks/List.graphql.ts deleted file mode 100644 index 3c5243d51..000000000 --- a/packages/trpc/lib/graphql/Fragments/Blocks/List.graphql.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { gql } from "graphql-tag" - -export const ListItem = gql` - fragment ListItem on CurrentBlocksPageBlocksListBlockListItemsListItem { - list_item { - list_item_style - subtitle - title - } - } -` - -export const ListItemExternalLink = gql` - fragment ListItemExternalLink on CurrentBlocksPageBlocksListBlockListItemsListItemExternalLink { - list_item_external_link { - link { - href - title - } - list_item_style - subtitle - } - } -` - -export const ListBlock = gql` - fragment ListBlock on CurrentBlocksPageBlocksList { - list { - list_items { - __typename - ...ListItem - ...ListItemExternalLink - } - title - } - } - ${ListItem} - ${ListItemExternalLink} -` diff --git a/packages/trpc/lib/graphql/Fragments/Blocks/Puff.graphql.ts b/packages/trpc/lib/graphql/Fragments/Blocks/Puff.graphql.ts deleted file mode 100644 index fa71ee3cc..000000000 --- a/packages/trpc/lib/graphql/Fragments/Blocks/Puff.graphql.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { gql } from "graphql-tag" - -import { Puff } from "../Puff.graphql" - -export const PuffBlock = gql` - fragment PuffBlock on CurrentBlocksPageBlocksPuffs { - puffs { - puffs { - ... on CurrentBlocksPageBlocksPuffsBlockPuffsPuff { - puff { - ...Puff - } - } - } - } - } - ${Puff} -` diff --git a/packages/trpc/lib/graphql/Fragments/Blocks/Text.graphql.ts b/packages/trpc/lib/graphql/Fragments/Blocks/Text.graphql.ts deleted file mode 100644 index 9e8c05200..000000000 --- a/packages/trpc/lib/graphql/Fragments/Blocks/Text.graphql.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "../SysAsset.graphql" - -export const TextBlock = gql` - fragment TextBlock on CurrentBlocksPageBlocksText { - text { - content { - embedded_itemsConnection { - totalCount - edges { - node { - __typename - ...SysAsset - } - } - } - json - } - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/Breadcrumbs/CurrentBlocksPage.graphql.ts b/packages/trpc/lib/graphql/Fragments/Breadcrumbs/CurrentBlocksPage.graphql.ts deleted file mode 100644 index 926076f18..000000000 --- a/packages/trpc/lib/graphql/Fragments/Breadcrumbs/CurrentBlocksPage.graphql.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { gql } from "graphql-tag" - -export const CurrentBlocksPageBreadcrumbs = gql` - fragment CurrentBlocksPageBreadcrumbs on CurrentBlocksPage { - breadcrumbs { - parents { - href - title - } - title - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/Breadcrumbs/PromoCampaignPage.graphql.ts b/packages/trpc/lib/graphql/Fragments/Breadcrumbs/PromoCampaignPage.graphql.ts deleted file mode 100644 index 0983b9d1d..000000000 --- a/packages/trpc/lib/graphql/Fragments/Breadcrumbs/PromoCampaignPage.graphql.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { gql } from "graphql-tag" - -import { System } from "../System.graphql" - -export const PromoCampaignPageBreadcrumb = gql` - fragment PromoCampaignPageBreadcrumb on PromoCampaignPage { - web { - breadcrumbs { - title - } - } - system { - ...System - } - url - } - ${System} -` - -export const PromoCampaignPageBreadcrumbRef = gql` - fragment PromoCampaignPageBreadcrumbRef on PromoCampaignPage { - web { - breadcrumbs { - title - } - } - system { - ...System - } - } - ${System} -` diff --git a/packages/trpc/lib/graphql/Fragments/Contact.graphql.ts b/packages/trpc/lib/graphql/Fragments/Contact.graphql.ts deleted file mode 100644 index 92f393a37..000000000 --- a/packages/trpc/lib/graphql/Fragments/Contact.graphql.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { gql } from "graphql-tag" - -export const ContactExtraInfo = gql` - fragment ContactExtraInfo on ContactBlockSectionsExtraInfo { - extra_info { - text - } - } -` - -export const ContactMailingAddress = gql` - fragment ContactMailingAddress on ContactBlockSectionsMailingAddress { - mailing_address { - city - country - name - street - zip - } - } -` - -export const ContactPhone = gql` - fragment ContactPhone on ContactBlockSectionsPhone { - phone { - number - title - } - } -` - -export const ContactTitle = gql` - fragment ContactTitle on ContactBlockSectionsTitle { - title { - text - } - } -` - -export const ContactVisitingAddress = gql` - fragment ContactVisitingAddress on ContactBlockSectionsVisitingAddress { - visiting_address { - city - country - street - zip - } - } -` - -export const Contact = gql` - fragment Contact on ContactBlock { - sections { - __typename - ...ContactExtraInfo - ...ContactMailingAddress - ...ContactPhone - ...ContactTitle - ...ContactVisitingAddress - } - system { - locale - uid - } - } - ${ContactExtraInfo} - ${ContactMailingAddress} - ${ContactPhone} - ${ContactTitle} - ${ContactVisitingAddress} -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql.ts deleted file mode 100644 index ed6c8bc86..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "../SysAsset.graphql" - -export const CurrentFooterAppDownloads = gql` - fragment CurrentFooterAppDownloads on CurrentFooter { - app_downloads { - title - app_store { - href - imageConnection { - edges { - node { - ...SysAsset - } - } - } - } - google_play { - href - imageConnection { - edges { - node { - ...SysAsset - } - } - } - } - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Logo.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/Logo.graphql.ts deleted file mode 100644 index 1fb4c6f33..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Logo.graphql.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "../SysAsset.graphql" - -export const Logo = gql` - fragment Logo on CurrentFooter { - logoConnection { - edges { - node { - ...SysAsset - } - } - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/MainLinks.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/MainLinks.graphql.ts deleted file mode 100644 index c9f62ef33..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/MainLinks.graphql.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { gql } from "graphql-tag" - -export const MainLinks = gql` - fragment MainLinks on Footer { - main_links { - title - open_in_new_tab - link { - href - title - } - pageConnection { - edges { - node { - __typename - ... on AccountPage { - title - url - } - ... on LoyaltyPage { - title - url - } - ... on ContentPage { - title - url - } - } - } - } - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Navigation.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/Navigation.graphql.ts deleted file mode 100644 index c5cd472eb..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Navigation.graphql.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { gql } from "graphql-tag" - -export const Navigation = gql` - fragment Navigation on CurrentFooter { - navigation { - links { - href - title - } - title - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/MainLinks.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/MainLinks.graphql.ts deleted file mode 100644 index 695c79edc..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/MainLinks.graphql.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { gql } from "graphql-tag" - -import { AccountPageRef } from "../../AccountPage/Ref.graphql" -import { ContentPageRef } from "../../ContentPage/Ref.graphql" -import { LoyaltyPageRef } from "../../LoyaltyPage/Ref.graphql" -import { System } from "../../System.graphql" - -export const MainLinksRef = gql` - fragment MainLinksRef on Footer { - __typename - main_links { - pageConnection { - edges { - node { - __typename - ...LoyaltyPageRef - ...ContentPageRef - ...AccountPageRef - } - } - } - } - system { - ...System - } - } - ${System} - ${LoyaltyPageRef} - ${AccountPageRef} - ${ContentPageRef} -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/SecondaryLinks.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/SecondaryLinks.graphql.ts deleted file mode 100644 index 12c2402c1..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/Refs/SecondaryLinks.graphql.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { gql } from "graphql-tag" - -import { AccountPageRef } from "../../AccountPage/Ref.graphql" -import { ContentPageRef } from "../../ContentPage/Ref.graphql" -import { LoyaltyPageRef } from "../../LoyaltyPage/Ref.graphql" -import { System } from "../../System.graphql" - -export const SecondaryLinksRef = gql` - fragment SecondaryLinksRef on Footer { - __typename - secondary_links { - links { - pageConnection { - edges { - node { - __typename - ...LoyaltyPageRef - ...ContentPageRef - ...AccountPageRef - } - } - } - } - } - system { - ...System - } - } - ${System} - ${LoyaltyPageRef} - ${AccountPageRef} - ${ContentPageRef} -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/SecondaryLinks.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/SecondaryLinks.graphql.ts deleted file mode 100644 index 694cd33a8..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/SecondaryLinks.graphql.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { gql } from "graphql-tag" - -export const SecondaryLinks = gql` - fragment SecondaryLinks on Footer { - secondary_links { - title - links { - title - open_in_new_tab - pageConnection { - edges { - node { - __typename - } - } - } - link { - href - title - } - } - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/SocialMedia.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/SocialMedia.graphql.ts deleted file mode 100644 index c1013ea06..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/SocialMedia.graphql.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { gql } from "graphql-tag" - -export const CurrentFooterSocialMedia = gql` - fragment CurrentFooterSocialMedia on CurrentFooter { - social_media { - title - facebook { - href - title - } - instagram { - href - title - } - twitter { - href - title - } - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql.ts b/packages/trpc/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql.ts deleted file mode 100644 index e6d129033..000000000 --- a/packages/trpc/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "../SysAsset.graphql" - -export const TripAdvisor = gql` - fragment TripAdvisor on CurrentFooter { - trip_advisor { - logoConnection { - edges { - node { - ...SysAsset - } - } - } - title - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/Footer/Refs/TertiaryLinks.graphql.ts b/packages/trpc/lib/graphql/Fragments/Footer/Refs/TertiaryLinks.graphql.ts deleted file mode 100644 index 3e118fdaf..000000000 --- a/packages/trpc/lib/graphql/Fragments/Footer/Refs/TertiaryLinks.graphql.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { gql } from "graphql-tag" - -import { AccountPageRef } from "../../AccountPage/Ref.graphql" -import { ContentPageRef } from "../../ContentPage/Ref.graphql" -import { LoyaltyPageRef } from "../../LoyaltyPage/Ref.graphql" - -export const TertiaryLinksRef = gql` - fragment TertiaryLinksRef on Footer { - __typename - tertiary_links { - pageConnection { - edges { - node { - __typename - ...LoyaltyPageRef - ...ContentPageRef - ...AccountPageRef - } - } - } - } - system { - ...System - } - } - ${LoyaltyPageRef} - ${AccountPageRef} - ${ContentPageRef} -` diff --git a/packages/trpc/lib/graphql/Fragments/Grid.graphql.ts b/packages/trpc/lib/graphql/Fragments/Grid.graphql.ts deleted file mode 100644 index db75a97b7..000000000 --- a/packages/trpc/lib/graphql/Fragments/Grid.graphql.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { gql } from "graphql-tag" - -export const Grid = gql` - fragment Grid on Grid { - columns { - span - rows { - rowConnection { - edges { - node { - __typename - ... on Card { - title - } - } - } - } - } - } - } -` diff --git a/packages/trpc/lib/graphql/Fragments/Hero.graphql.ts b/packages/trpc/lib/graphql/Fragments/Hero.graphql.ts deleted file mode 100644 index f8af34678..000000000 --- a/packages/trpc/lib/graphql/Fragments/Hero.graphql.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "./SysAsset.graphql" - -export const Hero = gql` - fragment Hero on Hero { - imagesConnection { - totalCount - edges { - node { - ...SysAsset - } - } - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/PageLink/CurrentBlocksPageLink.graphql.ts b/packages/trpc/lib/graphql/Fragments/PageLink/CurrentBlocksPageLink.graphql.ts deleted file mode 100644 index 9edeec416..000000000 --- a/packages/trpc/lib/graphql/Fragments/PageLink/CurrentBlocksPageLink.graphql.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { gql } from "graphql-tag" - -import { System } from "../System.graphql" - -export const CurrentBlocksPageLink = gql` - fragment CurrentBlocksPageLink on CurrentBlocksPage { - title - url - system { - ...System - } - } - ${System} -` diff --git a/packages/trpc/lib/graphql/Fragments/PageLink/CurrentContentPageLink.graphql.ts b/packages/trpc/lib/graphql/Fragments/PageLink/CurrentContentPageLink.graphql.ts deleted file mode 100644 index 9edeec416..000000000 --- a/packages/trpc/lib/graphql/Fragments/PageLink/CurrentContentPageLink.graphql.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { gql } from "graphql-tag" - -import { System } from "../System.graphql" - -export const CurrentBlocksPageLink = gql` - fragment CurrentBlocksPageLink on CurrentBlocksPage { - title - url - system { - ...System - } - } - ${System} -` diff --git a/packages/trpc/lib/graphql/Fragments/Preamble.graphql.ts b/packages/trpc/lib/graphql/Fragments/Preamble.graphql.ts deleted file mode 100644 index f4ee592e2..000000000 --- a/packages/trpc/lib/graphql/Fragments/Preamble.graphql.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "./SysAsset.graphql" - -export const Preamble = gql` - fragment Preamble on CurrentBlocksPage { - preamble { - text { - json - embedded_itemsConnection(limit: 30) { - edges { - node { - __typename - ...SysAsset - } - } - } - } - } - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Fragments/Puff.graphql.ts b/packages/trpc/lib/graphql/Fragments/Puff.graphql.ts deleted file mode 100644 index 5c9d80f93..000000000 --- a/packages/trpc/lib/graphql/Fragments/Puff.graphql.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { gql } from "graphql-tag" - -import { SysAsset } from "./SysAsset.graphql" - -export const Puff = gql` - fragment Puff on Puff { - imageConnection { - edges { - node { - ...SysAsset - } - } - } - puff_style - link { - href - title - } - text { - json - } - title - } - ${SysAsset} -` diff --git a/packages/trpc/lib/graphql/Query/Rewards.graphql.ts b/packages/trpc/lib/graphql/Query/Rewards.graphql.ts deleted file mode 100644 index 0046f4990..000000000 --- a/packages/trpc/lib/graphql/Query/Rewards.graphql.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { gql } from "graphql-tag" - -export const GetRewards = gql` - query GetRewards($locale: String!, $rewardIds: [String!]) { - all_reward(locale: $locale, where: { reward_id_in: $rewardIds }) { - items { - taxonomies { - term_uid - } - label - grouped_label - description - grouped_description - value - reward_id - } - } - } -` diff --git a/scripts/README-convert-graphql-to-ts.md b/scripts/README-convert-graphql-to-ts.md deleted file mode 100644 index 26a4831b0..000000000 --- a/scripts/README-convert-graphql-to-ts.md +++ /dev/null @@ -1,150 +0,0 @@ -# GraphQL to TypeScript Converter - -This script converts GraphQL files (`.graphql`) to TypeScript files (`.graphql.ts`) that use the `gql` template literal from `graphql-tag`. - -## Features - -- Converts individual fragments and queries into separate TypeScript exports -- Handles GraphQL imports (`#import`) and converts them to TypeScript imports -- Preserves fragment references and generates proper import statements -- Groups multiple imports from the same file -- Supports fragments, queries, mutations, and subscriptions -- Handles files with multiple operations - -## Usage - -### Basic Conversion - -Convert all GraphQL files in the project: - -```bash -yarn graphql:convert -``` - -Convert files matching a specific pattern: - -```bash -yarn graphql:convert "packages/trpc/**/*.graphql" -``` - -Convert a single file: - -```bash -yarn graphql:convert "path/to/file.graphql" -``` - -### Options - -- `--dry-run`: Preview what files would be converted without actually converting them -- `--delete-originals`: Delete original `.graphql` files after successful conversion -- `--help`, `-h`: Show help message - -### Examples - -Preview conversion: - -```bash -yarn graphql:convert --dry-run -``` - -Convert and delete originals: - -```bash -yarn graphql:convert --delete-originals -``` - -Convert specific directory: - -```bash -yarn graphql:convert "packages/trpc/lib/graphql/Fragments/**/*.graphql" -``` - -## Input Format - -### GraphQL Fragment - -```graphql -fragment Contact on ContactBlock { - sections { - __typename - } -} -``` - -### GraphQL Query with Imports - -```graphql -#import "../Fragments/System.graphql" -#import "../Fragments/Metadata.graphql" - -query GetData($locale: String!) { - data(locale: $locale) { - ...System - ...Metadata - } -} -``` - -## Output Format - -### TypeScript Fragment - -```typescript -import { gql } from "graphql-tag"; - -export const Contact = gql` - fragment Contact on ContactBlock { - sections { - __typename - } - } -`; -``` - -### TypeScript Query with Imports - -```typescript -import { gql } from "graphql-tag"; - -import { System } from "../Fragments/System.graphql"; -import { Metadata } from "../Fragments/Metadata.graphql"; - -export const GetData = gql` - query GetData($locale: String!) { - data(locale: $locale) { - ...System - ...Metadata - } - } - ${System} - ${Metadata} -`; -``` - -## How It Works - -1. **Parse GraphQL Files**: Reads `.graphql` files and extracts imports and operations -2. **Handle Imports**: Converts `#import` statements to TypeScript imports by: - - Reading the imported file to determine export names - - Converting paths from `.graphql` to `.graphql.ts` - - Grouping multiple imports from the same file -3. **Extract Operations**: Identifies fragments, queries, mutations, and subscriptions -4. **Generate TypeScript**: Creates TypeScript files with: - - `gql` template literals - - Proper import statements - - Named exports for each operation - -## Dependencies - -- `glob`: For file pattern matching -- `tsx`: For TypeScript execution -- `@types/node`: For Node.js types -- `graphql-tag`: For the `gql` template literal (runtime dependency) - -## Notes - -- The script preserves the original file structure and naming -- Fragment references (`...FragmentName`) are preserved in the GraphQL content -- Multiple operations in a single file are split into separate exports -- Import conflicts are avoided by using the exact export names from referenced files -- Generated files maintain the same directory structure with `.graphql.ts` extension diff --git a/scripts/convert-graphql-to-ts.ts b/scripts/convert-graphql-to-ts.ts deleted file mode 100644 index ab23c5bfc..000000000 --- a/scripts/convert-graphql-to-ts.ts +++ /dev/null @@ -1,373 +0,0 @@ -#!/usr/bin/env tsx - -import * as fs from "fs"; -import * as path from "path"; -import { glob } from "glob"; - -interface ImportInfo { - fragmentName: string; - importPath: string; - variableName: string; -} - -interface GraphQLFile { - content: string; - imports: ImportInfo[]; - operations: Array<{ name: string; content: string }>; -} - -/** - * Extracts individual fragments/operations from GraphQL content - */ -function extractOperations( - content: string -): Array<{ name: string; content: string }> { - const operations: Array<{ name: string; content: string }> = []; - - // Split content into lines for processing - const lines = content.split("\n"); - let currentOperation: { name: string; content: string[] } | null = null; - let braceCount = 0; - - for (const line of lines) { - const trimmedLine = line.trim(); - - // Check if this line starts a new operation - const fragmentMatch = trimmedLine.match(/^fragment\s+(\w+)\s+on/); - const queryMatch = trimmedLine.match(/^query\s+(\w+)\s*[({]/); - const mutationMatch = trimmedLine.match(/^mutation\s+(\w+)\s*[({]/); - const subscriptionMatch = trimmedLine.match( - /^subscription\s+(\w+)\s*[({]/ - ); - - if (fragmentMatch || queryMatch || mutationMatch || subscriptionMatch) { - // Finish previous operation if exists - if (currentOperation && currentOperation.content.length > 0) { - operations.push({ - name: currentOperation.name, - content: currentOperation.content.join("\n").trim(), - }); - } - - // Start new operation - const operationName = (fragmentMatch || - queryMatch || - mutationMatch || - subscriptionMatch)![1]; - currentOperation = { - name: operationName, - content: [line], - }; - - // Count braces in the current line - braceCount = - (line.match(/{/g) || []).length - - (line.match(/}/g) || []).length; - } else if (currentOperation) { - // Add line to current operation - currentOperation.content.push(line); - - // Update brace count - braceCount += - (line.match(/{/g) || []).length - - (line.match(/}/g) || []).length; - - // If we've closed all braces, this operation is complete - if (braceCount === 0 && trimmedLine.includes("}")) { - operations.push({ - name: currentOperation.name, - content: currentOperation.content.join("\n").trim(), - }); - currentOperation = null; - } - } - } - - // Handle case where file ends without closing brace - if (currentOperation && currentOperation.content.length > 0) { - operations.push({ - name: currentOperation.name, - content: currentOperation.content.join("\n").trim(), - }); - } - - return operations; -} - -/** - * Generates TypeScript content from parsed GraphQL - */ -function generateTypeScriptContent(parsedFile: GraphQLFile): string { - const { imports, operations } = parsedFile; - - let output = 'import { gql } from "graphql-tag"\n'; - - // Add imports for fragments - group by import path to avoid duplicates - if (imports.length > 0) { - output += "\n"; - - const importsByPath = new Map(); - for (const imp of imports) { - if (!importsByPath.has(imp.importPath)) { - importsByPath.set(imp.importPath, []); - } - if ( - !importsByPath.get(imp.importPath)!.includes(imp.variableName) - ) { - importsByPath.get(imp.importPath)!.push(imp.variableName); - } - } - - for (const [importPath, variableNames] of importsByPath) { - output += `import { ${variableNames.join(", ")} } from "${importPath}"\n`; - } - } - - output += "\n"; - - // Generate exports for each operation - if (operations.length === 0) { - // If no operation names found, use a default export - const defaultName = "GraphQLDocument"; - const fragmentSubstitutions = - imports.length > 0 - ? "\n" + - imports.map((imp) => `\${${imp.variableName}}`).join("\n") - : ""; - output += `export const ${defaultName} = gql\`\n${parsedFile.content}${fragmentSubstitutions}\n\`\n`; - } else { - for (let i = 0; i < operations.length; i++) { - const operation = operations[i]; - const fragmentSubstitutions = - imports.length > 0 - ? "\n" + - imports.map((imp) => `\${${imp.variableName}}`).join("\n") - : ""; - output += `export const ${operation.name} = gql\`\n${operation.content}${fragmentSubstitutions}\n\`\n`; - - if (i < operations.length - 1) { - output += "\n"; - } - } - } - - return output; -} - -/** - * Converts a GraphQL import path to a TypeScript import path - */ -function convertImportPath(graphqlPath: string): string { - // Remove the .graphql extension and add .graphql - const withoutExt = graphqlPath.replace(/\.graphql$/, ""); - return `${withoutExt}.graphql`; -} - -/** - * Gets the export names from a GraphQL file by analyzing the fragments it contains - */ -function getExportNamesFromGraphQLFile(filePath: string): string[] { - try { - const content = fs.readFileSync(filePath, "utf-8"); - const operations = extractOperations(content); - return operations.map((op) => op.name); - } catch { - // If file doesn't exist or can't be read, try to infer from path - console.warn( - `Warning: Could not read ${filePath}, inferring export name from path` - ); - return [getVariableNameFromPath(filePath)]; - } -} - -/** - * Extracts the expected variable name from a file path - */ -function getVariableNameFromPath(filePath: string): string { - const basename = path.basename(filePath, ".graphql"); - - // Convert kebab-case or snake_case to PascalCase - return basename - .split(/[-_]/) - .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) - .join(""); -} - -/** - * Parses a GraphQL file and extracts imports and content - */ -function parseGraphQLFile(filePath: string): GraphQLFile { - const content = fs.readFileSync(filePath, "utf-8"); - const lines = content.split("\n"); - const imports: ImportInfo[] = []; - const contentLines: string[] = []; - - for (const line of lines) { - const trimmedLine = line.trim(); - - if (trimmedLine.startsWith("#import")) { - // Extract import path from #import "path" - const match = trimmedLine.match(/#import\s+"([^"]+)"/); - if (match) { - const importPath = match[1]; - const fullImportPath = path.resolve( - path.dirname(filePath), - importPath - ); - const exportNames = - getExportNamesFromGraphQLFile(fullImportPath); - const tsImportPath = convertImportPath(importPath); - - // Add all exports from the imported file - for (const exportName of exportNames) { - imports.push({ - fragmentName: exportName, - importPath: tsImportPath, - variableName: exportName, - }); - } - } - } else if (trimmedLine && !trimmedLine.startsWith("#")) { - contentLines.push(line); - } - } - - const cleanContent = contentLines.join("\n").trim(); - const operations = extractOperations(cleanContent); - - return { - content: cleanContent, - imports, - operations, - }; -} - -/** - * Converts a single GraphQL file to TypeScript - */ -function convertFile(graphqlPath: string): void { - try { - console.log(`Converting: ${graphqlPath}`); - - const parsed = parseGraphQLFile(graphqlPath); - const tsContent = generateTypeScriptContent(parsed); - const tsPath = graphqlPath.replace(/\.graphql$/, ".graphql.ts"); - - fs.writeFileSync(tsPath, tsContent, "utf-8"); - console.log(`✓ Created: ${tsPath}`); - - // Optionally remove the original .graphql file - // Uncomment the next line if you want to delete the original files - // fs.unlinkSync(graphqlPath) - } catch (error) { - console.error(`Error converting ${graphqlPath}:`, error); - } -} - -/** - * Main function to convert all GraphQL files - */ -async function main() { - const args = process.argv.slice(2); - - if (args.includes("--help") || args.includes("-h")) { - console.log(` -GraphQL to TypeScript Converter - -Converts GraphQL files (.graphql) to TypeScript files (.graphql.ts) using gql template literals. - -Usage: tsx convert-graphql-to-ts.ts [options] [pattern] - -Options: - --help, -h Show this help message - --dry-run Show what files would be converted without converting them - --delete-originals Delete original .graphql files after conversion - -Examples: - tsx convert-graphql-to-ts.ts # Convert all .graphql files - tsx convert-graphql-to-ts.ts "packages/trpc/**/*.graphql" # Convert specific pattern - tsx convert-graphql-to-ts.ts --dry-run # Preview conversion - tsx convert-graphql-to-ts.ts --delete-originals # Convert and delete originals - -Features: - • Converts fragments, queries, mutations, and subscriptions - • Handles GraphQL imports (#import) and converts to TypeScript imports - • Preserves fragment references and generates proper import statements - • Groups multiple imports from the same file - • Splits multiple operations into separate exports -`); - return; - } - - const dryRun = args.includes("--dry-run"); - const deleteOriginals = args.includes("--delete-originals"); - - // Get the pattern from args or use default - const pattern = args.find((arg) => !arg.startsWith("--")) || "**/*.graphql"; - - console.log(`🔍 Searching for GraphQL files with pattern: ${pattern}`); - - try { - const files = await glob(pattern, { - ignore: ["**/*.graphql.ts", "**/node_modules/**"], - }); - - if (files.length === 0) { - console.log("❌ No GraphQL files found."); - return; - } - - console.log(`📁 Found ${files.length} GraphQL files`); - - if (dryRun) { - console.log("\n📋 Files that would be converted:"); - files.forEach((file, index) => { - console.log( - ` ${index + 1}. ${file} → ${file.replace(/\.graphql$/, ".graphql.ts")}` - ); - }); - console.log("\n🔍 --dry-run mode: No files were converted."); - return; - } - - console.log("\n🔄 Converting files..."); - let successCount = 0; - let errorCount = 0; - - for (let i = 0; i < files.length; i++) { - const file = files[i]; - try { - console.log( - `📝 [${i + 1}/${files.length}] Converting: ${file}` - ); - convertFile(file); - successCount++; - - if (deleteOriginals) { - fs.unlinkSync(file); - console.log(`🗑️ Deleted: ${file}`); - } - } catch (error) { - console.error(`❌ Error converting ${file}:`, error); - errorCount++; - } - } - - console.log(`\n✅ Conversion complete!`); - console.log(` 📈 Successfully converted: ${successCount} files`); - if (errorCount > 0) { - console.log(` ❌ Errors: ${errorCount} files`); - } - if (deleteOriginals && successCount > 0) { - console.log(` 🗑️ Deleted: ${successCount} original files`); - } - } catch (error) { - console.error("❌ Error:", error); - process.exit(1); - } -} - -// Run the script -if (import.meta.url === `file://${process.argv[1]}`) { - main().catch(console.error); -}