Skip to content

Commit d6810d3

Browse files
committed
clean up service stats
1 parent be895c8 commit d6810d3

6 files changed

Lines changed: 26 additions & 29 deletions

File tree

packages/apollo-language-server/src/languageProvider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,17 @@ function symbolForFieldDefinition(
9393
export class GraphQLLanguageProvider {
9494
constructor(public workspace: GraphQLWorkspace) {}
9595

96-
async provideStatus() {
96+
async provideStats(uri?: DocumentUri) {
9797
if (
9898
this.workspace &&
9999
this.workspace.projects &&
100100
this.workspace.projects.length
101-
)
102-
return this.workspace.projects[0].getProjectStats();
101+
) {
102+
if (uri) {
103+
const project = this.workspace.projectForFile(uri);
104+
return project ? project.getProjectStats() : { loaded: false };
105+
}
106+
}
103107

104108
return {
105109
loaded: false

packages/apollo-language-server/src/project/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class GraphQLClientProject extends GraphQLProject {
125125
: 0;
126126

127127
return {
128+
type: "client",
128129
serviceId: this.serviceID,
129130
// filter out primitives and internal Types for type stats to match engine
130131
types: {

packages/apollo-language-server/src/project/service.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,6 @@ export class GraphQLServiceProject extends GraphQLProject {
4545
validate() {}
4646

4747
getProjectStats() {
48-
// use this to remove primitives and internal fields for stats
49-
const filterTypes = (type: string) =>
50-
!/__.*|Boolean|ID|Int|String|Float/.test(type);
51-
52-
const serviceTypes = this.schema
53-
? Object.keys(this.schema.getTypeMap()).filter(filterTypes).length
54-
: 0;
55-
56-
return {
57-
loaded: true,
58-
serviceId: this.displayName(),
59-
types: {
60-
service: serviceTypes,
61-
client: 0,
62-
total: serviceTypes
63-
},
64-
tag: this.config.tag,
65-
lastFetch: this.lastLoadDate
66-
};
48+
return { loaded: true, type: "service" };
6749
}
6850
}

packages/apollo-language-server/src/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ connection.onNotification(
212212
(selection: QuickPickItem) => workspace.updateSchemaTag(selection)
213213
);
214214

215-
connection.onNotification("apollographql/getStatus", async () => {
216-
const status = await languageProvider.provideStatus();
217-
connection.sendNotification("apollographql/statusLoaded", status);
215+
connection.onNotification("apollographql/getStats", async ({ uri }) => {
216+
const status = await languageProvider.provideStats(uri);
217+
connection.sendNotification("apollographql/statsLoaded", status);
218218
});
219219

220220
// Listen on the connection

packages/vscode-apollo/src/extension.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ export function activate(context: ExtensionContext) {
8484
context.subscriptions.push(client.start());
8585

8686
client.onReady().then(() => {
87-
commands.registerCommand("apollographql/showStatus", () => {
88-
client.sendNotification("apollographql/getStatus");
87+
commands.registerCommand("apollographql/showStats", () => {
88+
client.sendNotification("apollographql/getStats", {
89+
uri: window.activeTextEditor
90+
? window.activeTextEditor.document.uri.toString()
91+
: null
92+
});
8993
});
9094

91-
client.onNotification("apollographql/statusLoaded", params => {
95+
client.onNotification("apollographql/statsLoaded", params => {
9296
const timeSince = (date: number) => {
9397
const seconds = Math.floor((+new Date() - date) / 1000);
9498
let interval = Math.floor(seconds / 86400);
@@ -103,6 +107,12 @@ export function activate(context: ExtensionContext) {
103107
return `${Math.floor(seconds)}s`;
104108
};
105109

110+
// we don't support logging of stats for service projects currently
111+
if (params.type === "service") {
112+
client.outputChannel.show();
113+
return;
114+
}
115+
106116
if (!params.loaded) {
107117
client.outputChannel.appendLine(
108118
"Service not loaded. See above errors if any are printed"

packages/vscode-apollo/src/statusBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class ApolloStatusBar {
1616
this.statusBarItem.text = "Apollo GraphQL $(rss)";
1717
this.statusBarItem.show();
1818

19-
this.statusBarItem.command = "apollographql/showStatus";
19+
this.statusBarItem.command = "apollographql/showStats";
2020
// context.subscriptions.push(this.statusBarItem);
2121
}
2222

0 commit comments

Comments
 (0)