apollo-link-performance
Version:
Easily log and report on the performance of your GraphQL queries.
51 lines (37 loc) • 1.08 kB
Markdown
Easily tap into Apollo Client requests and log those in your performance tracking tool of choice.
Via [npm](https://npmjs.com/package/apollo-link-performance)
```sh
npm install apollo-link-performance
```
Via [Yarn](https://yarn.pm/apollo-link-performance)
```sh
yarn add apollo-link-performance
```
```js
import { ApolloClient, from, HTTPLink } from '@apollo/client'
import { performanceLink } from 'apollo-link-performance'
import analytics from '../libs/analytics'
const httpLink = new HttpLink({
uri: https://mygraphqlapi.com,
})
const client = new ApolloClient({
link: from([
performanceLink({
onRequestComplete: ({ data, dataSize, duration, operation }) => {
analytics.track(`GraphQL Request - Performance`, {
dataSize,
duration,
operationName: operation.operationName,
operationType: operation.query.definitions[0].operation,
})
}
})
httpLink,
])
})
```
[](LICENSE) © [Pregraph](https://www.pregraph.com)