-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
bc4b91a
commit 1064c5b
Showing
7 changed files
with
94 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { gql } from "urql"; | ||
import { OrderCreatedWebhookPayloadFragment } from "../../../../../generated/graphql"; | ||
import { saleorApp } from "../../../../saleor-app"; | ||
import { SaleorAsyncWebhook } from "@saleor/app-sdk/handlers/fetch-api"; | ||
|
||
/** | ||
* Example payload of the webhook. It will be transformed with graphql-codegen to Typescript type: OrderCreatedWebhookPayloadFragment | ||
*/ | ||
const OrderCreatedWebhookPayload = gql` | ||
fragment OrderCreatedWebhookPayload on OrderCreated { | ||
order { | ||
userEmail | ||
id | ||
number | ||
user { | ||
firstName | ||
lastName | ||
} | ||
} | ||
} | ||
`; | ||
|
||
/** | ||
* Top-level webhook subscription query, that will be attached to the Manifest. | ||
* Saleor will use it to register webhook. | ||
*/ | ||
const OrderCreatedGraphqlSubscription = gql` | ||
# Payload fragment must be included in the root query | ||
${OrderCreatedWebhookPayload} | ||
subscription OrderCreated { | ||
event { | ||
...OrderCreatedWebhookPayload | ||
} | ||
} | ||
`; | ||
|
||
/** | ||
* Create abstract Webhook. It decorates handler and performs security checks under the hood. | ||
* | ||
* orderCreatedWebhook.getWebhookManifest() must be called in api/manifest too! | ||
*/ | ||
export const orderCreatedWebhook = new SaleorAsyncWebhook<OrderCreatedWebhookPayloadFragment>({ | ||
name: "Order Created in Saleor", | ||
webhookPath: "api-v2/webhooks/order-created", | ||
event: "ORDER_CREATED", | ||
apl: saleorApp.apl, | ||
query: OrderCreatedGraphqlSubscription, | ||
}); |
42 changes: 1 addition & 41 deletions
42
src/app/api-v2/webhooks/order-filter-shipping-methods/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,7 @@ | ||
import { gql } from "urql"; | ||
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/fetch-api"; | ||
import { OrderFilterShippingMethodsPayloadFragment } from "../../../../../generated/graphql"; | ||
import { saleorApp } from "../../../../saleor-app"; | ||
|
||
const OrderFilterShippingMethodsPayload = gql` | ||
fragment OrderFilterShippingMethodsPayload on OrderFilterShippingMethods { | ||
order { | ||
deliveryMethod { | ||
... on ShippingMethod { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const OrderFilterShippingMethodsSubscription = gql` | ||
${OrderFilterShippingMethodsPayload} | ||
subscription OrderFilterShippingMethods { | ||
event { | ||
...OrderFilterShippingMethodsPayload | ||
} | ||
} | ||
`; | ||
|
||
export const orderFilterShippingMethodsWebhook = | ||
new SaleorSyncWebhook<OrderFilterShippingMethodsPayloadFragment>({ | ||
name: "Order Filter Shipping Methods", | ||
webhookPath: "api-v2/webhooks/order-filter-shipping-methods", | ||
event: "ORDER_FILTER_SHIPPING_METHODS", | ||
apl: saleorApp.apl, | ||
query: OrderFilterShippingMethodsSubscription, | ||
}); | ||
import { orderFilterShippingMethodsWebhook } from "./webhook"; | ||
|
||
export const POST = orderFilterShippingMethodsWebhook.createHandler((request, ctx) => { | ||
const { payload } = ctx; | ||
console.log("Order Filter Shipping Methods Webhook received with: ", payload); | ||
return new Response("{}", { status: 200 }) | ||
}); | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
}; |
35 changes: 35 additions & 0 deletions
35
src/app/api-v2/webhooks/order-filter-shipping-methods/webhook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { gql } from "urql"; | ||
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/fetch-api"; | ||
import { OrderFilterShippingMethodsPayloadFragment } from "../../../../../generated/graphql"; | ||
import { saleorApp } from "../../../../saleor-app"; | ||
|
||
const OrderFilterShippingMethodsPayload = gql` | ||
fragment OrderFilterShippingMethodsPayload on OrderFilterShippingMethods { | ||
order { | ||
deliveryMethod { | ||
... on ShippingMethod { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const OrderFilterShippingMethodsSubscription = gql` | ||
${OrderFilterShippingMethodsPayload} | ||
subscription OrderFilterShippingMethods { | ||
event { | ||
...OrderFilterShippingMethodsPayload | ||
} | ||
} | ||
`; | ||
|
||
export const orderFilterShippingMethodsWebhook = | ||
new SaleorSyncWebhook<OrderFilterShippingMethodsPayloadFragment>({ | ||
name: "Order Filter Shipping Methods", | ||
webhookPath: "api-v2/webhooks/order-filter-shipping-methods", | ||
event: "ORDER_FILTER_SHIPPING_METHODS", | ||
apl: saleorApp.apl, | ||
query: OrderFilterShippingMethodsSubscription, | ||
}); |