Skip to content

Commit

Permalink
feat(client): log query complexity (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
deini authored Feb 8, 2024
1 parent 841da4c commit 503459f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
throw await BigCommerceAPIError.createFromResponse(response);
}

log();
log(response);

return response.json() as Promise<BigCommerceResponse<TResult>>;
}
Expand Down Expand Up @@ -135,12 +135,16 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {

const timeStart = Date.now();

return () => {
return (response: Response) => {
const timeEnd = Date.now();
const duration = timeEnd - timeStart;

const complexity = response.headers.get('x-bc-graphql-complexity');

// eslint-disable-next-line no-console
console.log(`[BigCommerce] ${type} ${name ?? 'anonymous'} - ${duration}ms`);
console.log(
`[BigCommerce] ${type} ${name ?? 'anonymous'} - ${duration}ms - complexity ${complexity ?? 'unknown'}`,
);
};
}
}
Expand Down

0 comments on commit 503459f

Please sign in to comment.