Exam4Training

How should the Adobe Commerce Architect declare output of this mutation?

An Adobe Commerce Architect is creating a new GraphQL API mutation to alter the process of adding configurable products to the cart. The mutation accepts configurable product ID. If the given product has only one variant, then the mutation should add this variant to the cart and return not nullable Cart type. If the configurable product has more variants, then the mutation should return not

nullable Conf igurableProduct type.

The mutation declaration looks as follows:

How should the Adobe Commerce Architect declare output of this mutation?

A)

B)

C)

A . Option A
B . Option B
C . Option C

Answer: A

Explanation:

Based on the description of the GraphQL API mutation for adding configurable products to a cart in Adobe Commerce, and the provided mutation declaration, the output of this mutation should be able to return two different types based on the condition:

A not nullable Cart type if the given product has only one variant.

A not nullable ConfigurableProduct type if the product has more variants.

To handle such a scenario, GraphQL uses Union types to return different types based on the condition. Here’s how the declaration should be made based on the options:

Option A suggests using a union type named AddToCartOutput, which includes two types: ConfigurableProduct and Cart. This is the correct approach because it allows for returning either type based on the condition.

Option B is not visible to me but assuming it might suggest using a single output type without a union, which would not be suitable for this requirement as we have a conditional output.

Option C is also not visible to me, but if it suggests using an interface, it would not be suitable either because interfaces require that all implementing types have the same fields, which is not the case here since Cart and ConfigurableProduct would likely have different fields.

Exit mobile version