Skip to content

Commit 57c880c

Browse files
reworked open explorer to use services (#81)
1 parent d59e7a6 commit 57c880c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/commands/openExplorer.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import * as vscode from "vscode";
77
import * as path from "path";
88
import * as fs from "fs";
9-
import { execSync } from "child_process";
109
import { StepZenError, handleError } from "../errors";
1110
import { StepZenConfig } from "../types";
1211
import { services } from "../services";
@@ -19,16 +18,19 @@ import { FILE_PATTERNS, MESSAGES, UI } from "../utils/constants";
1918
* @param workspaceFolderPath Path to the workspace folder containing StepZen config
2019
* @returns Object with StepZen account, domain, API key, and endpoint
2120
*/
22-
function getStepZenInfo(workspaceFolderPath: string): {
21+
async function getStepZenInfo(workspaceFolderPath: string): Promise<{
2322
account: string;
2423
domain: string;
2524
apiKey: string;
2625
endpoint: string;
27-
} {
26+
}> {
2827
try {
29-
const account = execSync("stepzen whoami --account").toString().trim();
30-
const domain = execSync("stepzen whoami --domain").toString().trim();
31-
const apiKey = execSync("stepzen whoami --apikey").toString().trim();
28+
// Use CLI service instead of execSync calls
29+
const [account, domain, apiKey] = await Promise.all([
30+
services.cli.getAccount(),
31+
services.cli.getDomain(),
32+
services.cli.getApiKey()
33+
]);
3234

3335
const configPath = path.join(workspaceFolderPath, FILE_PATTERNS.CONFIG_FILE);
3436
if (!fs.existsSync(configPath)) {
@@ -69,7 +71,7 @@ function getStepZenInfo(workspaceFolderPath: string): {
6971
*
7072
* @param context The VS Code extension context
7173
*/
72-
export function openQueryExplorer(context: vscode.ExtensionContext) {
74+
export async function openQueryExplorer(context: vscode.ExtensionContext) {
7375
try {
7476
services.logger.info("Starting Open Query Explorer command");
7577

@@ -97,7 +99,7 @@ export function openQueryExplorer(context: vscode.ExtensionContext) {
9799

98100
let stepzenInfo;
99101
try {
100-
stepzenInfo = getStepZenInfo(workspaceFolderPath);
102+
stepzenInfo = await getStepZenInfo(workspaceFolderPath);
101103
services.logger.info(`Retrieved StepZen info for endpoint: ${stepzenInfo.endpoint}`);
102104
} catch (err) {
103105
handleError(err);
@@ -176,7 +178,7 @@ export function openQueryExplorer(context: vscode.ExtensionContext) {
176178
</style>
177179
</head>
178180
<body>
179-
<div id="graphiql">Loading...</div>
181+
<div id="graphiql">${MESSAGES.EXPLORER_LOADING}</div>
180182
<script src="${reactUri}"></script>
181183
<script src="${reactDomUri}"></script>
182184
<script src="${graphiqlUri}"></script>

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export const MESSAGES = {
136136
SCHEMA_VISUALIZER_NO_TYPES_DESCRIPTION: "The schema visualizer could not find any GraphQL types to display. This might happen if your schema files are empty or contain only directives.",
137137
SCHEMA_VISUALIZER_LOADING: "Loading schema data...",
138138
SCHEMA_VISUALIZER_ERROR_TITLE: "Schema Visualization Error",
139+
EXPLORER_LOADING: "Loading...",
139140
} as const;
140141

141142
// Type definitions for better type safety

0 commit comments

Comments
 (0)