Skip to content

Commit 922fa0b

Browse files
VSCode: Schema tag switching (#632)
* VSCode Schema Tag Switching Enable developing against different schema tags by allowing the user to choose a tag from a dropdown. * Allow publishing to a specific tag from the CLI * Server cleanup, split out loading handler * Extension DX improvement * Conditionally and more explicitly add tag key since it can be undefined * Allow for a keyless config (env only). This will eventually be enforced. * Prevent loading engine data without an API key. + good opportunity to combine requests for gathering engine data. * Key from .env should take precedence * Add proper truthy/falsey checking to prevent possible type errors * Remove click handler from status bar and add schema switch command to command palette
1 parent f4c556c commit 922fa0b

18 files changed

Lines changed: 472 additions & 217 deletions

File tree

package-lock.json

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"prettier": "1.14.2",
7777
"ts-jest": "^23.1.4",
7878
"ts-node": "^7.0.1",
79+
"tsc-watch": "^1.0.30",
7980
"tslib": "^1.9.3",
8081
"typescript": "^3.0.3",
8182
"vsce": "^1.46.0"

packages/apollo-language-server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"installServer": "installServerIntoExtension ../apollo-vscode ./package.json ./tsconfig.json && ./copy-apollo-libs.sh",
1818
"clean": "rm -rf ../apollo-vscode/server",
1919
"prebuild": "npm run clean",
20-
"build": "npm run installServer && tsc -p .",
21-
"watch": "npm run installServer && tsc -w -p .",
22-
"watchOnly": "tsc -w -p .",
20+
"build": "npm run installServer && tsc",
21+
"watch": "npm run installServer && tsc-watch --onSuccess \"./copy-apollo-libs.sh\"",
22+
"watchOnly": "tsc -w",
2323
"prepare": "npm run build"
2424
},
2525
"engines": {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { IConnection, NotificationType } from "vscode-languageserver";
2+
3+
export class LoadingHandler {
4+
constructor(private connection: IConnection) {}
5+
private latestLoadingToken = 0;
6+
async handle<T>(message: string, value: Promise<T>): Promise<T> {
7+
const token = this.latestLoadingToken;
8+
this.latestLoadingToken += 1;
9+
this.connection.sendNotification(
10+
new NotificationType<any, void>("apollographql/loading"),
11+
{ message, token }
12+
);
13+
try {
14+
const ret = await value;
15+
this.connection.sendNotification(
16+
new NotificationType<any, void>("apollographql/loadingComplete"),
17+
token
18+
);
19+
return ret;
20+
} catch (e) {
21+
this.connection.sendNotification(
22+
new NotificationType<any, void>("apollographql/loadingComplete"),
23+
token
24+
);
25+
this.showError(`Error in "${message}": ${e}`);
26+
throw e;
27+
}
28+
}
29+
handleSync<T>(message: string, value: () => T): T {
30+
const token = this.latestLoadingToken;
31+
this.latestLoadingToken += 1;
32+
this.connection.sendNotification(
33+
new NotificationType<any, void>("apollographql/loading"),
34+
{ message, token }
35+
);
36+
try {
37+
const ret = value();
38+
this.connection.sendNotification(
39+
new NotificationType<any, void>("apollographql/loadingComplete"),
40+
token
41+
);
42+
return ret;
43+
} catch (e) {
44+
this.connection.sendNotification(
45+
new NotificationType<any, void>("apollographql/loadingComplete"),
46+
token
47+
);
48+
this.showError(`Error in "${message}": ${e}`);
49+
throw e;
50+
}
51+
}
52+
showError(message: string) {
53+
this.connection.window.showErrorMessage(message);
54+
}
55+
}

0 commit comments

Comments
 (0)