Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Add rover dev restarts for add/delete subgraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-watson committed Apr 8, 2024
1 parent 9ca8e56 commit c237266
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commands/local-supergraph-designs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/workbench/file-system/fileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ export class FileProvider {

if (shouldRefresh)
StateManager.instance.localSupergraphTreeDataProvider.refresh();

await Rover.instance.tryRestartRoverDev(path);
}

workbenchFileByGraphName(name: string) {
Expand Down
15 changes: 15 additions & 0 deletions src/workbench/rover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 } = {};
Expand Down Expand Up @@ -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[];
Expand Down

0 comments on commit c237266

Please sign in to comment.