Skip to content

Commit 8d052ad

Browse files
Log GQL requests in watcher (#517)
* Update config for server GQL * Add winston logger for GQL requests * Fix codegen templates for resolver and package * Update package versions --------- Co-authored-by: Prathamesh Musale <[email protected]>
1 parent 836fe45 commit 8d052ad

26 files changed

+374
-96
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "0.2.93",
5+
"version": "0.2.94",
66
"npmClient": "yarn",
77
"useWorkspaces": true,
88
"command": {

packages/cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cerc-io/cache",
3-
"version": "0.2.93",
3+
"version": "0.2.94",
44
"description": "Generic object cache",
55
"main": "dist/index.js",
66
"scripts": {

packages/cli/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cerc-io/cli",
3-
"version": "0.2.93",
3+
"version": "0.2.94",
44
"main": "dist/index.js",
55
"license": "AGPL-3.0",
66
"scripts": {
@@ -15,13 +15,13 @@
1515
},
1616
"dependencies": {
1717
"@apollo/client": "^3.7.1",
18-
"@cerc-io/cache": "^0.2.93",
19-
"@cerc-io/ipld-eth-client": "^0.2.93",
18+
"@cerc-io/cache": "^0.2.94",
19+
"@cerc-io/ipld-eth-client": "^0.2.94",
2020
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
2121
"@cerc-io/nitro-node": "^0.1.15",
22-
"@cerc-io/peer": "^0.2.93",
23-
"@cerc-io/rpc-eth-client": "^0.2.93",
24-
"@cerc-io/util": "^0.2.93",
22+
"@cerc-io/peer": "^0.2.94",
23+
"@cerc-io/rpc-eth-client": "^0.2.94",
24+
"@cerc-io/util": "^0.2.94",
2525
"@ethersproject/providers": "^5.4.4",
2626
"@graphql-tools/utils": "^9.1.1",
2727
"@ipld/dag-cbor": "^8.0.0",

packages/cli/src/server.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import assert from 'assert';
1111
import { ConnectionOptions } from 'typeorm';
1212
import express, { Application } from 'express';
1313
import { ApolloServer } from 'apollo-server-express';
14+
import winston from 'winston';
1415

1516
import { JsonRpcProvider } from '@ethersproject/providers';
1617
import {
@@ -30,7 +31,8 @@ import {
3031
Consensus,
3132
readParty,
3233
UpstreamConfig,
33-
fillBlocks
34+
fillBlocks,
35+
createGQLLogger
3436
} from '@cerc-io/util';
3537
import { TypeSource } from '@graphql-tools/utils';
3638
import type {
@@ -268,7 +270,11 @@ export class ServerCmd {
268270
}
269271

270272
async exec (
271-
createResolvers: (indexer: IndexerInterface, eventWatcher: EventWatcher) => Promise<any>,
273+
createResolvers: (
274+
indexer: IndexerInterface,
275+
eventWatcher: EventWatcher,
276+
gqlLogger: winston.Logger
277+
) => Promise<any>,
272278
typeDefs: TypeSource,
273279
paymentsManager?: PaymentsManager
274280
): Promise<{
@@ -308,7 +314,8 @@ export class ServerCmd {
308314
await eventWatcher.start();
309315
}
310316

311-
const resolvers = await createResolvers(indexer, eventWatcher);
317+
const gqlLogger = createGQLLogger(config.server.gql.logDir);
318+
const resolvers = await createResolvers(indexer, eventWatcher, gqlLogger);
312319

313320
// Create an Express app
314321
const app: Application = express();

packages/codegen/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cerc-io/codegen",
3-
"version": "0.2.93",
3+
"version": "0.2.94",
44
"description": "Code generator",
55
"private": true,
66
"main": "index.js",
@@ -20,7 +20,7 @@
2020
},
2121
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
2222
"dependencies": {
23-
"@cerc-io/util": "^0.2.93",
23+
"@cerc-io/util": "^0.2.94",
2424
"@graphql-tools/load-files": "^6.5.2",
2525
"@npmcli/package-json": "^5.0.0",
2626
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",

packages/codegen/src/assets/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ out/
44

55
.vscode
66
.idea
7+
8+
gql-logs/

packages/codegen/src/templates/config-template.handlebars

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
host = "127.0.0.1"
33
port = {{port}}
44
kind = "{{watcherKind}}"
5-
gqlPath = "/graphql"
65

76
# Checkpointing state.
87
checkpointing = true
@@ -24,25 +23,32 @@
2423
clearEntitiesCacheInterval = 1000
2524

2625
{{/if}}
27-
# Max block range for which to return events in eventsInRange GQL query.
28-
# Use -1 for skipping check on block range.
29-
maxEventsBlockRange = 1000
30-
3126
# Flag to specify whether RPC endpoint supports block hash as block tag parameter
3227
rpcSupportsBlockHashParam = true
3328

34-
# GQL cache settings
35-
[server.gqlCache]
36-
enabled = true
29+
# Server GQL config
30+
[server.gql]
31+
path = "/graphql"
32+
33+
# Max block range for which to return events in eventsInRange GQL query.
34+
# Use -1 for skipping check on block range.
35+
maxEventsBlockRange = 1000
36+
37+
# Log directory for GQL requests
38+
logDir = "./gql-logs"
39+
40+
# GQL cache settings
41+
[server.gql.cache]
42+
enabled = true
3743

38-
# Max in-memory cache size (in bytes) (default 8 MB)
39-
# maxCacheSize
44+
# Max in-memory cache size (in bytes) (default 8 MB)
45+
# maxCacheSize
4046

41-
# GQL cache-control max-age settings (in seconds)
42-
maxAge = 15
43-
{{#if (subgraphPath)}}
44-
timeTravelMaxAge = 86400 # 1 day
45-
{{/if}}
47+
# GQL cache-control max-age settings (in seconds)
48+
maxAge = 15
49+
{{#if (subgraphPath)}}
50+
timeTravelMaxAge = 86400 # 1 day
51+
{{/if}}
4652

4753
[metrics]
4854
host = "127.0.0.1"

packages/codegen/src/templates/indexer-template.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ export class Indexer implements IndexerInterface {
660660
}
661661

662662
async getEventsInRange (fromBlockNumber: number, toBlockNumber: number): Promise<Array<Event>> {
663-
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.maxEventsBlockRange);
663+
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.gql.maxEventsBlockRange);
664664
}
665665

666666
async getSyncStatus (): Promise<SyncStatus | undefined> {

packages/codegen/src/templates/package-template.handlebars

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
4242
"dependencies": {
4343
"@apollo/client": "^3.3.19",
44-
"@cerc-io/cli": "^0.2.93",
45-
"@cerc-io/ipld-eth-client": "^0.2.93",
46-
"@cerc-io/solidity-mapper": "^0.2.93",
47-
"@cerc-io/util": "^0.2.93",
44+
"@cerc-io/cli": "^0.2.94",
45+
"@cerc-io/ipld-eth-client": "^0.2.94",
46+
"@cerc-io/solidity-mapper": "^0.2.94",
47+
"@cerc-io/util": "^0.2.94",
4848
{{#if (subgraphPath)}}
49-
"@cerc-io/graph-node": "^0.2.93",
49+
"@cerc-io/graph-node": "^0.2.94",
5050
{{/if}}
5151
"@ethersproject/providers": "^5.4.4",
5252
"debug": "^4.3.1",
@@ -75,6 +75,7 @@
7575
"eslint-plugin-standard": "^5.0.0",
7676
"husky": "^7.0.2",
7777
"ts-node": "^10.2.1",
78-
"typescript": "^5.0.2"
78+
"typescript": "^5.0.2",
79+
"winston": "^3.13.0"
7980
}
8081
}

packages/codegen/src/templates/readme-template.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
To enable GQL requests caching:
6565

66-
* Update the `server.gqlCache` config with required settings.
66+
* Update the `server.gql.cache` config with required settings.
6767

6868
* In the GQL [schema file](./src/schema.gql), use the `cacheControl` directive to apply cache hints at schema level.
6969

0 commit comments

Comments
 (0)