diff --git a/src/commands/local-supergraph-designs.ts b/src/commands/local-supergraph-designs.ts index cf969a5..a91e8f9 100644 --- a/src/commands/local-supergraph-designs.ts +++ b/src/commands/local-supergraph-designs.ts @@ -362,7 +362,7 @@ export async function addSubgraph(item?: SubgraphSummaryTreeItem) { } else { const wbFile = FileProvider.instance.workbenchFileFromPath(wbFilePath); let schemaString = - 'extend schema \n\t@link(url: "https://specs.apollo.dev/federation/v", import: ["@key"])\n\ntype Product @key(fields:"id") { \n\tid: ID!\n}'; + 'extend schema \n\t@link(url: "https://specs.apollo.dev/federation/v2.7", import: ["@key"])\n\ntype Product @key(fields:"id") { \n\tid: ID!\n}'; if (Object.keys(wbFile.subgraphs).length == 0) { schemaString += '\ntype Query {\n\tproducts: [Product]\n}'; } @@ -399,7 +399,7 @@ export async function addSubgraph(item?: SubgraphSummaryTreeItem) { await FileProvider.instance.writeWorkbenchConfig(wbFilePath, wbFile); } } -// } + export async function deleteSubgraph(item?: SubgraphTreeItem) { const wbFilePath = item ? item.wbFilePath : await whichDesign(); if (!wbFilePath) return; diff --git a/src/workbench/file-system/fileProvider.ts b/src/workbench/file-system/fileProvider.ts index b817e42..d8838d3 100644 --- a/src/workbench/file-system/fileProvider.ts +++ b/src/workbench/file-system/fileProvider.ts @@ -468,6 +468,8 @@ export class FileProvider { if (shouldRefresh) StateManager.instance.localSupergraphTreeDataProvider.refresh(); + + await Rover.instance.tryRestartRoverDev(path); } workbenchFileByGraphName(name: string) { diff --git a/src/workbench/rover.ts b/src/workbench/rover.ts index 1a6f4ba..b4026dd 100644 --- a/src/workbench/rover.ts +++ b/src/workbench/rover.ts @@ -30,6 +30,7 @@ import { URI } from 'vscode-uri'; export class Rover { private static _instance: Rover; + private wbFilePath: string = ''; static get instance(): Rover { if (!this._instance) this._instance = new Rover(); @@ -442,6 +443,7 @@ export class Rover { this.stopRoverDev(); } + this.wbFilePath = wbFilePath; const wbFile = FileProvider.instance.workbenchFileFromPath(wbFilePath); const subgraphNames = Object.keys(wbFile.subgraphs); const subgraphsToMock: { [name: string]: Subgraph } = {}; @@ -521,6 +523,19 @@ export class Rover { statusBar.hide(); } + /** + * If rover dev is already running, it will be restarted with the same config + * If rover dev is not running, nothing will be changed. + * We need to do this for adding or removing subgraphs from a config file because rover dev doesn't currently watch for those changes. + * See https://github.com/apollographql/rover/issues/1885. + */ + async tryRestartRoverDev(wbFilePath: string) { + if (this.wbFilePath == wbFilePath && this.primaryDevTerminal) { + this.stopRoverDev(); + await this.startRoverDev(this.wbFilePath); + } + } + static extractDefinedEntities(schema: string) { const entities: { [entity: string]: FieldWithType[];