Skip to content

Commit 76f87f0

Browse files
authored
fix(tracing): Warn if resolvers is not defined in ApolloServer config (#5850)
Log a warning instead of breaking the application when `resolvers` array is not defined in the `ApolloServer` configuration.
1 parent 4c6c6f6 commit 76f87f0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/tracing/src/integrations/node/apollo.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,33 @@ export class Apollo implements Integration {
3535
}>('apollo-server-core');
3636

3737
if (!pkg) {
38-
logger.error('Apollo Integration was unable to require apollo-server-core package.');
38+
__DEBUG_BUILD__ && logger.error('Apollo Integration was unable to require apollo-server-core package.');
3939
return;
4040
}
4141

4242
/**
4343
* Iterate over resolvers of the ApolloServer instance before schemas are constructed.
4444
*/
4545
fill(pkg.ApolloServerBase.prototype, 'constructSchema', function (orig: () => unknown) {
46-
return function (this: { config: { resolvers: ApolloModelResolvers[] } }) {
46+
return function (this: { config: { resolvers?: ApolloModelResolvers[]; schema?: unknown; modules?: unknown } }) {
47+
if (!this.config.resolvers) {
48+
if (__DEBUG_BUILD__) {
49+
if (this.config.schema) {
50+
logger.warn(
51+
'Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.',
52+
);
53+
} else if (this.config.modules) {
54+
logger.warn(
55+
'Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property.',
56+
);
57+
}
58+
59+
logger.error('Skipping tracing as no resolvers found on the `ApolloServer` instance.');
60+
}
61+
62+
return orig.call(this);
63+
}
64+
4765
const resolvers = arrayify(this.config.resolvers);
4866

4967
this.config.resolvers = resolvers.map(model => {

packages/tracing/src/integrations/node/graphql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class GraphQL implements Integration {
2323
}>('graphql/execution/execute.js');
2424

2525
if (!pkg) {
26-
logger.error('GraphQL Integration was unable to require graphql/execution package.');
26+
__DEBUG_BUILD__ && logger.error('GraphQL Integration was unable to require graphql/execution package.');
2727
return;
2828
}
2929

0 commit comments

Comments
 (0)