If you want to try a different approach while using cy.request
, similar to how you would use restful
in cy.request
, here's a suggestion:
For instance, if your query is named findUser
and involves a variable like username
, the syntax should resemble something along the lines of
findUser(username:"hello"){id, name}
and so forth.
However, instead of just inputting this directly, make sure to format it as json
. For example, if it's a query, it should be structured as
{"query": findUser(username:"hello"){id, name}}
, which will serve as your body.
Below is an illustrative example:
const query = `{
findUser(username:"hello") {
id
}
}`;
cy.request({
url: 'http://localhost/graphql/',
body: { query },
failOnStatusCode: false
}).then((res) => {
cy.log(res);
});