Publish directly to POS channel only

claytonnl
Shopify Partner
2 0 1

Currently trying to completely move remaining REST calls in my app to GQL. Is it possible to directly publish from the productCreate mutation to the POS channel only? The Shopify frontend still uses the publications input on the frontend that has now been deprecated for years. It seems like this is no longer possible in one request, but that makes absolutely no sense so I'm just hoping I've overlooked something.

Reply 1 (1)

EcomGraduates
Shopify Partner
588 48 77

hello there 

 

It is possible to publish a productCreate mutation directly to the POS channel using GraphQL. However, the way to do this would be to subscribe to the productCreate event and publish the product to the POS channel within your app's code.

When subscribing to the productCreate event, you can filter the events to only listen for products that are created through your app. Then, within the event listener, you can use the GraphQL API to publish the product to the POS channel.

Here's an example of how this could be done:

Subscribe to the productCreate event and filter for products created by your app:

subscription { productCreate(input: { ownerTypes: ["APP"] }) { product { id title # any other fields you need to publish to POS } } }

 

In your event listener, publish the product to the POS channel using the GraphQL API:

 

import { gql } from '@apollo/client';

const PUBLISH_TO_POS_MUTATION = gql`
  mutation PublishToPOS($productId: ID!) {
    publishableChannelCreate(input: {
      publicationableId: $productId,
      publicationableType: PRODUCT,
      channelId: "gid://shopify/Channel/POS"
    }) {
      publicationable {
        id
      }
    }
  }
`;

// ... inside your event listener
client.mutate({
  mutation: PUBLISH_TO_POS_MUTATION,
  variables: {
    productId: event.productCreate.product.id,
  },
});