2.2.1: Our Custom Scenario

2.2: Initial Custom Schema

Now that we've familiarized ourselves with a few examples of Magento GraphQL queries and mutations, it's time to start building our own.

We're going to add GraphQL queries and mutations for a "Group Shipping Policy" site feature. In order to have a good foundation for the concepts behind the functionality we're implementing, the best place for us to start is to outline our requirements scenario in practical terms, just as we would expect from the discovery process with a client or product owner.

The Scenario

Our hypothetical storefront sells specialty products with limited inventory and receives orders from both direct consumers and wholesalers. The target consumer for these specialty items would rather secure their order and wait for inventory availability than find products out of stock, so backorders are common. The merchant must prioritize retail orders over those from wholesalers.

In addition, customers who make frequent purchases become "club" members and get a number of benefits, one of which is priority shipping before other retail customers. And lastly, while the merchant accepts orders from most countries, guaranteed shipping priority only applies to a few; customers placing orders from other countries are encouraged to contact the merchant for more details.

The merchant needs to set proper expectations on their storefront regarding shipping policy and a customer's likely priority level when items are on backorder. To facilitate this, a new entity called a "Group Shipping Policy" has been created, with each policy assigned to a specific customer group and to one or more applicable countries. The merchant wants a dedicated page on the storefront with up-to-date details on all shipping policies, as well as to display the policy relevant to a particular customer at checkout.

In addition, a customer should have the ability to provide their phone number to receive a callback about shipping policy. For this reason, database structure also exists to track "Shipping Policy Callback" records.

The storefront is a PWA build connecting to a Magento backend. A GraphQL query is needed for fetching data about Group Shipping Policies, as well as a mutation for registering a Shipping Policy Callback.

Complete and Continue