Skip to content
New issue

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

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

Already on GitHub? # to your account

Look through definitions to find an operation type #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
"contributions": [
"code"
]
},
{
"login": "amcvitty",
"name": "Andy McVitty",
"avatar_url": "https://avatars1.githubusercontent.com/u/7907585?v=4",
"profile": "https://github.com/amcvitty",
"contributions": [
"code"
]
}
],
"repoType": "github"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![AirBnB style guide][airbnb-style-badge]][airbnb-style]

[![MIT License][license-badge]][LICENSE]
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Commitizen friendly][commitizen-badge]][commitizen]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -115,8 +115,8 @@ Thanks goes to these people ([emoji key][emojis]):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars3.githubusercontent.com/u/133308?v=4" width="100px;"/><br /><sub><b>Adrian Perez</b></sub>](https://adrianperez.codes)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Code") [📖](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Documentation") [🚇](#infra-blackxored "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Tests") | [<img src="https://avatars3.githubusercontent.com/u/294597?s=460&v=4" width="100px;"/><br /><sub><b>Adam Savitzky</b></sub>](https://github.com/adambom)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=adambom "Code") | [<img src="https://avatars3.githubusercontent.com/u/3065138?v=4" width="100px;"/><br /><sub><b>Ifeanyi Oraelosi</b></sub>](https://github.com/gnerkus)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=gnerkus "Code") | [<img src="https://avatars0.githubusercontent.com/u/7076981?v=4" width="100px;"/><br /><sub><b>Romario</b></sub>](https://github.com/romarioraffington)<br />[🐛](https://github.com/blackxored/apollo-link-logger/issues?q=author%3Aromarioraffington "Bug reports") [🤔](#ideas-romarioraffington "Ideas, Planning, & Feedback") | [<img src="https://avatars0.githubusercontent.com/u/6183943?v=4" width="100px;"/><br /><sub><b>Yuriy Kornienko</b></sub>](http://www.dinamchiki.ru)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=Horoshiy "Code") |
| :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/133308?v=4" width="100px;"/><br /><sub><b>Adrian Perez</b></sub>](https://adrianperez.codes)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Code") [📖](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Documentation") [🚇](#infra-blackxored "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/blackxored/apollo-link-logger/commits?author=blackxored "Tests") | [<img src="https://avatars3.githubusercontent.com/u/294597?s=460&v=4" width="100px;"/><br /><sub><b>Adam Savitzky</b></sub>](https://github.com/adambom)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=adambom "Code") | [<img src="https://avatars3.githubusercontent.com/u/3065138?v=4" width="100px;"/><br /><sub><b>Ifeanyi Oraelosi</b></sub>](https://github.com/gnerkus)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=gnerkus "Code") | [<img src="https://avatars0.githubusercontent.com/u/7076981?v=4" width="100px;"/><br /><sub><b>Romario</b></sub>](https://github.com/romarioraffington)<br />[🐛](https://github.com/blackxored/apollo-link-logger/issues?q=author%3Aromarioraffington "Bug reports") [🤔](#ideas-romarioraffington "Ideas, Planning, & Feedback") | [<img src="https://avatars0.githubusercontent.com/u/6183943?v=4" width="100px;"/><br /><sub><b>Yuriy Kornienko</b></sub>](http://www.dinamchiki.ru)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=Horoshiy "Code") | [<img src="https://avatars1.githubusercontent.com/u/7907585?v=4" width="100px;"/><br /><sub><b>Andy McVitty</b></sub>](https://github.com/amcvitty)<br />[💻](https://github.com/blackxored/apollo-link-logger/commits?author=amcvitty "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ 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;
// Here we try to find an operation definition to find its operationType
// (as opposed to fragment definitions with no operationType)
// There is usually only one query or mutation
let operationType;
operation.query.definitions.forEach(definition => {
operationType = definition.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