如何将输入类型对象从Pact(打字稿)传递给GraphQL突变

时间:2020-06-01 10:19:03

标签: typescript graphql pact mutation

针对输入类型作为查询参数的GraphQL突变创建Pact消费者/提供者测试。

GraphQL模式:

input ReviewInput {
  stars: Int!
  commentary: String
}

GraphQL突变:

mutation Stars(
  $input: ReviewInput!
) {
  createStars(input: $input) {
...

在Pact的使用者方面(使用打字稿),我必须定义查询变量,这些变量希望传递给GraphQL突变。 如果仅定义变量starscommentary,则尝试从Pact的提供者端开始测试会导致错误,即未定义输入类型变量。

契约消费者方:

describe('Stars', () => {
    describe('with correct variables', () => {
      const variables = {
        stars: 1,
        commentary: 'test',
      }

契约提供者方面的错误:

"message":"ReviewInput isn't a defined input type (on $input)"

我应该如何在Pact一侧定义包含starscommentary的输入类型,并将该输入类型传递给GraphQL突变?

希望有人可以帮助您,谢谢您!

0 个答案:

没有答案