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,
},
});