Reputation: 81
I wonder if there is a way to send GraphQL mutations using Cypress?
There is cy.intercept()
but this is more for waiting for responses.
Upvotes: 0
Views: 406
Reputation: 8322
You can use cy.request()
, you only need to know how GraphQL works and what format of the payload you need to send to your endpoint.
An example could be:
describe('GraphQl example', () => {
it('Send req to graphql endpoint', () => {
const query = `{
speakers(name: "Miloš") {
id
firstName
lastName
}
}`;
cy
.request({
url: 'https://demagog.cz/graphql',
method: 'POST',
body: { query }
})
.then(res => {
cy
.log(res);
});
});
});
And I easily get a successful response with data:
Things you need to know:
cy.request()
Upvotes: 2