App reviews, troubleshooting, and recommendations
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
I'm adding a webhook, and in that webhook I want to make a graphql call to modify an order.
export const action = async ({ request }) => {
const { payload, topic, shop, session, admin } = await authenticate.webhook(request);
switch (topic) {
...
case "CHECKOUTS_CREATE":
if (admin) {
admin.graphql.query(`query here...`)
}
...
I assumed that I could use the graphql client here, but I get a TS error `Argument of type 'string' is not assignable to parameter of type 'GraphqlParams'.`
What is the right way to do this?
OK, so for some reason the `admin.graphql` that comes back from `authenticate.webhook` is different than what comes back from `authenticate.admin`. If I pass `{data: "query here..."}` this works. Now I just need to craft the right query.
Damn, thanks man. I really hate Shopify's docs.
inside yourAppName/app/routes/webhooks.jsx
case "CHECKOUTS_CREATE":
if (session) {
const response = await admin.graphql.query({data: `
query {
shop {
name
}
}`
});
}
break;
I'm getting the same issue. Would you mind sharing the docs you refer to / what was your solution?
Thanks!
if anyone is facing the same issue, here's what works for me:
isHook - true if it's from webhook's admin, false if it's from the web admin.
I have spent so long trying to figure out how to make admin graphQL calls from a webhook, and your answer solved it. Sincerely, thank you so much for sharing.
PS: Why there doesn't seem to be anything about this in the docs is beyond me!