Skip to content

Commit

Permalink
Allow absolute paths for subgraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
WolffRuoff committed Oct 14, 2023
1 parent f6c79da commit 51b7d8a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class Subgraph extends vscode.TreeItem {
type: 'node',
request: 'launch',
name: this.label,
program: '${workspaceRoot}' + `/${this.filePath}/server.js`,
program: `${this.filePath}/server.js`,
skipFiles: ['<node_internals>/**'],
// eslint-disable-next-line @typescript-eslint/naming-convention
env: { NODE_ENV: 'local' },
Expand Down
32 changes: 27 additions & 5 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { commands, window, workspace } from 'vscode';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { isAbsolute, join } from 'path';
import axios from 'axios';

export const sampleSupergraphJson = {
Expand Down Expand Up @@ -38,24 +39,35 @@ export const generateTemplate = (rootPath: string) => {
mkdirSync(rootPath + '/.vscode');
}
if (!existsSync(rootPath + '/.rover-runner/supergraph.json')) {
writeFileSync(`${rootPath}/.rover-runner/supergraph.json`, JSON.stringify(sampleSupergraphJson, null, 2), 'utf-8');
writeFileSync(
`${rootPath}/.rover-runner/supergraph.json`,
JSON.stringify(sampleSupergraphJson, null, 2),
'utf-8'
);
commands.executeCommand('subgraphsList.refreshEntry');
}
};

export const isApolloConfigured = () => {
if (
workspace.getConfiguration().get('apolloStudioConfiguration.apolloKey', '').length > 0 &&
workspace.getConfiguration().get('apolloStudioConfiguration.apolloGraphRef', '').length > 0
workspace.getConfiguration().get('apolloStudioConfiguration.apolloKey', '')
.length > 0 &&
workspace
.getConfiguration()
.get('apolloStudioConfiguration.apolloGraphRef', '').length > 0
) {
return true;
}
return false;
};

export const fetchSubgraphUrls = async () => {
let apolloKey = workspace.getConfiguration().get('apolloStudioConfiguration.apolloKey', '');
let graphRef = workspace.getConfiguration().get('apolloStudioConfiguration.apolloGraphRef', '');
let apolloKey = workspace
.getConfiguration()
.get('apolloStudioConfiguration.apolloKey', '');
let graphRef = workspace
.getConfiguration()
.get('apolloStudioConfiguration.apolloGraphRef', '');
let body = {
operationName: 'GetSubgraphUrls',
query:
Expand Down Expand Up @@ -91,3 +103,13 @@ export const fetchSubgraphUrls = async () => {
return {};
});
};

export const makePathAbsolute = (filePath: string, configPath: string) => {
// If absolute or empty path, then return
if (isAbsolute(filePath) || filePath.length === 0) {
return filePath;
}
// Convert relative path to be absolute
const workspaceRoot = configPath.split('.rover-runner')[0];
return join(workspaceRoot, filePath);
};
5 changes: 3 additions & 2 deletions src/supergraph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'fs';
import { setTimeout } from 'timers/promises';
import { fetchSubgraphUrls } from './setup';
import { fetchSubgraphUrls, makePathAbsolute } from './setup';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState, window, workspace } from 'vscode';
import { SupergraphYaml, writeSupergraphYaml } from './supergraphYaml';
import { Subgraph } from './Subgraph';
Expand Down Expand Up @@ -35,14 +35,15 @@ export class Supergraph extends TreeItem {
const current = context.workspaceState.get(subgraphName + 'currentUrl', 'devUrl');
// Can either be Stopped or Running
const contextValue = context.workspaceState.get(subgraphName, 'StoppedSubgraph');
const filePath = makePathAbsolute(subgraphConfig.path, configPath);
return [
new Subgraph(
subgraphName,
current,
subgraphConfig.localUrl,
usedDevUrl,
contextValue,
subgraphConfig.path,
filePath,
TreeItemCollapsibleState.None
),
];
Expand Down

0 comments on commit 51b7d8a

Please sign in to comment.