The best way to execute mutations for extension-only apps

Hi,

When you develop an extension-only app that is hosted by Shopify, what is the best way to execute the mutations that create the function instances?
Normally I would implement it such that it happens automatically using the token to access to API after the app has been installed in a shop, but as extension-only apps are hosted by Shopify I do not know how to get the token for a shop install.
I currently execute the mutation from GraphiQL which works, but I expect there is a better way to do it.

Kind regards,
-Louise

Sounds like you want the token - but the thing is extension only apps cannot be published to the app store, and for private apps, it’s manual anyways.
Also, recommended route is to proxy the requests via an endpoint you create in your app and not directly from extension

Hey @Lull For extension only apps I also use the GraphiQL app to run the mutations like cartTransformCreate manually. I’m not aware of a better way to do it.

Currently not all Function APIs are well supported in extension-only apps. The best supported extension-only APIs allow use of Admin API extensions for enabling and configuring functions, but as of writing this only two support them.

Alternatives at the moment are to use the GraphiQL app (not the CLI-integrated GraphiQL), which has the ability to enable functions in any app, or to enable the function in an admin UI extension. The latter has direct API access, but at the moment your options for where to place these extensions are limited, so from a UX perspective it could be odd.

1 Like

Thank you for your answer. The recommended route you mention is for full apps though right - that is not something you can do in an extension-only app?

Thank you for your answer - if there is no better way, then I’ll let it go :+1:

@NickWesselman Thank you for your answer. Ok so I could do an extension-only app with an admin API extension that can create the function instance? So you can define a mutation in the admin API extension, or how does it work?

@Taksh_Shah Ok it makes sense that it is manual to create the function when it is not possible to have an extension-only app in the app store, thanks.

Thank you for your answer. Ok so I could do an extension-only app with an admin API extension that can create the function instance? So you can define a mutation in the admin API extension, or how does it work?

Some function APIs have direct support for associating an Admin UI extension:

If the Function API you are using does not, you can create an Action or Block extension against one of the supported targets, and use Direct API access from the extension to run the mutation.

async function makeGraphQLQuery(query, variables) {
  const graphQLQuery = {
    query,
    variables,
  };

  const res = await fetch("shopify:admin/api/graphql.json", {
    method: "POST",
    body: JSON.stringify(graphQLQuery),
  });

  if (!res.ok) {
    console.error("Network error");
  }

  return await res.json();
}

@NickWesselman Ok super, thank you very much!

@NickWesselman Would be really neat if we could get admin extension targets for the shop settings page. Would be an ideal place for configuring functions that affect a store globally.

Removed cart-transform, cart-validation, delivery-fulfilment, discount-functions