README
Query profiler for Apollo Server 2
Dependencies
Apollo Server is a community-maintained open-source GraphQL server. This Query Profiler project try to make super easy to control how many and which requests are called when a query is executed.
Getting started
npm i -D apollo-q-prof
- Replace
app = new ApolloServer({configData})
byapp = ApolloQProf({configData})
- Run your application and that's all!
Configuration (Experimental)
There is a second [optional] argument to provide a configuration.
The current version only accept an ApolloServer
object. So if you are using apollo-server-express
you can provide you object and version and use it.
{
apolloInstance: ApolloServer,
enabled: Boolean
}
Example:
// Just an example
import ApolloServer from 'apollo-server-express';
const server = ApolloQProf({
schema,
debug: true,
dataSources: () => dataSources,
context: (): AppContextWithoutDataSources => {
return {
locale: "",
authHeaders: {},
cookies: {}
};
}
}, {
apolloInstance: ApolloServer,
enabled: true
});
The service is enabled
by default
Running the UI
Apollo-Q-Prof provide an UI to be able to see the generated json
file with the information about the request/responses. To be able to use it you need to do the following:
- In your project, open you
package.json
and update thescripts
section with a new command like:
{
...,
scripts: {
...,
"ui-prof": "apollo-q-prof-ui"
}
}
- Ejecute the command:
npm run ui-prof
- Open a browser and go to the url:
http://localhost:9000
(or a different port - check the console) - Now you can open the file
apollo-q-prof.json
located in the root folder of your project (the one generated by the profiler). - Refresh it when you want to see new data.
Structure of JSON file
[
{
"outgoingRequests": [
{
"startTimestamp": "0",
"endsTimestamp": "1",
"params": "[ 'parameter1',... ,'paramenterN' ]",
"executionTime": "time in ms",
"method": "",
"dataSource": ""
},
...
],
"request": {
"operationName": "",
"variables": {},
"query": "{...}"
},
"response": {
"startTimestamp": "0",
"endsTimestamp": "1",
"executionTime": "time in ms"
}
},
]
Upcoming versions
There are some improvements that we are going to include in upcoming versions like:
- Timeline for each request
- Real-time monitoring
- Statitics and Graphs