Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tracing): Warn if resolvers is not defined in ApolloServer config #5850

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/tracing/src/integrations/node/apollo.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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