最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

模拟apollo graphql客户

IT培训 admin 4浏览 0评论

模拟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)

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

模拟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. 暂无评论