Closed kmajay978 closed 1 year ago
You can't use clientProvider
in webhooks. shop
is already available in webhook function params, use that to load session ID and then sessionHandler.loadSession()
to load a session and pass it to shopify
to create a new GraphQL client
Ok got it, but I do have one doubt, from where to load session Id using shop? From Database?
Kindly provide the code sample if possible, I am trying to work with shopify webhook and client from 2 days, but no luck. Help would be appreciated.
Thanks
Read the documentation: https://github.com/Shopify/shopify-api-js#guides
Hi @kinngh
I tried with the documentation, and here is my code, but still things not working and i am getting accessToken undefined issue.
Here is my approach, let me know what i am missing here.
const sessionResult = await SessionModel.findOne({shop}); //offline session
const session = await sessionHandler.loadSession(sessionResult.id);
console.log(session,'newSession.......');
const client = new shopify.clients.Graphql({ session });
const work = await client.query({ data: TEST_QUERY });
console.log(work,'work............');
Error i am getting
[server] TypeError: Cannot read properties of undefined (reading 'accessToken')
[server] at new GraphqlClient (E:\Shopify app\mypre\node_modules\@shopify\shopify-api\lib\clients\graphql\graphql_client.js:14:57)
Hello @kinngh , after researching a lot, i got to know that issue was related to package, it seems it doesn't support properly. Now i sifted on official package and it's working fine with official package. Thanks anyway.
@kmajay978 just a heads up, there's an update to clientProvider
so you can create a new client with clientProvider.offline
method
I am working with order create and order update webhook. I wanted to add the tags to the order but i am not able to do it. Kindly let me know how to work with Graphql in webhook.
Query:- How can i pass the req, res in clientProvider.graphqlClient using webhook file. (orders_create.js)
Here is the code , what i am trying to do.
import clientProvider from "../../utils/clientProvider.js";
Code