Allow to buy product only if another is in the cart

Hi,

I need to make it possible to buy some product X only together with product Y.

I saw this forum thread that suggests using shopify apps for that.

Is it possible to do it with shopify API or shopify GraphQL instead?