Product specific fields based on category

Hi.

I’d like to create a product catalog. Each product has common fields like:

  • category
  • name
  • price

and also each product should have some specific fields based on selected product category.

For example if product category is the car then product must have:

  • engine
  • mileage

if product category is the house then product must have:

  • material type
  • number of floors

I created collection type “product” and added common fields for all products. But I could not find any information how to add fields based on selected product category…

I had another idea to create multiple collection types for each product category and to add additional graphql field which will return all product something like this:


union Product = Car | House

type Query {
  products: [Product]
}

But in this case I have no idea how to reuse common fields like category, name, price between all collection types.

Could somebody please explain me how to handle my case?

Thanks in advance.

2 Likes