Skip to content

Commit

Permalink
chore(op-reg): Change to Logger types from apollo-server-types fo…
Browse files Browse the repository at this point in the history
…r agent.

Use the `Logger` types which are now provided by `apollo-server-types` as a
base type for a "logger" now, introduced in the below-referenced PR.

Note: While it's now more within reach, this doesn't yet expose the `logger`
configurability at the top-level, nor does it try to leverage the `logger`
that is provided to `serverWillStart` since that will require additional
changes which are currently out of scope to accommodate the `dryRun` mode of
operation which currently forces the log-level to a specific level when
activated. Further, it does so using a `loglevel`-specific API.

Therefore, these changes are best described as being limited to the agent's
logger.

[Ref]: #3894
  • Loading branch information
abernix committed Jun 29, 2020
1 parent 2d2fddb commit 7c8d30f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import Agent, { AgentOptions } from "../agent";
import { Operation, OperationManifest } from "../ApolloServerPluginOperationRegistry";
import { fakeTestBaseUrl, getLegacyOperationManifestUrl, getStoreKey, getOperationManifestUrl, urlOperationManifestBase } from "../common";
import { Logger } from "apollo-server-types";

// These get a bit verbose within the tests below, so we use this as a
// sample store to pick and grab from.
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('Agent', () => {
sampleManifestRecords.c,
]);
const relevantLogs: any = [];
const logger = {
const logger: Logger = {
debug: jest.fn().mockImplementation((...args: any[]) => {
if (
typeof args[0] === 'string' &&
Expand All @@ -167,6 +168,8 @@ describe('Agent', () => {
relevantLogs.push(args);
}
}),
info: () => {},
error: () => {},
};
await createAgent({ logger }).start();

Expand Down
5 changes: 3 additions & 2 deletions packages/apollo-server-plugin-operation-registry/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { Response } from 'node-fetch';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { fetchIfNoneMatch } from './fetchIfNoneMatch';
import { OperationManifest } from "./ApolloServerPluginOperationRegistry";
import { Logger } from "apollo-server-types";

const DEFAULT_POLL_SECONDS: number = 30;
const SYNC_WARN_TIME_SECONDS: number = 60;

export interface AgentOptions {
logger?: loglevel.Logger;
logger?: Logger;
pollSeconds?: number;
schemaHash: string;
engine: any;
Expand All @@ -32,7 +33,7 @@ const callToAction = `Ensure this server's schema has been published with 'apoll

export default class Agent {
private timer?: NodeJS.Timer;
private logger: loglevel.Logger;
private logger: Logger;
private hashedServiceId?: string;
private requestInFlight: Promise<any> | null = null;
private lastSuccessfulCheck?: Date;
Expand Down

0 comments on commit 7c8d30f

Please sign in to comment.