If x apples are produced in an economy, and only x - y are consumed (y apples get rotten at different stores in the country), is the value of these wasted apples considered as a part of GDP?
It may depend on when they are wasted:
yes if a consumer purchases them, as it does not matter whether they are eaten or thrown away rotten from the consumer's cupboard (except on the consumer's waistline and perhaps therefore on other purchases);
no if a producer fails to sell them and writes them off as they rot in the producer's stores, as they have a value of zero
probably not if a retailer buys them from the producer but writes them off as they rot in the shop, as they count towards GDP from the producer's accounts but negatively towards from the retailer's accounts (either as negative profit in the GDP income calculation, or as consumption of intermediate goods in the GDP production calculation, or simply not counted in the GDP expenditure calculation)
Remember that GDP is the total income produced in an economy, in addition to a measure of total production. It is usually easier for accounting purposes to think in terms of income.
So if a farmer grows some apples and sells them to a store that counts towards his income and toward GDP. Now suppose the store sells that apple to a customer. For simplicity, assume the store is owned by a single person. Then the store (presumably) made a profit on that apple so that sale also added to GDP. If instead the apple rots and the store fails to sell it then we never get that extra GDP but the farmer's income still counts.
If it sounds dumb that an apple no one eats counts toward GDP, remember that if the farmer ate the apple it wouldn't count. Or that if he poisoned the apple and sold it and killed someone that would count even more. GDP is not meant to measure the value of production in some general sense, so don't expect it to match your intuition.