【发布时间】:2020-10-21 01:28:13
【问题描述】:
我有一个 Pact 文件,如下所示:
{
"consumer": {
"name": "UI"
},
"provider": {
"name": "GraphQL API"
},
"interactions": [
{
"description": "Delete item request",
"providerState": "Atleast one item exists",
"request": {
"method": "POST",
"path": "/",
"headers": {
"content-type": "application/json"
},
"body": {
"operationName": null,
"query": "mutation ($itemId: ID!) { \n removeItem(id: $itemId) { \n item { \n id \n __typename \n } \n __typename \n }\n }",
"variables": {
"itemId": "item-c9b1f276-3748-4be3-915d-ec01ccbc2197"
}
},
"matchingRules": {
"$.body.query": {
"match": "regex",
"regex": "mutation\\s*\\(\\$itemId:\\s*ID!\\)\\s*\\{\\s*removeItem\\(id:\\s*\\$itemId\\)\\s*\\{\\s*plan\\s*\\{\\s*id\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
},
"$.body.variables.itemId": {
"match": "type"
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"data": {
"removeItem": {
"item": {
"id": "item-c9b1f276-3748-4be3-915d-ec01ccbc2197",
"__typename": "Item"
},
"__typename": "ItemPayload"
}
}
},
"matchingRules": {
"$.body.data.removeItem.item.id": {
"match": "type"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
在协议验证之前,我想提供一个有效的 itemId 值,它是一个 GraphQL 变量。
在上面的 JSON 中,它位于 interactions > request > body > variables > itemId
我尝试的一个选项是使用 requestFilters 选项 (Pact-JS-modify-requests-prior-to-verification-request-filters),
但是,我无法理解如何修改 GraphQL 变量?
或者如果有任何其他验证选项可以使用?
【问题讨论】:
标签: javascript node.js graphql graphql-js pact