|
1 | 1 | import { Defined } from "@definedfi/sdk"; |
2 | 2 |
|
3 | | -import { Network } from "../../src/resources/graphql"; |
| 3 | +// import { AlertRecurrence } from "../../dist/sdk/generated/graphql"; |
| 4 | +import { AlertRecurrence, Network } from "../../src/resources/graphql"; |
4 | 5 |
|
5 | 6 | const sdk = new Defined(process.env.DEFINED_API_KEY || ""); |
6 | 7 |
|
7 | 8 | sdk |
8 | 9 | .send<{ getNetworks: Network[] }>( |
9 | 10 | `query GetNetworks { getNetworks { id name } }`, |
10 | | - {} |
| 11 | + {}, |
11 | 12 | ) |
12 | 13 | .then((res) => { |
13 | 14 | console.log("Networks: ", res.getNetworks); |
@@ -74,6 +75,50 @@ sdk.queries |
74 | 75 |
|
75 | 76 | sdk.queries |
76 | 77 | .getWebhooks({ |
77 | | - webhookId: "45b7de27-8063-40b9-85c1-c716c37379ba", |
| 78 | + webhookId: "802cda45-5cc4-4bec-b456-5bec5a08cec4", |
78 | 79 | }) |
79 | 80 | .then(console.log); |
| 81 | + |
| 82 | +// Mutations |
| 83 | + |
| 84 | +// Example showing how to create a webhook and how to delete it. |
| 85 | +sdk.mutations |
| 86 | + .createWebhooks({ |
| 87 | + input: { |
| 88 | + priceWebhooksInput: { |
| 89 | + webhooks: [ |
| 90 | + { |
| 91 | + name: "SDK test webhook", |
| 92 | + callbackUrl: |
| 93 | + "https://webhook.site/#!/697da597-6f40-4bec-b59a-3b6dc2e680b8", |
| 94 | + securityToken: "1234567890", |
| 95 | + alertRecurrence: AlertRecurrence.Once, |
| 96 | + conditions: { |
| 97 | + priceUsd: { |
| 98 | + gt: "100", |
| 99 | + }, |
| 100 | + networkId: { |
| 101 | + eq: 1, |
| 102 | + }, |
| 103 | + tokenAddress: { |
| 104 | + eq: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + ], |
| 109 | + }, |
| 110 | + }, |
| 111 | + }) |
| 112 | + .then((data) => { |
| 113 | + console.log(data); |
| 114 | + const webhookId = data?.createWebhooks?.priceWebhooks?.[0]?.id; |
| 115 | + if (webhookId) { |
| 116 | + sdk.mutations |
| 117 | + .deleteWebhooks({ |
| 118 | + input: { |
| 119 | + webhookIds: [webhookId], |
| 120 | + }, |
| 121 | + }) |
| 122 | + .then(console.log); |
| 123 | + } |
| 124 | + }); |
0 commit comments