A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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.
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,
},
});
If this fixed your issue, likes and accepting as a solution are highly appreciated.
Build an online presence with our custom built Shopify Theme EcomifyTheme