Can't publish Shopify Function

I’m working on implementing a Shopify Function into a Shopify app built with Express and React. I am not using a Shopify app template but I have successfully set up an App TOML on the root of my project and managed to generate the Shopify Function and push it up to my Shopify partners account using the command below.

Shopify app deploy --no-release

When I take a look at my Shopify partner account, I can see the Shopify Function listed as published.

And in this image below you can see that when I install my app on a Shopify Store, Shopify Functions is listed as part of the app permissions.

But even after confirming all of this I don’t see my Shopify Function listed on the my Shopify Store when I run a GraphQL query for the available Shopify Functions.

For reference, this is the query I am running:

query {
   shopifyFunctions(first: 30) {
    edges{
      node{
        id
        title
      }
    }
  }
}

I need to confirm that the function exists so I can activate it with a GraphQL mutation.

Is there anything else I need to do in order for the Shopify Function to be listed on my Shopify Store?

Hey @Patrick_Pierre,

Just to make sure, when you query the functions are doing that through your app? I just ask as I’ve often seen where developers will use a different app for the query resulting in an empty response

Hey Kyle, I was using the GraphiQL Shopify App to check for the existing Shopify Functions on my Shopify Store.

When I run the query that I mentioned above, I can see a bunch of Shopify Functions from other apps installed on my store, but I don’t see the one I created.

Can you help me to figure out why this is happening?

Interesting. Can you try using your app instead of the Shopify graphiql app?

Hey Patrick? Were you able to test the query with your app? The reason I ask is the admin graphql app can have many different factors that control what is returned, including the provided access scopes and user permissions. Relying on your own app for these queries would be the most consistent experience and make it easier to troubleshoot.

Hey @KyleG-Shopify, I haven’t managed to try your suggestion yet because I ran into another issue. I tried to reset the permissions on my Shopify App by uninstalling the app, wiping my database and then re-installing it but I ran into an OAUTH error.

During the OAUTH process I got the following error message:

Could not find an OAUTH cookie for shop url

I did search for this issue online and found a lot of people complaining about it but I couldn’t find a solution. I also left a comment on another post in the community about this hoping someone had already solved this problem.

I struggled with the issue for a few days and tried everything I could think of but I came to the conclusion that the issue has to do with the library I was using.

Just for your reference I was using the Shopify App Express library listed on npm.

I took a step back and took a look at a few different Github repos from Shopify on Shopify App Development and saw this note:

If you are building an embedded app, we strongly recommend using Shopify managed installation with token exchange instead of the authorization code grant flow.

I’m currently using the authorization code grant flow so I need to switch to using the Shopify managed installation.

Are there any examples of this being done in a non-remix app?

Please let me know if you can recommend any resources for this.

Hey @Patrick_Pierre, I just tested here and spun up a new app using the express library linked here: Shopify API, libraries, and tools

npm init @shopify/app@latest -- --template=node

This template also uses managed installation and was working on my fresh install.

Hey @KyleG-Shopify , I span up this template on my end just to get a closer look at how everything is set up and would like to ask you a question.

Where exactly in the template is the token exchange happening?
For your reference this link below on one of the Shopify API docs (on Github) mentions that Shopify recommends using a token exchange strategy to handle OAUTH.

But when I look at the code in the node template, I don’t see anything related to the token exchange.

I took a look at web/index.js (in the express template) and that seems to be the file that is run when the web server is turned on.

In that file I see this code from the Shopify express package:

app.get(shopify.config.auth.path, shopify.auth.begin());
app.get(
  shopify.config.auth.callbackPath,
  shopify.auth.callback(),
  shopify.redirectToShopifyOrAppRoot()
);

This is the code that is used to handle the auth process but I wanted to se get more insight into how it worked because this is what triggered my cookie issue. I had a pretty similar set up in my own project when I encountered the error.

Is the code I mentioned above used for the token exchange or is this using the previous OATUH strategy?

Sorry if this is getting a little off-topic but this is the thing stopping me from being able to re-install my app and implement your suggestion to check for my Shopify Function.

Hey @KyleG-Shopify
I managed to resolve my OAUTH Cookie issue by switching over to using OAUTH Token Exchange in my app.

Just in case anyone else reading this has the same OAUTH cookie issue that I had, here is the post that helped me fix the issue:

After resolving my OAUTH issue, I managed to publish my Shopify Function properly by running the following command:

shopify app deploy

In my initial post, you’ll see that I ran the deploy command with this flag: –no-relesae. It was working once I removed that flag.

Now I am able to see my function in GraphQL requests made by my app as well as requests made with the Shopify GraphiQL App.

All I have do do now is run a GraphQL mutation to activate the Shopify Function on my Shopify Store and it should be working as intended.

@KyleG-Shopify do you have any recommendations on how activate the function on any Shopify Store that installs my app? Am I supposed to run a GraphQL mutation during the app installation process or is it automatically activated on any store that installs my app?

Hey Patrick! Thanks for the follow up and the detailed resolution.

Yes, you’ll need to activate the function after the merchant installs your app. You could do this programmatically after the installation, or build that in to the onboarding steps.