我正在尝试使用 .graphql 文件并传递变量来对空手道进行测试。在我的 graphql 模式上,我试图重用另一个 .graphql 文件中的片段。我尝试按照以下说明进行操作https://www.apollographql.com/docs/react/advanced/fragments#webpack-importing-fragments https://www.apollographql.com/docs/react/advanced/fragments#webpack-importing-fragments但是当我在 .graphql 文件上使用 #import 语句运行空手道测试时,测试失败,表示片段未知。
查找配置文件.feature
@smoke
Feature: Test GraphQL FindTrendingProfiles
Background:
* url 'https://192.168.0.0.1'
Scenario: FindTrendingProfiles Request
Given def query = read('FindProfile.graphql')
And def variables = { cursor: "1", cursorType: PAGE, size: 2 }
And request { query: '#(query)', variables: '#(variables)' }
When method post
Then status 200
FindProfile.graphql
#import "./Media.graphql"
query FindProfile($cursor: String, $cursorType: CursorType!, $size: Int!) {
FindProfile(cursor: $cursor, cursorType: $cursorType, size: $size) {
edges{
id
profilePictureMedia{
...Media
}
}
}
}
Media.graphql
fragment Media on Media {
id
title
description
}
我希望我可以重用另一个 .graphql 文件中的片段,但实际我不能这样做。任何帮助是极大的赞赏。谢谢。
To Karate GraphQL 只是作为纯文本或原始字符串进行处理。不支持 GraphQL 导入。
团队通常做的是在客户端向服务器发出 HTTP POST 请求时获取有效的 GraphQL 样本。这甚至可以包含像您在中看到的片段这些例子 https://graphql.org/learn/queries/#fragments.
然后您的测试所需要做的就是重新播放该内容。空手道为您提供了大量的字符串操作功能,例如replace https://github.com/intuit/karate#replace如果您需要数据驱动的测试。
总而言之,使用完整形成的 GraphQL 字符串。如果您需要修改它们,请使用replace
或使用 JS 或 Java 实用程序进行自定义字符串操作。大多数情况下 GraphQL变量 https://graphql.org/learn/queries/#variables足以进行数据驱动的测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)