Skip to content

Commit

Permalink
fix(tracing): Warn if resolvers is not defined in ApolloServer co…
Browse files Browse the repository at this point in the history
…nfig (#5850)

Log a warning instead of breaking the application when `resolvers` array is not defined in the `ApolloServer` configuration.
  • Loading branch information
onurtemizkan committed Sep 29, 2022
1 parent 4c6c6f6 commit 76f87f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions packages/tracing/src/integrations/node/apollo.ts
Expand Up @@ -35,15 +35,33 @@ export class Apollo implements Integration {
}>('apollo-server-core');

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

/**
* Iterate over resolvers of the ApolloServer instance before schemas are constructed.
*/
fill(pkg.ApolloServerBase.prototype, 'constructSchema', function (orig: () => unknown) {
return function (this: { config: { resolvers: ApolloModelResolvers[] } }) {
return function (this: { config: { resolvers?: ApolloModelResolvers[]; schema?: unknown; modules?: unknown } }) {
if (!this.config.resolvers) {
if (__DEBUG_BUILD__) {
if (this.config.schema) {
logger.warn(
'Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.',
);
} else if (this.config.modules) {
logger.warn(
'Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property.',
);
}

logger.error('Skipping tracing as no resolvers found on the `ApolloServer` instance.');
}

return orig.call(this);
}

const resolvers = arrayify(this.config.resolvers);

this.config.resolvers = resolvers.map(model => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/src/integrations/node/graphql.ts
Expand Up @@ -23,7 +23,7 @@ export class GraphQL implements Integration {
}>('graphql/execution/execute.js');

if (!pkg) {
logger.error('GraphQL Integration was unable to require graphql/execution package.');
__DEBUG_BUILD__ && logger.error('GraphQL Integration was unable to require graphql/execution package.');
return;
}

Expand Down

0 comments on commit 76f87f0

Please sign in to comment.