0.1.7 • Published 6 years ago

qewl-mock v0.1.7

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

qewl-mock

Mocking middleware for Qewl GraphQL Application Framework.

Installation

$ yarn add qewl-mock

Usage

route.use(
  mock({ schema: 'schemaName', mocks?: {...}, preserveResolvers?: true | false })
)

Adds mocking to a GraphQL schema. Uses addMockFunctionsToSchema from graphql-tools.

Note: The preserveResolvers setting only applies to the resolvers in your original schema. Any resolvers you add using the Qewl resolve function will override the mock functions. This allows for optimal control over your resolvers.

Uses Faker.js for default mock values for Number, Float and String. Uses cuid for mock values for ID.

You can use qewl-mock together with Qewl GraphQL middleware functions to add additional processing to the mocked results, just like normal queries.

Example

import * as express from 'express'
import { expressPlayground } from 'graphql-playground-middleware'
import { schema, remoteSchema, use, resolve } from 'qewl'
import { mock } from 'qewl-mock'

import { helloSchema } from './helloSchema'
import { helloResolver } from './helloResolver'

async function run() {

  const app = express()
  const graphql = express.Router()

  // Schema
  graphql.use(
    schema({ name: 'mySchema', schema: `
      type Query {
        hello: String
      }`
    })
  )

  // Mocking
  graphql.use(
    mock({schema: 'mySchema'})
  )

  // Endpoint
  graphql.use(
    serve()
  )

  app.use('/graphql', express.json(), graphql)
  app.use('/playground', expressPlayground({ endpoint: '/graphql' }))

  app.listen(3000, () => console.log('Server running. Open http://localhost:3000/playground to run queries.'))
}

run().catch(console.error.bind(console))
0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago