I recently had this issue and I was able to resolve this by adding a command in the command.js in cypress's support folder.
Cypress.Commands.add('apiMutation', (mutations) => {
cy.request({
method:'POST',
url:'api/graphql',
body: { query : "mutation" + mutations }
})
})
The problem is that cy.request requires you to have a query inside the body or ofcourse that's what I feel.
You can override this by add the word mutation inside the body before the actual query(mutation). Like below
body: { query : "mutation" + mutations }
And you can make your request like:
describe("Reservation Validations", () => {
it("should return a valid addAdditions mutation", () => {
cy.apiMutation('{addAdditions(reservationId: 1001 reservedResourceId: 100 additions: { resourceId: 10 quantity: 12 }){resourceId type resortArticle}}'
).then((Response) => {
expect(Response.body.data).to.have.property("addAdditions")
expect(Response.body.data.addAdditions).to.not.be.undefined
})
})
})