Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from semiotic-ai/feat/fetch-graphnode-endpoint
Browse files Browse the repository at this point in the history
feat: add fetch call to sql-studio-webapp when instancing ResultsProv…
  • Loading branch information
ricardo-rp authored Mar 20, 2024
2 parents 487b3cd + 088ff5a commit 274b861
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/providers/results.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import * as vscode from 'vscode';
import { IQueryResult, executeSQL, ISubgraphInfo } from '../service';
import { write as writeCSV } from '../filetypes/csv';
import fetch from 'node-fetch';

class ResultsProvider implements vscode.WebviewViewProvider {
public static readonly viewType = 'tabularResult';
private static readonly __knownPaths?: { [key: string]: string } = vscode.workspace
.getConfiguration('graphsql')
.get('paths');
private static readonly __gateway?: string = vscode.workspace
.getConfiguration('graphsql')
.get('gateway');
private static __gateway?: string = vscode.workspace.getConfiguration('graphsql').get('gateway');

private _view?: vscode.WebviewView;

private abortController?: AbortController;

constructor(private readonly _extensionUri: vscode.Uri) {}
constructor(private readonly _extensionUri: vscode.Uri) {
ResultsProvider.fetchGateway();
}

private static async fetchGateway() {
try {
const response = await fetch('https://sql-studio-webapp.vercel.app/graph-node-endpoint');
const gateway = await response.text();
ResultsProvider.__gateway = gateway;
} catch (error) {
vscode.window.showErrorMessage('Failed to fetch gateway endpoint.');
}
}

public resolveWebviewView(
webviewView: vscode.WebviewView,
Expand Down Expand Up @@ -57,12 +68,12 @@ class ResultsProvider implements vscode.WebviewViewProvider {
throw new Error(`${info.displayName} is not yet supported/indexed.`);
}

const enpoint = `${ResultsProvider.__gateway}/${path}`;
const endpoint = `${ResultsProvider.__gateway}/${path}`;

this.abortController = new AbortController();

await this.postMessage({ type: 'start', data: info.image });
const result = await executeSQL(enpoint, query!, this.abortController.signal);
const result = await executeSQL(endpoint, query!, this.abortController.signal);
await this.postMessage({ type: 'finish', data: result });
} catch (error: any) {
await this.postMessage({ type: 'clear' });
Expand Down

0 comments on commit 274b861

Please sign in to comment.