最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

模拟apollo graphql客户

运维笔记admin11浏览0评论

模拟apollo graphql客户

模拟apollo graphql客户

我编写了以下节点客户端,该客户端与graphql服务器交互并使用apollo-tools节点模块。我无法在下面的节点中找到任何模拟测试。请让我知道有没有一种方法可以模拟下面的代码。

const batchIdFetchClient = new ApolloClient({
        uri: `http://localhost:3435`,
        fetch,
    })

    await batchfetchclient.query({
        query: gql`
  query batcidId($batchid: String!) {
    batchIds(batchid: $batchid){
        batchrenewedId 
    }
  }
`,
        variables: {
            batchid: 'exdsfsdfsfdid1234', // As of now hardcoded
        },
    })
        .then(data => {
            logger.info('BatchId Database Successful Response =>' + JSON.stringify(data))
        })
        .catch(error => {
            logger.error('BatchId Database Error Response =>' + error)
        })
回答如下:

也许您可以尝试使用easygraphql-tester,它将像这样:

您需要传递您的模式才能进行模拟

const EasyGraphQLTester = require('easygraphql-tester')

const tester = new EasyGraphQLTester(schema)

const query = gql`
  query batcidId($batchid: String!) {
    batchIds(batchid: $batchid){
      batchrenewedId 
    }
  }
`

const mock = tester.mock({
  query,
  variables: {
    batchid: 'exdsfsdfsfdid1234', // As of now hardcoded
  }
})

console.log(mock)

此外,如果您要获取特定数据,也可以设置灯具。

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论