In my experience, it has become evident that the query letter should be written early on in the writing process. This is because the query letter has a way of flushing out problems with the overall manuscript.
There are four questions that must be answered in order for your query letter to be enticing. They are: Who is your protag? What does he/she want? What/Who’s stopping them from getting it? What are the stakes? If you can’t answer these questions, then you don’t have a story.
I have learned this the hard way, resulting in the complete rewrite in my sci-fi novel.
I have another fantasy novel in the works, and am nearing the end of my first draft. My intentions are to sit down after completing the draft and write my query letter. I want to put everything into one concise place, because I surely don’t want to have to start all over, again.
Now you might say, “Well, I plot everything out, so I know what I’m doing”. Well, I do to. But that doesn’t mean you have a story. I’m a member of several writing/critiquing websites and there are a lot of people who don’t realize that they don’t have a story.
You might also ask, “Why not just answer these four questions and get on with it?” The answer is because writing a query letter is a tedious exercise which will not only allow you to see your ms for what it really is, but help you focus on what’s most important. Or what is being conveyed as most important. Trust me, if you can conquer the query letter, then your ms will be a breeze.
Obviously you don’t want to send out that query letter until your ms is polished, and then you will probably be rewriting that letter to adjust for improvements made to your ms during the editing process.
Here are a couple of references for writing a query letter: