diff --git a/.all-contributorsrc b/.all-contributorsrc index b7d19e7..f21e575 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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" diff --git a/README.md b/README.md index a4f831a..412c6af 100644 --- a/README.md +++ b/README.md @@ -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] @@ -115,8 +115,8 @@ Thanks goes to these people ([emoji key][emojis]): -| [
Adrian Perez](https://adrianperez.codes)
[💻](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") | [
Adam Savitzky](https://github.com/adambom)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=adambom "Code") | [
Ifeanyi Oraelosi](https://github.com/gnerkus)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=gnerkus "Code") | [
Romario](https://github.com/romarioraffington)
[🐛](https://github.com/blackxored/apollo-link-logger/issues?q=author%3Aromarioraffington "Bug reports") [🤔](#ideas-romarioraffington "Ideas, Planning, & Feedback") | [
Yuriy Kornienko](http://www.dinamchiki.ru)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=Horoshiy "Code") | -| :---: | :---: | :---: | :---: | :---: | +| [
Adrian Perez](https://adrianperez.codes)
[💻](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") | [
Adam Savitzky](https://github.com/adambom)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=adambom "Code") | [
Ifeanyi Oraelosi](https://github.com/gnerkus)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=gnerkus "Code") | [
Romario](https://github.com/romarioraffington)
[🐛](https://github.com/blackxored/apollo-link-logger/issues?q=author%3Aromarioraffington "Bug reports") [🤔](#ideas-romarioraffington "Ideas, Planning, & Feedback") | [
Yuriy Kornienko](http://www.dinamchiki.ru)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=Horoshiy "Code") | [
Andy McVitty](https://github.com/amcvitty)
[💻](https://github.com/blackxored/apollo-link-logger/commits?author=amcvitty "Code") | +| :---: | :---: | :---: | :---: | :---: | :---: | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/index.js b/src/index.js index 5ef1d26..003713b 100644 --- a/src/index.js +++ b/src/index.js @@ -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);