Karate API GraphQL POST示例:创建用户后查询参数传递问题求助
问题根因
- 第二个GraphQL查询语句中的变量占位符存在语法错误:你写的
#(userID'缺少了占位符要求的右闭合括号),非法的查询语句直接触发GraphQL解析报错。 - 额外注意:如果你的服务端
getUser接口的id参数定义为数值类型而非字符串类型,需要删除占位符外层的双引号,避免后续出现参数类型不匹配的错误。
修正后的测试代码
Scenario: Create a User Given path 'query' And header Accept = 'application/json' Given text query = """ mutation { createUser(username: "CreateUser16" , name: "Auto CreateUser", isPrivate: true) { id username lastLoginAt createdAt } } """ And request { query: '#(query)' } When method POST Then status 200 And print response And match response.data.createUser.id !=null * def userID = response.data.createUser.id And print userID Given path 'query' And header Accept = 'application/json' Given text query = """ { getUser(id: '#(userID)') { bio birthDate createdAt id } } """ And request { query: '#(query)' } When method POST Then status 200 And print response
内容的提问来源于stack exchange,提问作者mark quinteros
相关产品推荐
相关产品推荐

