Skip to content

Commit c10cebd

Browse files
committed
Improve startup time and logging
1 parent 4806556 commit c10cebd

File tree

11 files changed

+112
-207
lines changed

11 files changed

+112
-207
lines changed

src/plugins/log.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import syslog from 'syslog-client';
2+
3+
const logger = syslog.createClient(process.env.SYSLOG_HOST, {
4+
port: process.env.SYSLOG_PORT,
5+
syslogHostname: `gql`,
6+
});
7+
8+
export default {
9+
requestDidStart({ schemaHash, context: { req } }) {
10+
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
11+
12+
return {
13+
validationDidStart({ source, queryHash, request }) {
14+
logger.log([
15+
queryHash,
16+
ip,
17+
`QUERY`,
18+
`"${source?.split(`\n`).filter((line) => Boolean(line.trim())).join(' ').replace(/"/g, `'`)}"`,
19+
schemaHash,
20+
].join(' '));
21+
if (request?.variables) {
22+
logger.log([
23+
queryHash,
24+
ip,
25+
`QUERY_VARIABLES`,
26+
`"${JSON.stringify(request.variables)}"`,
27+
schemaHash,
28+
].join(' '));
29+
}
30+
return (errs) => {
31+
(errs || []).forEach((e) => {
32+
logger.log([
33+
queryHash,
34+
ip,
35+
`PARSE_ERROR`,
36+
`"${e?.toString().split(`\n`).join('; ')}"`,
37+
`"${e?.stack?.split(`\n`).join('; ')}"`
38+
].join(' '));
39+
});
40+
}
41+
},
42+
43+
didEncounterErrors({ queryHash, errors }) {
44+
console.log(errors);
45+
(errors || []).forEach((e) => {
46+
logger.log([
47+
queryHash,
48+
ip,
49+
`EXEC_ERROR`,
50+
`"${e?.toString().split(`\n`).join('; ')}"`,
51+
`"${e?.stack?.split(`\n`).join('; ')}"`
52+
].join(' '));
53+
});
54+
}
55+
}
56+
},
57+
}

src/remotes/advisors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { wrapSchema, introspectSchema } from '@graphql-tools/wrap';
22
import makeRemoteTransport from '../remoteTransport';
33

44
export default async function createAdvisorsSchema(uri) {
5+
console.log(` * advisors(${uri})`);
56
const { executor, subscriber } = makeRemoteTransport(uri);
67
const schema = wrapSchema({
78
schema: await introspectSchema(executor),

src/remotes/calendar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { loadSchema } from '@graphql-tools/load';
22
import { UrlLoader } from '@graphql-tools/url-loader';
33

4-
export default async function createDiscordPostsSchema(uri) {
4+
export default async function createCalendarSchema(uri) {
5+
console.log(` * calendar(${uri})`);
56
const schema = await loadSchema(uri, { loaders: [new UrlLoader()] });
67
return {
78
schema,

src/remotes/clear.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function getConnectionResolvers(prefix, schemas) {
6161

6262

6363
export default async function createClearSchema(uri) {
64+
console.log(` * clear(${uri})`);
6465
const { executor, subscriber } = makeRemoteTransport(uri);
6566
const schema = wrapSchema({
6667
schema: await introspectSchema(executor),

src/remotes/contentful.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function getConnectionResolvers(prefix, schemas) {
7878
}
7979

8080
export default async function createContentfulSchema(space, token) {
81+
console.log(` * contentful(${space})`);
8182
const schema = await loadSchema(
8283
`https://graphql.contentful.com/content/v1/spaces/${space}`,
8384
{

src/remotes/discordPosts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function getConnectionResolvers(prefix, schemas) {
3535
}
3636

3737
export default async function createDiscordPostsSchema(uri) {
38+
console.log(` * discordPosts(${uri})`);
3839
const schema = await loadSchema(uri, { loaders: [new UrlLoader()] });
3940
return {
4041
schema,

src/remotes/labs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function getConnectionResolvers(prefix, schemas) {
4949
}
5050

5151
export default async function createLabsSchema(uri) {
52+
console.log(` * labs(${uri})`);
5253
const { executor, subscriber } = makeRemoteTransport(uri);
5354
const schema = wrapSchema({
5455
schema: await introspectSchema(executor),

src/remotes/learn.js

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/remotes/showcase.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ function getConnectionResolvers(prefix, schemas) {
206206

207207

208208
export default async function createShowcaseSchema(uri, wsUri) {
209+
console.log(` * showcase(${uri})`);
209210
const { executor, subscriber } = makeRemoteTransport(uri, wsUri);
210211
const schema = wrapSchema({
211212
schema: await introspectSchema(executor),

src/remotes/wordpress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function getConnectionResolvers(prefix, schemas) {
4343
}
4444

4545
export default async function createWordpressSchema(uri) {
46+
console.log(` * wordpress(${uri})`);
4647
const schema = await loadSchema(uri, { loaders: [new UrlLoader()] });
4748
return {
4849
schema,

0 commit comments

Comments
 (0)