作者:天呀你呀_778 | 来源:互联网 | 2022-12-19 17:38
我在Google上搜索过类似内容,cypress request with graphql
但我看到很多人都在谈论mock up server
,stub
等等。但是我无法找到完整的示例以及如何cypress.io
与graphql
using请求一起使用。
有谁知道它是如何cy.request
工作的,graphql
或者在哪里可以找到它的解决方案?
在此先感谢您的帮助。
1> Dora..:
也许你可以使用这个时候这个尝试cy.request
非常喜欢使用通常的方式restful
在cy.request
例如,您的查询名称findUser
带有查询的变量,username
看起来应该像这样findUser(username:"hello"){id, name}
,依此类推
但是,您不仅需要传递它,还需要传递它,就json
好像它是一个查询一样,{"query": findUser(username:"hello"){id, name}}
这实际上将是您的身体。
下面是一个例子...
const query = `{
findUser(username:"hello")
{
id
}
}`;
cy.request(
{
url: 'http://localhost/graphql/', // graphql endpoint
body: { query }, // or { query: query } depending if you are writing with es6
failOnStatusCode: false // not a must but in case the fail code is not 200 / 400
}
).then((res) => {
cy.log(res);
})