You need to grant write access for your web server to the .graphql-generated directory in your development environment, and if you aren’t committing it to your version control or creating it in a CI step then it also needs to have access in your production environment. This is mentioned in the filesystem permissions documentation.
I had granted access to .graphql-generated directory with sudo chmod a+rwx -R directory
but the result is still same,
Note : this error message isn’t always appear, unless if the position in the events (odd and events) then the message appear,
for example : if I run dev/build at :
first attempt this error message not appear,
but on second attempt this error message appear,
the third attempt same as he first and the fourth same as the second
Ahh, I think I didn’t see part of the error message you showed which might explain this:
That seems to indicate that one of the files in the .graphql-generated directory is being read - either by the Silverstripe application or by something else on your system - at the time Silverstripe wants to clear it. This explains why it is happening only every second attempt - after the first attempt, there is some lingering process which is still accessing the file. By the time you attempt it a third time, that process has finished.
Try simply waiting a little bit longer between dev/build attempts.