Skip to content

Commit c357e10

Browse files
committed
updated logging & stats printing
1 parent 34dea45 commit c357e10

3 files changed

Lines changed: 59 additions & 10 deletions

File tree

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,28 @@ export class GraphQLClientProject extends GraphQLProject {
115115
}
116116

117117
public getProjectStats() {
118+
// use this to remove primitives and internal fields for stats
119+
const filterTypes = (type: string) =>
120+
!/__.*|Boolean|ID|Int|String|Float/.test(type);
121+
122+
const serviceTypes = this.serviceSchema
123+
? Object.keys(this.serviceSchema.getTypeMap()).filter(filterTypes).length
124+
: 0;
125+
const totalTypes = this.schema
126+
? Object.keys(this.schema.getTypeMap()).filter(filterTypes).length
127+
: 0;
128+
118129
return {
119130
serviceId: this.serviceID,
120-
types: this.serviceSchema
121-
? Object.keys(this.serviceSchema.getTypeMap).length
122-
: 0,
131+
// filter out primitives and internal Types for type stats to match engine
132+
types: {
133+
service: serviceTypes,
134+
client: totalTypes - serviceTypes,
135+
total: totalTypes
136+
},
123137
tag: this.config.tag,
124-
loaded: this.serviceID,
125-
lastFetch: ""
138+
loaded: this.serviceID ? true : false,
139+
lastFetch: this.lastLoadDate
126140
};
127141
}
128142

@@ -228,8 +242,6 @@ export class GraphQLClientProject extends GraphQLProject {
228242
] = await engineClient.loadSchemaTagsAndFieldStats(serviceID);
229243
this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]);
230244
this.fieldStats = fieldStats;
231-
232-
console.log(this.fieldStats);
233245
this.lastLoadDate = +new Date();
234246

235247
this.generateDecorations();

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

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

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

packages/vscode-apollo/src/extension.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,44 @@ export function activate(context: ExtensionContext) {
8989
});
9090

9191
client.onNotification("apollographql/statusLoaded", params => {
92-
client.outputChannel.appendLine("Hello");
92+
const timeSince = (date: number) => {
93+
const seconds = Math.floor((+new Date() - date) / 1000);
94+
let interval = Math.floor(seconds / 86400);
95+
if (interval >= 1) return `${interval}d`;
96+
97+
interval = Math.floor(seconds / 3600);
98+
if (interval >= 1) return `${interval}h`;
99+
100+
interval = Math.floor(seconds / 60);
101+
if (interval >= 1) return `${interval}m`;
102+
103+
return `${Math.floor(seconds)}s`;
104+
};
105+
106+
if (!params.loaded) {
107+
client.outputChannel.appendLine(
108+
"Service not loaded. See above errors if any are printed"
109+
);
110+
} else {
111+
client.outputChannel.appendLine("------------------------------");
112+
client.outputChannel.appendLine(`🚀 Apollo GraphQL v${version}`);
113+
client.outputChannel.appendLine("✅ Service Loaded!");
114+
client.outputChannel.appendLine(`🆔 Service ID: ${params.serviceId}`);
115+
client.outputChannel.appendLine(`🏷 Schema Tag: ${params.tag}`);
116+
client.outputChannel.appendLine(
117+
`📈 Number of Types: ${params.types.total} ${
118+
params.types.client
119+
? `(${params.types.client} client ${
120+
params.types.client > 1 ? "types" : "type"
121+
})`
122+
: ""
123+
}`
124+
);
125+
client.outputChannel.appendLine(
126+
`🗓 Last Fetched ${timeSince(params.lastFetch)} Ago`
127+
);
128+
client.outputChannel.appendLine("------------------------------");
129+
}
93130
client.outputChannel.show();
94131
});
95132

0 commit comments

Comments
 (0)