-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathindex.ts
More file actions
57 lines (51 loc) · 1.51 KB
/
index.ts
File metadata and controls
57 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { getExecutor } from '@graphprotocol/client-runtime'
import fusiongraph from '../fusiongraph'
import { parse } from 'graphql'
const executor = getExecutor({
fusiongraph,
})
async function main() {
const response = await executor({
document: parse(/* GraphQL */ `
fragment UserFields on User {
# Shared unique identifier field
id
# Field from uniswap source
ERC721tokens(first: 1001) {
# Testing auto pagination by exceeding the limit of 1000
id
uri
}
# Field from nft source
liquidityPositions(first: 1) {
id
}
}
query ExampleQuery {
# Get base entity from nft source
account(id: "0x72ba1965320ab5352fd6d68235cc3c5306a6ffa2") {
...UserFields
}
# Get base entity from uniswap source
# user(id: "0x72ba1965320ab5352fd6d68235cc3c5306a6ffa2") {
# ...UserFields
#}
}
`),
})
if (Symbol.asyncIterator in response) {
throw new Error('Unexpected async iterator response')
}
if ('errors' in response && response.errors?.length) {
for (const error of response.errors) {
console.error(error.message)
}
} else {
console.log(`
Account: ${response.data?.account.id} has
${response.data?.account.ERC721tokens.length} ERC721 tokens and
${response.data?.account.liquidityPositions.length} liquidity positions
`)
}
}
main().catch((e) => console.error(`Failed to run example:`, e))