Socket
Socket
Sign inDemoInstall

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

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Mocking graphql schema capabilities


Version published
Weekly downloads
171
increased by11.04%
Maintainers
5
Weekly downloads
 
Created
Source

@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

Keywords

FAQs

Package last updated on 21 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc