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

change to print graphql sql on request #1428

Merged
merged 1 commit into from
Nov 22, 2022
Merged
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
23 changes: 6 additions & 17 deletions packages/query/src/configure/x-postgraphile/debugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,10 @@ type ExplainResult = Omit<RawExplainResult, 'result'> & {
// print original Graphql Query
export function queryExplainPlugin(logger: Pino.Logger): ApolloServerPlugin {
return {
requestDidStart: () => {
let op;

return {
didResolveOperation({request}) {
if (request.operationName === null) {
op = request.query;
}
},
willSendResponse(context) {
if (op) {
logger.info(` \n GraphQL: ${op}`);
}
},
};
requestDidStart: ({request}) => {
if (request.operationName === null && request.query !== undefined) {
logger.info(` \n GraphQL query: ${request.query}`);
}
},
} as unknown as ApolloServerPlugin;
}
Expand Down Expand Up @@ -113,13 +102,13 @@ export function debugPgClient(pgClient: PoolClient, logger: Pino.Logger): PoolCl
}
pgClient._explainResults.forEach(({query, values}: {query: string; values?: any[]}) => {
let res: string;
res = `\n Query: ${query} `;
res = `\n SQL query: ${query} `;
if (values && values.length !== 0) {
res = res.concat(` \n Values: ${JSON.stringify(values)}`);
}
logger.info(res);
});

pgClient._explainResults = [];
return pgClient[$$pgClientOrigQuery].apply(this, args);
} else {
// We don't understand it (e.g. `pgPool.query`), just let it happen.
Expand Down