Queries, pitches and synopses are different things.
A query is a one-page letter that explains what you’ve written, who you are, and why the agent should represent you or publisher should consider your book. In a query letter will be a pitch, which is an explanation of your story in 3-5 sentences. It’s like the text you see on the back of a DVD box. It’s designed to pique your interest. A pitch, like the back of a book or DVD, will not spill the beans regarding the ending.
A synopsis is a front-to-back telling of what happens in your story. It’s like sitting down with a 12-year-old and explaining your entire story in about five minutes. You explain who the characters are, what the conflict is, the three acts, and finally, what happens at the end (e.g., the villain dies). In a synopsis, you do indeed give away the ending. You would not do so in a pitch, and a pitch is what appears in a query.