npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fruits-chain/qiufen-pro-graphql-mock

v0.1.5

Published

Mocking graphql schema capabilities

Downloads

43

Readme

@fruits-chain/qiufen-pro-graphql-mock

  • Mock your GraphQL data based on a schema.

Install

yarn add @fruits-chain/qiufen-pro-graphql-mock -D

Usage

  • step1:Create the "qiufen.config.js" configuration file in the project root directory.
  • step2:Configure the type of the object
interface GraphqlKitConfig {
  /** your qiufen service port */
  port: number
  /** backend service config */
  endpoint: ServiceConfig
  /** local graphql schema file path */
  localSchemaFile?: string
  /** use either local schema or remote schema, if unset, remote will be used */
  schemaPolicy?: SchemaPolicy
  /** mock config */
  mock?: MockConfig
}

interface ServiceConfig {
  /** backend service url */
  url: string
}

interface MockConfig {
  /** value map rules, you should add all your scalar type mappers here or you'll get an error */
  scalarMap: any
  /** graphql resolvers for operations, you can custom operation response here */
  resolvers?: any
}

type SchemaPolicy = 'local' | 'remote'

interface PlaygroundConfig {
  /** request headers */
  headers?: Record<string, string>
}
  • step3:Go to configure "qiufen.config.js".
// demo of configure
const Mock = require('mockjs')
const { GraphqlKitConfig } = require('@fruits-chain/qiufen-pro-graphql-mock')
const { Random } = Mock

//@ts-check
/** @typedef {GraphqlKitConfig} Config **/

/** @type Config */
const config = {
  port: 4200,
  // Local schema file path
  localSchemaFile: './src/graphql/generated/schema.graphql',
  // "remote" | "local". When the remote gateway fails, you are advised to set it to "local" and specify the path of the local schema file.
  schemaPolicy: 'remote',
  endpoint: {
    // remote schema address
    url: 'http://localhost:4000/graphql',
  },
  mock: {
    scalarMap: {
      Int: () => Random.integer(0, 100),
      String: () => Random.ctitle(2, 4),
      ID: () => Random.id(),
      Boolean: () => Random.boolean(),
      BigDecimal: () => Random.integer(0, 1000000),
      Float: () => Random.float(0, 100),
      Date: () => Random.date(),
      DateTime: () => Random.datetime(),
      Long: () => Random.integer(0, 10000),
      NumberOrBoolOrStringOrNull: () => null,
      NumberOrString: () => null,
      Object: () => ({}),
    },
    resolvers: {
      Query: {
        /* Custom field interface return */
        // ListTaskBoard: () => {
        //   return [
        //     {
        //       commodityName: "111111111",
        //       commoditySpecOptionName: "争11232131231212果",
        //       commodityTypeName: "样情",
        //       completedQuantity: "府委产",
        //       createBy: "火传离那",
        //       customerName: "布红系",
        //       customerTypeName: "报件指加",
        //       expectSaleQuantity: "容规数",
        //       index: 47,
        //       leaderName: "车做",
        //       line: "质身管手",
        //       planId: "320000201903036414",
        //       planProductionQuantity: "年着",
        //       productionType: "专本学",
        //       schedule: "再严今花",
        //     },
        //   ]
        // },
      },
    },
  },
}

module.exports = config
  • step4:
const {
  executeQiufenMockingServer,
} = require('@fruits-chain/qiufen-pro-graphql-mock')

executeQiufenMockingServer()
  • step5: If you want to customize the configuration
import { startMockingServer } = require('@fruits-chain/qiufen-pro-graphql-mock')

startMockingServer(config) // config above