How to use graphql on the front end
I have currently set up a route as follows:
And this is how I call it on my frontend react file:
However I keep getting this error:
Is there a better way to use the shopify client on the frontend in an embedded app instance
56 Replies
OKay I tried using a global action and it is still giving me problems, I think this is happening mostly because of some authentication issues since the shopify client object is appearing as blank, how to fix this?
Please check one of the recent help posts
https://discord.com/channels/836317518595096598/1327342551228874894/1327388160421924924
okay but I'm not calling it from an extension, this is an embedded app, it is an authenticated instance, idk why its not working
Have a look at these docs
https://docs.gadget.dev/guides/plugins/shopify/frontends
Yeah I did exactly whats in this guide to be precise, the section Calling Shopify within actions guide
And im calling the global action like this in my code:
Someone please help me with this
Hello,
Could you please share the URL of the app and the relevant files? I'd like to take a closer look to assess the issue quickly
hidesort.gadget.app the url
api\actions\savePaymentCustomization.ts
web\routes\new.tsx
And where in the frontend are you making the request?
in the routes\new.tsx line 89:
const [{ fetching: isSaving }, saveSettings] = useGlobalAction(api.savePaymentCustomization);
Oh, I misread, sorry
ignore the PaymentCustomizationForm.tsx and PaymentCustomizationDashboard.tsx in components directory, they're not being used
Would you allow me to make my own connection on your development environment so that I can test it on my end?
oh for sure have at it no worries
just help me fix this I've been sidequested on this stupid issue since the past 3 days almost
How do I submit the form?
just click save on the save bar ui
Interesting. I don't have it

weird it's working for me fine when i make changes
Ohhh. I'm so used to the old app bridge save bar
okay do you see it?
Whoopsie

They should change that
Its so hard to tell that something changed
yup a little unintuitive but used to it now
I wasn't able to get the !shopify statement to run. I'm getting
Cannot read properties of undefined (reading 'currentAppInstallation')
yup that's because the graphql query to get the app id is returning null
howwver when i use the graphql explorer the exact same query does infact return the app id
I think the problem is with the shopify client
What API version do you use in the GraphiQL Playground?
The Shopify client wouldn't make a difference since you're running graphql requests
but the graphql requests are to the shopify api not the gadget api
Oh, I thought you meant the
shopify api node
client
It might be an error in the Shopify API. Do you mind checking the version used in the browser (GraphiQL UI)? It might be on the latest. They did have a ton of issues in 24-10okay wait lemme check
okay so the api version here is 2025-01 and you can see the exact same query returns a valid response for the same app:

Can you try changing the API version to 24-10 to see if you get the same outcome?
yup works just as well

the api version in my gadget app is however 24-10, how od i change that?
You unfortunately can't move between API versions in Gadget. We also haven't yet released 25-01 yet
oh makes sense
Lets see what we can do to resolve this issue for now
so hypothetically for the apps that are live on the store do I create a new app and clone it to upgrade the API version?
and what's causing the issue here because I have followed the exact documentation
to call global actions
Sorry, I should have been more specific. You can't downgrade once you've went to a higher API version
if you check the logs, the shopify connection is also returning a blank object but it isn't returning an error that it is null wither
that's a little weird
The reason we did this (currently) is because there are many moving parts to an upgrade/downgrade. Depending on the direction of the move we'd need to add or remove fields from your application. There's potential data loss and other issues that can happen. I think we have plans to add this in the future
The Shopify connection isn't actually null/undefined. You'd get an error if you tried using shopify.graphql if that were the case. There's only an error in whats returned
understandable, downgrading is not something I look forward to, its just that i want to keep my apps uptodate which isnt a prolem as of now
Might I recommend that instead of immediately trying to destructure the return from the first call, you wait to see whats returned?
That won't be an issue. Upgrades are one click
check line 55 in the global action I try to output the instantiated shopify client:
This returns blank
changed the code to get the entire returned field:
Still got this error:
Yes because its a big object. I would recommend instead logging like this:
But again, thats not the issue here
Change this to something like the following code:

This needs to be switched around

logger.info doesn't behave like console.log
You need to have the object as the first arguement
Take a look at these docs for more information: https://docs.gadget.dev/guides/development-tools/logger#logging-from-actions
Logger - Developer Docs - Gadget
Gadget Docs
umm okay so I did this:
`
Do I have permission to change your code?
Okay I got the error
Just a minute
I used console.log
and voila
I have the result: App installation result: { appInstallationResult: { currentAppInstallation: { id: 'gid://shopify/AppInstallation/536086937819' } } }
SO that means the api is returning the app id correctly
just some problem parsig
you have permission to change my code but I think I got it
Yep, the issue was hidden because you were destructuring
i used console.log to see what the currentAppInstallation query returned
You should use logger.info so that you have more performance and so that you have better structured logs.
Just note that the message is always the second arguement and not the first
alright got it sir
Thank you so much for your help and assistance
I am really so grateful to you you have no idea
I cant believe I spent three days on this lol feeling kinda stupid ngl
but regardless forever indebted to you man
No problem!