Skip to content

Commit 8b0b963

Browse files
committed
feat: add subgraph client
1 parent 9fd57bf commit 8b0b963

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
query TokenConverters {
2+
tokenConverters {
3+
id
4+
converterNetwork {
5+
id
6+
}
7+
destinationAddress
8+
baseAsset
9+
configs {
10+
id
11+
tokenAddressIn
12+
tokenAddressOut
13+
incentive
14+
access
15+
}
16+
paused
17+
}
18+
}

subgraph-client/.graphclientrc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sources:
2+
- name: venus-protocol-reserve-chapel
3+
handler:
4+
graphql:
5+
endpoint: https://api.thegraph.com/subgraphs/name/venusprotocol/venus-protocol-reserve-chapel
6+
7+
documents:
8+
- '../**/*.graphql'

subgraph-client/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { DocumentNode } from 'graphql';
2+
import { Client as UrqlClient, createClient } from 'urql/core';
3+
4+
import {
5+
TokenConvertersDocument,
6+
} from './.graphclient';
7+
8+
class SubgraphClient {
9+
urqlClient: UrqlClient;
10+
11+
constructor(url: string) {
12+
this.urqlClient = createClient({
13+
url,
14+
requestPolicy: 'network-only',
15+
});
16+
}
17+
18+
async query(document: DocumentNode, args: Record<string, string>) {
19+
const result = await this.urqlClient.query(document, args).toPromise();
20+
if (result.error) {
21+
console.error(result.error);
22+
}
23+
return result;
24+
}
25+
26+
async getTokenConverters() {
27+
const result = await this.query(TokenConvertersDocument, {});
28+
return result;
29+
}
30+
}
31+
32+
export default new SubgraphClient(
33+
'https://api.thegraph.com/subgraphs/name/venusprotocol/venus-protocol-reserve-chapel',
34+
);

0 commit comments

Comments
 (0)