diff --git a/connect/src/wg/cosmo/platform/v1/platform_pb.ts b/connect/src/wg/cosmo/platform/v1/platform_pb.ts index 01bd57d8ee..314ec37b2f 100644 --- a/connect/src/wg/cosmo/platform/v1/platform_pb.ts +++ b/connect/src/wg/cosmo/platform/v1/platform_pb.ts @@ -3985,6 +3985,11 @@ export class MigrateFromApolloRequest extends Message */ apiKey = ""; + /** + * @generated from field: string variantName = 2; + */ + variantName = ""; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -3994,6 +3999,7 @@ export class MigrateFromApolloRequest extends Message static readonly typeName = "wg.cosmo.platform.v1.MigrateFromApolloRequest"; static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "apiKey", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "variantName", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): MigrateFromApolloRequest { diff --git a/controlplane/src/core/bufservices/PlatformService.ts b/controlplane/src/core/bufservices/PlatformService.ts index cce2c12f9c..499da3fc8e 100644 --- a/controlplane/src/core/bufservices/PlatformService.ts +++ b/controlplane/src/core/bufservices/PlatformService.ts @@ -1789,10 +1789,23 @@ export default function (opts: RouterOptions): Partial { @@ -49,9 +59,11 @@ export default class ApolloMigrator { } // fetches the schemas of the subgraphs and the routing url of the federated graph - public async fetchGraphDetails({ graphID, variantName }: { graphID: string; variantName: string }): Promise<{ + public async fetchGraphDetails({ graphID }: { graphID: string }): Promise<{ + success: boolean; fedGraphRoutingURL: string; subgraphs: MigrationSubgraph[]; + errorMessage?: string; }> { const headers = new Headers(); headers.append('X-API-KEY', this.apiKey); @@ -91,20 +103,31 @@ export default class ApolloMigrator { body: graphql, }); if (response.status !== 200) { - throw new Error('Could not fetch the subgraphs from apollo.'); + return { + success: false, + fedGraphRoutingURL: '', + subgraphs: [], + errorMessage: 'Could not fetch the graphs from apollo.', + }; } const body = await response.json(); const data = body.data; const variants: any[] = data.graph.variants; - const variant = variants.find((v: { name: string }) => v.name === variantName); + const variant = variants.find((v: { name: string }) => v.name === this.variantName); if (!variant) { - throw new Error('Could not find the requested variant of the graph.'); + return { + success: false, + fedGraphRoutingURL: '', + subgraphs: [], + errorMessage: 'Could not find the requested variant of the graph.', + }; } const subgraphs: any[] = variant.subgraphs; return { + success: true, fedGraphRoutingURL: variant.url, subgraphs: subgraphs.map((subgraph) => { return { diff --git a/proto/wg/cosmo/platform/v1/platform.proto b/proto/wg/cosmo/platform/v1/platform.proto index be092b9a56..a906d31458 100644 --- a/proto/wg/cosmo/platform/v1/platform.proto +++ b/proto/wg/cosmo/platform/v1/platform.proto @@ -518,6 +518,7 @@ message RemoveInvitationResponse { message MigrateFromApolloRequest { string apiKey = 1; + string variantName = 2; } message MigrateFromApolloResponse { diff --git a/studio/src/components/federatedgraphs-cards.tsx b/studio/src/components/federatedgraphs-cards.tsx index 825e3e7063..733c9dd301 100644 --- a/studio/src/components/federatedgraphs-cards.tsx +++ b/studio/src/components/federatedgraphs-cards.tsx @@ -1,32 +1,46 @@ -import { useFireworks } from '@/hooks/use-fireworks'; -import { SubmitHandler, useZodForm } from '@/hooks/use-form'; -import { docsBaseURL } from '@/lib/constants'; -import { useChartData } from '@/lib/insights-helpers'; -import { ChevronDoubleRightIcon, CommandLineIcon } from '@heroicons/react/24/outline'; -import { useMutation } from '@tanstack/react-query'; -import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common_pb'; -import { migrateFromApollo } from '@wundergraph/cosmo-connect/dist/platform/v1/platform-PlatformService_connectquery'; -import { FederatedGraph } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb'; -import { getTime, parseISO, subDays } from 'date-fns'; -import Link from 'next/link'; -import { Dispatch, SetStateAction, useContext, useState } from 'react'; -import { Line, LineChart, ResponsiveContainer, XAxis } from 'recharts'; -import { z } from 'zod'; -import { UserContext } from './app-provider'; -import { ComposeStatusMessage } from './compose-status'; -import { ComposeStatusBulb } from './compose-status-bulb'; -import { EmptyState } from './empty-state'; -import { TimeAgo } from './time-ago'; -import { Button } from './ui/button'; -import { Card } from './ui/card'; -import { CLI } from './ui/cli'; -import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from './ui/dialog'; -import { Input } from './ui/input'; -import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'; -import { useToast } from './ui/use-toast'; -import { Logo } from './logo'; -import { SiApollographql } from 'react-icons/si'; -import { cn } from '@/lib/utils'; +import { useFireworks } from "@/hooks/use-fireworks"; +import { SubmitHandler, useZodForm } from "@/hooks/use-form"; +import { docsBaseURL } from "@/lib/constants"; +import { useChartData } from "@/lib/insights-helpers"; +import { + ChevronDoubleRightIcon, + CommandLineIcon, +} from "@heroicons/react/24/outline"; +import { useMutation } from "@tanstack/react-query"; +import { EnumStatusCode } from "@wundergraph/cosmo-connect/dist/common_pb"; +import { migrateFromApollo } from "@wundergraph/cosmo-connect/dist/platform/v1/platform-PlatformService_connectquery"; +import { FederatedGraph } from "@wundergraph/cosmo-connect/dist/platform/v1/platform_pb"; +import { getTime, parseISO, subDays } from "date-fns"; +import Link from "next/link"; +import { Dispatch, SetStateAction, useContext, useState } from "react"; +import { Line, LineChart, ResponsiveContainer, XAxis } from "recharts"; +import { z } from "zod"; +import { UserContext } from "./app-provider"; +import { ComposeStatusMessage } from "./compose-status"; +import { ComposeStatusBulb } from "./compose-status-bulb"; +import { EmptyState } from "./empty-state"; +import { TimeAgo } from "./time-ago"; +import { Button } from "./ui/button"; +import { Card } from "./ui/card"; +import { CLI } from "./ui/cli"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "./ui/dialog"; +import { Input } from "./ui/input"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "./ui/tooltip"; +import { useToast } from "./ui/use-toast"; +import { Logo } from "./logo"; +import { SiApollographql } from "react-icons/si"; +import { cn } from "@/lib/utils"; // this is required to render a blank line with LineChart const fallbackData = [ @@ -53,6 +67,9 @@ const MigrationDialog = ({ apiKey: z .string() .min(1, { message: "API Key must contain at least 1 character." }), + variantName: z + .string() + .min(1, { message: "Variant name must contain at least 1 character." }), }); type MigrateInput = z.infer; @@ -79,6 +96,7 @@ const MigrationDialog = ({ mutate( { apiKey: data.apiKey, + variantName: data.variantName, }, { onSuccess: (d) => { @@ -167,6 +185,19 @@ const MigrationDialog = ({ )} +
+ Graph Variant Name + + {errors.variantName && ( + + {errors.variantName.message} + + )} +