Query for select fields matching the content of other fields

Hello everyone,

maybe you can help me.

I would like to set options for product variants e.g.

“Size” → “S, L, M”
“Color” → “Red, Green, Blue”

And now, when I create a product variant, I would like e.g.

T-shirt:
Size → L
Color → Blue

that the keys of the option structure are used in the selection fields and the matching tags of the respective key should be used for the values. See source code:

options:
  type: structure
  fields:
    key:
      type: text
    values:
      type: tags

variants:
  type: structure
  fields:
    variant:
      type: structure
      fields:
        optionkey:
          type: select
          options:
            type: query
            query: GET ALL "key"s FROM "options"
        optionvalue:
          type: select
          options:
            type: query
            query: GET ALL "values" FROM "options" THAT MATCHES THE SELECTED "key"

How must the two queries look in order to solve this? Unfortunately, I cannot find a solution.

Many thanks and best regards

This will not work out of the box, because the blueprint and thus the queries are rendered server-side, so the second query will not take into account any changes in the first field.