Skip to content

Commit

Permalink
feat: look through definitions to find an operation type
Browse files Browse the repository at this point in the history
Previously we were just reporting the first, which for large queries was
often a fragment definition, which doesn't have an operation. In most
use cases, there will be exactly one query or mutation. In the case
where there are multiple, we'll report one of them (no worse than
before!). Also - correct spelling of "elapsed"
  • Loading branch information
amcvitty committed Feb 14, 2019
1 parent 7e33da2 commit f317dca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ const loggerLink = new ApolloLink((operation, forward) => {
const startTime = new Date().getTime();

return forward(operation).map(result => {
const operationType = operation.query.definitions[0].operation;
const ellapsed = new Date().getTime() - startTime;
let operationType;
for (let i = 0; i < operation.query.definitions.length; i += 1) {
operationType = operation.query.definitions[i].operation || operationType;
}
const elapsed = new Date().getTime() - startTime;

const group = formatMessage(operationType, operation, ellapsed);
const group = formatMessage(operationType, operation, elapsed);

logging.groupCollapsed(...group);

Expand Down

0 comments on commit f317dca

Please sign in to comment.