QuestionQ3

Orders, Payments, Shipping, and Tax

An Adobe Commerce Architect is developing a new GraphQL API mutation to change how configurable products are added to the cart. The mutation accepts a configurable product ID. If the supplied product has only one variant, the mutation must add that variant to the cart and return a non-null Cart type. If the configurable product has multiple variants, the mutation must return a non-null ConfigurableProduct type.

The mutation declaration is as follows:

Question Image

How should the Adobe Commerce Architect declare this mutation’s output?

  • A
  • B
  • C
Explanation

A GraphQL union represents a result that can be one of several object types without requiring those types to share fields. AddToCartOutput must therefore be a union of ConfigurableProduct and Cart, with a type resolver that determines the concrete returned type. The mutation’s AddToCartOutput! return type ensures that one of those results is non-null.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!