Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
DeleteWebhook with example
Browse files Browse the repository at this point in the history
  • Loading branch information
jstep committed Oct 17, 2023
1 parent 65f7296 commit cec8cdc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
74 changes: 44 additions & 30 deletions examples/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sdk = new Defined(process.env.DEFINED_API_KEY || "");
sdk
.send<{ getNetworks: Network[] }>(
`query GetNetworks { getNetworks { id name } }`,
{}
{},
)
.then((res) => {
console.log("Networks: ", res.getNetworks);
Expand Down Expand Up @@ -79,32 +79,46 @@ sdk.queries
})
.then(console.log);

// Uncomment to test createWebhooks mutation
// sdk.mutations
// .createWebhooks({
// input: {
// priceWebhooksInput: {
// webhooks: [
// {
// name: "SDK test webhook",
// callbackUrl:
// "https://webhook.site/#!/697da597-6f40-4bec-b59a-3b6dc2e680b8",
// securityToken: "1234567890",
// alertRecurrence: AlertRecurrence.Once,
// conditions: {
// priceUsd: {
// gt: "100",
// },
// networkId: {
// eq: 1,
// },
// tokenAddress: {
// eq: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
// },
// },
// },
// ],
// },
// },
// })
// .then(console.log);
// Mutations

// Example showing how to create a webhook and how to delete it.
sdk.mutations
.createWebhooks({
input: {
priceWebhooksInput: {
webhooks: [
{
name: "SDK test webhook",
callbackUrl:
"https://webhook.site/#!/697da597-6f40-4bec-b59a-3b6dc2e680b8",
securityToken: "1234567890",
alertRecurrence: AlertRecurrence.Once,
conditions: {
priceUsd: {
gt: "100",
},
networkId: {
eq: 1,
},
tokenAddress: {
eq: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
},
},
},
],
},
},
})
.then((data) => {
console.log(data);
const webhookId = data?.createWebhooks?.priceWebhooks?.[0]?.id;
if (webhookId) {
sdk.mutations
.deleteWebhooks({
input: {
webhookIds: [webhookId],
},
})
.then(console.log);
}
});
4 changes: 4 additions & 0 deletions src/sdk/Mutation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { DeleteWebhooksInput } from "../resources/graphql";
import {
CreateWebhooksDocument,
CreateWebhooksInput,
DeleteWebhooksDocument,
} from "./generated/graphql";
import { Defined } from "./index";

export class Mutation {
constructor(private sdk: Defined) {}
createWebhooks = async (vars: { input: CreateWebhooksInput }) =>
this.sdk.mutation(CreateWebhooksDocument, vars);
deleteWebhooks = async (vars: { input: DeleteWebhooksInput }) =>
this.sdk.mutation(DeleteWebhooksDocument, vars);
}
Loading

0 comments on commit cec8cdc

Please sign in to comment.