Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to override apiVersion from graphql api client after its defined from shopifyApp (used in shopify-app-remix) #1889

Closed
muchisx opened this issue Dec 18, 2024 · 3 comments
Assignees

Comments

@muchisx
Copy link

muchisx commented Dec 18, 2024

Overview

In here, you can see that the version of the client becomes hardcoded once the shopifyApp is declared once with the first version.

return async function query(operation, options) {
const client = new params.api.clients.Graphql({
session,
apiVersion: options?.apiVersion,
});

An example of this is the shopify remix template shopify.server.ts file, here:

https://github.com/Shopify/shopify-app-template-remix/blob/465a566475badecfd81ccc56ceefd704e3a1a99b/app/shopify.server.ts#L10-L15

const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
  apiVersion: ApiVersion.October24,  // <-------- Hardcoding api version here, ideally this would be a fallback/default instead,
  scopes: process.env.SCOPES?.split(","),
  appUrl: process.env.SHOPIFY_APP_URL || "",
  authPathPrefix: "/auth",
  sessionStorage: new PrismaSessionStorage(prisma),
  distribution: AppDistribution.AppStore,
  future: {
    unstable_newEmbeddedAuthStrategy: true,
    removeRest: true,
  },
  ...(process.env.SHOP_CUSTOM_DOMAIN
    ? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
    : {}),
});

What we want to acheive is to have a default for most operations in provided by the shopifyApp config and then the ability to override it in the graphql client exported from the majority of the auth contexts.

Like so:

export const loader = async ({ request }: LoaderFunctionArgs) => {
  const {
    admin: { graphql },
  } = await authenticate.admin(request);

  const res = graphql(UNSTABLE_QUERY, {
    apiVersion: ApiVersion.Unstable,
  })

As of today, I've tried and I can't get it to work, which leads me to believe that even if the apiVersion param is exposed by the graphql function's options, it's not passed down.

@lizkenyon
Copy link
Contributor

Hi there 👋

I think this would be a good improvement. I am going to move this to the teams work backlog for the new year.

@lizkenyon
Copy link
Contributor

Hi 👋

I just spent some time looking into this and I am not able to reproduce the issue. When I pass in an API version it successfully overrides the request. Please let me know if I am misunderstanding the issue.

e.g.

//shopify.server
const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
  apiVersion: ApiVersion.October24, // Defaulted to October
  scopes: process.env.SCOPES?.split(","),
  appUrl: process.env.SHOPIFY_APP_URL || "",
  authPathPrefix: "/auth",
  logger: {
    level: 3,
    httpRequests: true,
  },
  sessionStorage: new PrismaSessionStorage(prisma),
  distribution: AppDistribution.AppStore,
  future: {
    unstable_newEmbeddedAuthStrategy: true,
    removeRest: true,
  },
  ...(process.env.SHOP_CUSTOM_DOMAIN
    ? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
    : {}),
});
//app/routes/app._index.jsx

...
export const action = async ({ request }) => {
  //const { admin, session } = await authenticate.admin(request);

  const {
    admin: { graphql },
  } = await authenticate.admin(request);
  const color = ["Red", "Orange", "Yellow", "Green"][
    Math.floor(Math.random() * 4)
  ];
  const response = await graphql(
    `#graphql
      mutation populateProduct($product: ProductCreateInput!) {
        productCreate(product: $product) {
          product {
            id
            title
            handle
            status
            variants(first: 10) {
              edges {
                node {
                  id
                  price
                  barcode
                  createdAt
                }
              }
            }
          }
        }
      }`,
    {
      variables: {
        product: {
          title: `${color} Snowboard`,
        },
      },
      apiVersion: ApiVersion.Unstable, // Set to unstable for this request
    },
  );

In our logs we can see that unstable was used for the request.

Image

@lizkenyon lizkenyon self-assigned this Jan 14, 2025
@muchisx
Copy link
Author

muchisx commented Jan 16, 2025

@lizkenyon I've checked with the latest version and I confirm what I'm requesting is possible!

Thank you for checking. I must've done something wrong on my first try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants