graphql-vcr
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

graphql-vcr

Usage with koa

import graphqlVcr from 'graphql-vcr'
import { graphql } from 'graphql'
 
const vcr = graphqlVcr({
  schema,
  graphql
  enable: true /* put false to disable recording without having to remove any code*/
})
const graphQLRouter = new KoaRouter()
graphQLRouter.post('/graphql', koaBody(), (context, next) => {
  const reqRec = vcr.recordRequest()
  reqRec.query(context.req.body)
  return graphqlKoa({
    schema,
    context: context.req.session
  })(context, next).then(() => {
    reqRec.result(context.response.body)
  })
})
 
// then to replay:
vcr.playFile('./vcr-sessions/2018-04-30T00:24:24.317Z.json', false) // pass true as second argument to check the result of queries
// helper method
vcr.playLastSession(false) // pass true as second argument to check the result of queries

Package Sidebar

Install

npm i graphql-vcr

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

23.1 kB

Total Files

10

Last publish

Collaborators

  • capaj