-
Notifications
You must be signed in to change notification settings - Fork 28
/
graphql-gql-tag.ts
70 lines (63 loc) · 1.8 KB
/
graphql-gql-tag.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
import { DFUSE_API_KEY, runMain, prettifyJson, DFUSE_API_NETWORK } from "../../config"
import { createDfuseClient, GraphqlResponse } from "@dfuse/client"
import gql from "graphql-tag"
import { print as printGraphqlDocument } from "graphql/language/printer"
/**
* This example showcases usage of `gql` string template literal
* that parses the GraphQL document before sending it to the server
* so you are sure the syntax is correct. This feature depends on
* package `graphql-tag` and `graphql` to be available. The actual
* parsing and turning them into proper JSON can be performed
* at compile time using the appropriate Webpack or Rollup loader.
*
* Those dependencies are totally optional, check out the `examples/basic/gragpql-search-your-latest-transactions.ts`
* file for an example that does not use those depencendies.
*/
type Message = {
searchTransactionsBackward: {
results: {
block: {
num: number
}
trace: {
id: string
matchingActions: {
json: any
}[]
}
}[]
}
}
async function main(): Promise<void> {
const client = createDfuseClient({
apiKey: DFUSE_API_KEY,
network: DFUSE_API_NETWORK,
})
try {
const response = (await client.graphql(printGraphqlDocument(searchTransferQuery), {
variables: { limit: 10 },
})) as GraphqlResponse<Message>
console.log(prettifyJson(response))
} catch (error) {
console.log("An error occurred", error)
}
client.release()
}
const searchTransferQuery = gql`
query($limit: Int64!) {
searchTransactionsBackward(query: "receiver:eosio.token action:transfer", limit: $limit) {
results {
block {
num
}
trace {
id
matchingActions {
json
}
}
}
}
}
`
runMain(main)