Skip to content

Commit 7184bde

Browse files
committed
use template literals
1 parent 2d9ce0e commit 7184bde

File tree

9 files changed

+52
-50
lines changed

9 files changed

+52
-50
lines changed

packages/gateway/src/commands/handleFork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function handleFork(log: Logger, config: { fork?: number }): boolean {
1010
if (cluster.isPrimary && config.fork && config.fork > 1) {
1111
const workers = new Set<Worker>();
1212
let expectedToExit = false;
13-
log.debug('Forking %d workers', config.fork);
13+
log.debug(`Forking ${config.fork} workers`);
1414
for (let i = 0; i < config.fork; i++) {
1515
const worker = cluster.fork();
1616
const workerLogger = log.child({ worker: worker.id });
@@ -38,7 +38,7 @@ export function handleFork(log: Logger, config: { fork?: number }): boolean {
3838
workers.add(worker);
3939
}
4040
registerTerminateHandler((signal) => {
41-
log.info('Killing workers on %s', signal);
41+
log.info(`Killing workers on ${signal}`);
4242
expectedToExit = true;
4343
workers.forEach((w) => {
4444
w.kill(signal);

packages/gateway/src/commands/supergraph.ts

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ export const addCommand: AddCommand = (ctx, cli) =>
7979
let supergraph:
8080
| UnifiedGraphConfig
8181
| GatewayHiveCDNOptions
82-
| GatewayGraphOSManagedFederationOptions = 'supergraph.graphql';
82+
| GatewayGraphOSManagedFederationOptions = './supergraph.graphql';
8383
if (schemaPathOrUrl) {
84-
ctx.log.info('Supergraph will be loaded from %s', schemaPathOrUrl);
84+
ctx.log.info(`Supergraph will be loaded from ${schemaPathOrUrl}`);
8585
if (hiveCdnKey) {
8686
ctx.log.info('Using Hive CDN key');
8787
if (!isUrl(schemaPathOrUrl)) {
8888
ctx.log.error(
89-
'Hive CDN endpoint must be a URL when providing --hive-cdn-key but got %s',
90-
schemaPathOrUrl,
89+
`Hive CDN endpoint must be a URL when providing --hive-cdn-key but got ${schemaPathOrUrl}`,
9190
);
9291
process.exit(1);
9392
}
@@ -100,8 +99,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
10099
ctx.log.info('Using GraphOS API key');
101100
if (!schemaPathOrUrl.includes('@')) {
102101
ctx.log.error(
103-
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant> when providing --apollo-key. Please provide a valid graph ref not %s.`,
104-
schemaPathOrUrl,
102+
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant> when providing --apollo-key. Please provide a valid graph ref not ${schemaPathOrUrl}.`,
105103
);
106104
process.exit(1);
107105
}
@@ -128,7 +126,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
128126
);
129127
process.exit(1);
130128
}
131-
ctx.log.info('Using Hive CDN endpoint %s', hiveCdnEndpoint);
129+
ctx.log.info(`Using Hive CDN endpoint ${hiveCdnEndpoint}`);
132130
supergraph = {
133131
type: 'hive',
134132
endpoint: hiveCdnEndpoint,
@@ -137,8 +135,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
137135
} else if (apolloGraphRef) {
138136
if (!apolloGraphRef.includes('@')) {
139137
ctx.log.error(
140-
'Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref not %s.',
141-
apolloGraphRef,
138+
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref not ${apolloGraphRef}.`,
142139
);
143140
process.exit(1);
144141
}
@@ -148,7 +145,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
148145
);
149146
process.exit(1);
150147
}
151-
ctx.log.info('Using Apollo Graph Ref %s', apolloGraphRef);
148+
ctx.log.info(`Using Apollo Graph Ref ${apolloGraphRef}`);
152149
supergraph = {
153150
type: 'graphos',
154151
apiKey: apolloKey,
@@ -159,7 +156,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
159156
supergraph = loadedConfig.supergraph!; // TODO: assertion wont be necessary when exactOptionalPropertyTypes
160157
// TODO: how to provide hive-cdn-key?
161158
} else {
162-
ctx.log.info('Using default supergraph location %s', supergraph);
159+
ctx.log.info(`Using default supergraph location "${supergraph}"`);
163160
}
164161

165162
const registryConfig: Pick<SupergraphConfig, 'reporting'> = {};
@@ -276,13 +273,13 @@ export async function runSupergraph(
276273
absSchemaPath = isAbsolute(supergraphPath)
277274
? String(supergraphPath)
278275
: resolve(process.cwd(), supergraphPath);
279-
log.info('Reading supergraph from %s', absSchemaPath);
276+
log.info({ path: absSchemaPath }, 'Reading supergraph');
280277
try {
281278
await lstat(absSchemaPath);
282-
} catch {
279+
} catch (err) {
283280
log.error(
284-
'Could not read supergraph from %s. Make sure the file exists.',
285-
absSchemaPath,
281+
{ path: absSchemaPath, err },
282+
'Could not read supergraph. Make sure the file exists.',
286283
);
287284
process.exit(1);
288285
}
@@ -292,11 +289,14 @@ export async function runSupergraph(
292289
// Polling should not be enabled when watching the file
293290
delete config.pollingInterval;
294291
if (cluster.isPrimary) {
295-
log.info('Watching %s for changes', absSchemaPath);
292+
log.info({ path: absSchemaPath }, 'Watching supergraph for changes');
296293

297294
const ctrl = new AbortController();
298295
registerTerminateHandler((signal) => {
299-
log.info('Closing watcher for %s on %s', absSchemaPath, signal);
296+
log.info(
297+
{ path: absSchemaPath },
298+
`Closing watcher for supergraph on ${signal}`,
299+
);
300300
return ctrl.abort(`Process terminated on ${signal}`);
301301
});
302302

@@ -308,7 +308,10 @@ export async function runSupergraph(
308308
// TODO: or should we just ignore?
309309
throw new Error(`Supergraph file was renamed to "${f.filename}"`);
310310
}
311-
log.info('%s changed. Invalidating supergraph...', absSchemaPath);
311+
log.info(
312+
{ path: absSchemaPath },
313+
'Supergraph changed. Invalidating...',
314+
);
312315
if (config.fork && config.fork > 1) {
313316
for (const workerId in cluster.workers) {
314317
cluster.workers[workerId]!.send('invalidateUnifiedGraph');
@@ -321,10 +324,16 @@ export async function runSupergraph(
321324
})()
322325
.catch((e) => {
323326
if (e.name === 'AbortError') return;
324-
log.error(e, 'Watcher for %s closed with an error', absSchemaPath);
327+
log.error(
328+
{ path: absSchemaPath, err: e },
329+
'Supergraph watcher closed with an error',
330+
);
325331
})
326332
.then(() => {
327-
log.info('Watcher for %s successfuly closed', absSchemaPath);
333+
log.info(
334+
{ path: absSchemaPath },
335+
'Supergraph watcher successfuly closed',
336+
);
328337
});
329338
}
330339
}
@@ -359,17 +368,17 @@ export async function runSupergraph(
359368
const runtime = createGatewayRuntime(config);
360369

361370
if (absSchemaPath) {
362-
log.info('Serving local supergraph from %s', absSchemaPath);
371+
log.info({ path: absSchemaPath }, 'Serving local supergraph');
363372
} else if (isUrl(String(config.supergraph))) {
364-
log.info('Serving remote supergraph from %s', config.supergraph);
373+
log.info({ url: config.supergraph }, 'Serving remote supergraph');
365374
} else if (
366375
typeof config.supergraph === 'object' &&
367376
'type' in config.supergraph &&
368377
config.supergraph.type === 'hive'
369378
) {
370379
log.info(
371-
'Serving supergraph from Hive CDN at %s',
372-
config.supergraph.endpoint,
380+
{ endpoint: config.supergraph.endpoint },
381+
'Serving supergraph from Hive CDN',
373382
);
374383
} else {
375384
log.info('Serving supergraph from config');

packages/gateway/src/servers/bun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ export async function startBunServer<TContext extends Record<string, any>>(
6464
};
6565
}
6666
const server = Bun.serve(serverOptions);
67-
opts.log.info('Listening on %s', server.url);
67+
opts.log.info(`Listening on ${server.url}`);
6868
gwRuntime.disposableStack.use(server);
6969
}

packages/gateway/src/servers/nodeHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export async function startNodeHttpServer<TContext extends Record<string, any>>(
7777

7878
const url = `${protocol}://${host}:${port}`.replace('0.0.0.0', 'localhost');
7979

80-
log.debug('Starting server on %s', url);
80+
log.debug(`Starting server on ${url}`);
8181
if (!disableWebsockets) {
8282
log.debug('Setting up WebSocket server');
8383
const { WebSocketServer } = await import('ws');
@@ -112,7 +112,7 @@ export async function startNodeHttpServer<TContext extends Record<string, any>>(
112112
return new Promise((resolve, reject) => {
113113
server.once('error', reject);
114114
server.listen(port, host, () => {
115-
log.info('Listening on %s', url);
115+
log.info(`Listening on ${url}`);
116116
gwRuntime.disposableStack.defer(
117117
() =>
118118
new Promise<void>((resolve) => {

packages/plugins/hmac-upstream-signature/src/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ export function useHmacUpstreamSignature(
100100
log: rootLog,
101101
}) {
102102
const log = rootLog.child('[useHmacUpstreamSignature] ');
103-
log.debug('Running shouldSign for subgraph %s', subgraphName);
103+
log.debug(`Running shouldSign for subgraph ${subgraphName}`);
104104

105105
if (shouldSign({ subgraphName, subgraph, executionRequest })) {
106106
log.debug(
107-
'shouldSign is true for subgraph %s, signing request',
108-
subgraphName,
107+
`shouldSign is true for subgraph ${subgraphName}, signing request`,
109108
);
110109
textEncoder ||= new fetchAPI.TextEncoder();
111110
return handleMaybePromise(
@@ -134,8 +133,7 @@ export function useHmacUpstreamSignature(
134133
signature: extensionValue,
135134
payload: serializedExecutionRequest,
136135
},
137-
'Produced hmac signature for subgraph %s',
138-
subgraphName,
136+
`Produced hmac signature for subgraph ${subgraphName}`,
139137
);
140138

141139
if (!executionRequest.extensions) {
@@ -205,8 +203,8 @@ export function useHmacSignatureValidation(
205203
);
206204
const serializedParams = paramsSerializer(params);
207205
log.debug(
208-
'HMAC signature will be calculate based on serialized params %s',
209-
serializedParams,
206+
{ serializedParams },
207+
'HMAC signature will be calculate based on serialized params',
210208
);
211209

212210
return handleMaybePromise(

packages/plugins/jwt-auth/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ export function useJWT(
8888

8989
log.debug(
9090
{ payload: jwtData.payload },
91-
'[useJWT] Forwarding JWT payload to subgraph %s',
92-
subgraphName,
91+
`[useJWT] Forwarding JWT payload to subgraph ${subgraphName}`,
9392
);
9493

9594
setExecutionRequest({

packages/runtime/src/fetchers/graphos.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export function createGraphOSFetcher({
8181
if (nextFetchTime >= currentTime) {
8282
const delay = nextFetchTime - currentTime;
8383
log.info(
84-
'Fetching supergraph with delay %s',
85-
millisecondsToStr(delay),
84+
`Fetching supergraph with delay ${millisecondsToStr(delay)}`,
8685
);
8786
nextFetchTime = 0;
8887
return delayInMs(delay).then(fetchSupergraph);

packages/runtime/src/plugins/useWebhooks.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ export function useWebhooks({
3434
const expectedEventName = `webhook:${requestMethod}:${pathname}`;
3535
for (const eventName of eventNames) {
3636
if (eventName === expectedEventName) {
37-
log.debug('Received webhook request for %s', pathname);
37+
log.debug({ pathname }, 'Received webhook request');
3838
return handleMaybePromise(
3939
() => request.text(),
4040
function handleWebhookPayload(webhookPayload) {
4141
log.debug(
42-
{ payload: webhookPayload },
43-
'Emitted webhook request for %s',
44-
pathname,
42+
{ pathname, payload: webhookPayload },
43+
'Emitted webhook request',
4544
);
4645
webhookPayload =
4746
request.headers.get('content-type') === 'application/json'

packages/transports/http-callback/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ export default {
139139
}, heartbeatIntervalMs),
140140
);
141141
log.debug(
142-
'Subscribing to %s with callbackUrl: %s',
143-
transportEntry.location,
144-
callbackUrl,
142+
{ location: transportEntry.location, callbackUrl },
143+
'Subscribing using callback',
145144
);
146145
let pushFn: Push<ExecutionResult> = () => {
147146
throw new Error(
@@ -248,14 +247,13 @@ export default {
248247
pushFn = push;
249248
stopSubscription = stop;
250249
stopFnSet.add(stop);
251-
log.debug('Listening to %s', subscriptionCallbackPath);
250+
log.debug(`Listening to ${subscriptionCallbackPath}`);
252251
const subId = pubsub.subscribe(
253252
`webhook:post:${subscriptionCallbackPath}`,
254253
(message: HTTPCallbackMessage) => {
255254
log.debug(
256255
message,
257-
'Received message from %s',
258-
subscriptionCallbackPath,
256+
`Received message from ${subscriptionCallbackPath}`,
259257
);
260258
if (message.verifier !== verifier) {
261259
return;

0 commit comments

Comments
 (0)