Firstly, we need to clarify who is a wali and can he get benefit or prevent harm. Sheikh `Atiyyah Saqr, former head of Al-Azhar Fatwa Committee, states:

The term Wali stands for anyone who fulfils the obligations Allah has levied on him, and as such he is protected by Allah on that basis. Allah says in the Qur’an: (Lo! verily the friends of Allah are (those) on whom fear (cometh) not, nor do they grieve! Those who believe and keep their duty (to Allah). ) (Yunus: 62- 64)
In these verses, Allah Almighty describes the Wali as he who is amongst (those who believe and keep their duty (to Allah).) That means he fulfills his obligations and carries out what Allah has ordained on him. Keeping one’s duty to Allah means to comply with His commands and stay away from what He forbids in all aspects of life: Islamic rituals, manners, business dealings, etc.
the reward of that commitment to Allah is also mentioned in the verse: (On whom fear (cometh) not, nor do they grieve) meaning that they should not worry about their future, nor regret their past. Allah states elsewhere: (Theirs are good tidings in the life of the world and in the Hereafter.) (Yusus: 64) This indicates that Allah has protected them and taken care of their life and even the Hereafter (by granting them abundant reward).”

There are devout persons who deserve all respect and honor. We should respect them, love them and ask them to supplicate Allah for us because the supplication of the righteous persons is answered by Allah. Yet, asking them to supplicate for one is limited to their being alive; if they are dead, asking them to supplicate for one is against true faith.

The late sheikh Ibn Baz, a renowned Muslim scholar, said,

“The saying that the dead Walis can cause benefit or prevent harm is among the most abominable sayings and is included in kufr and shirks with Almighty Allah. This is because Allah Alone who can bring benefit or cause harm, not the dead walis. Allah, the exalted, said addressing the Prophet (peace and blessings be upon him)( Say: For myself I have no power to benefit, nor power to hurt, save that which Allah willeth.)(Al-A`raf, 7:188)

It is quite clear that the dead persons, who become unable to move and their life comes to an end, cannot cause benefit or harm because they are deceased and decline to do any thing. The same is true during their life, because the only one who can do harm or benefit is Allah and they cannot do such things except with Allah’s leave.”

Thus, a wali, during his life, cannot cause harm or benefit, except for supplicating Allah, who alone can do harm or benefit, who may answer his supplication or may not. Then, a dead wali is a lifeless being who can do anything. This needs no evidence because he is a human being and all dead human beings, even the Prophets, can do nothing for themselves after death. This is unquestionable.

As regards offering mazars (walis’ graves), they are like any other grave. It is permissible to visit graves for the purpose of making du’aa’ for the dead, praying for mercy for them, remembering death and preparing oneself for the Hereafter. The Prophet (peace and blessings be upon him) said: “Visit the graves, for they remind you of the Hereafter.”

However, visiting graves for the purpose of calling upon their occupants, seeking their help, offering sacrifices to them and making vows to them, is forbidden.
We again state that asking a righteous person to make du’a’ for one when he is still alive – this is permissible, because there is the hope that his du’a’ may be answered because of his righteousness. The evidence for this is:
It was reported from ‘Uthman ibn Hanif (may Allah be pleased with him) that a blind man came to the Prophet (peace and blessings be upon him) and said: “Pray to Allah to heal me.” He said, “If you wish, I will pray for you, and if you wish, I will delay that, and that will be better.” (Ahmad, al-Tirmidhi and Ibn Maajah)

Then, if a wali or Prophet dies, it is not correct, according to shari`ah, to ask him to make du’a’ for you, because he has been cut off from this world. This is a kind of shirk which is not committed by any of the righteous people of this Ummah, the Sahabah and those who follow them.
allah says:
And who is more astray than one who calls on (invokes) besides Allâh, such as will not answer him till the Day of Resurrection, and who are (even) unaware of their calls (invocations) to them? And when mankind are gathered (on the Day of Resurrection), they (false deities) will become their enemies and will deny their worshipping” [Al-Ahqaf 46:5-6]

May Allah guide all of us to what pleases Him!