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-cli

v1.0.1

Published

A cli for qiufen

Downloads

1

Readme

@fruits-chain/qiufen-cli

A cli for qiufen. Its main purpose is to serve a mock server and api docs for your graphql service.

Install

Install with npm:

npm install @fruits-chain/qiufen-cli --save-dev

Install with yarn:

yarn add @fruits-chain/qiufen-cli --dev

Usage

First, you should set up a configuration file:

yarn qiufen init

After that, you can start the server:

yarn qiufen start

Now, you can click the link to view docs or proxy your api to the mock server.

Configuration

After running yarn qiufen init, you'll have a qiufen.config.js file in your directory.

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
  /** playground config */
  playground?: PlaygroundConfig
}

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

interface MockConfig {
  /** enable the mock ability while it's true */
  enable: boolean
  /** the default value of enable arg in mock directive, default is true */
  mockDirectiveDefaultEnableValue: boolean
  /** schema files used for dev env, valid when enable is true */
  schemaFiles?: string[]
  /** value map rules, you should add all your scalar type mappers here or you'll get an error */
  scalarMap: IMockOptions['mocks']
  /** context for mock script in mock directive */
  context?: Record<string, unknown>
  /** graphql resolvers for operations, you can custom operation response here */
  resolvers?: IMockOptions['resolvers']
}

type SchemaPolicy = 'local' | 'remote'

interface PlaygroundConfig {
  /** request headers */
  headers?: Record<string, string>
}

Directives

@mock

Args

  • enable

    Type: Boolean
    Locations: QUERY | MUTATION

    If set and the value is true, the query will be mocked, otherwise the query will be forwarded to backend.

    example

    query customers($page: Page, $customersInput: CustomersInput)
    @mock(enable: true) {
      customers(page: $page, customersInput: $customersInput) {
        records {
          customerId
          customerStatus
        }
        pageCurrent
        pageSize
        totalRecords
      }
    }
  • err

    Type: { code: Int!, message: String! }
    Locations: FIELD

    If set, the query will response a result with errors you provided.

    example

    query customers($page: Page, $customersInput: CustomersInput)
    @mock(enable: true) {
      customers(page: $page, customersInput: $customersInput)
        @mock(err: { code: 500, message: "Internal error" }) {
        records {
          customerId
          customerStatus
        }
        pageCurrent
        pageSize
        totalRecords
      }
    }
  • len

    Type: String | Int
    Locations: FIELD

    If set and the field is of type Array, the result of this field will be an array with length of len.

    example

    query customers($page: Page, $customersInput: CustomersInput)
    @mock(enable: true) {
      customers(page: $page, customersInput: $customersInput) {
        records @mock(len: 10) {
          customerId
          customerStatus
        }
        pageCurrent
        pageSize
        totalRecords
      }
    }
  • val

    Type: String | Number | Boolean | Null
    Locations: FIELD

    If set, the result of this field will be the value you specified.

    example

    query customers($page: Page, $customersInput: CustomersInput)
    @mock(enable: true) {
      customers(page: $page, customersInput: $customersInput) {
        records @mock(len: 10) {
          customerId @mock(val: 1111)
          customerStatus
        }
        pageCurrent
        pageSize
        totalRecords
      }
    }
  • fallback

    Type: Boolean
    Locations: FIELD

    Sometimes, the value of val may cause an validation/runtime error, you can ignore the error by setting fallback to true, then the result will behave as if val is not set. Be aware that if the error is thrown by graphql, it's not effect.

    example

    query customers($page: Page, $customersInput: CustomersInput)
    @mock(enable: true) {
      customers(page: $page, customersInput: $customersInput) {
        records @mock(len: 10) {
          customerId @mock(val: {}, fallback: true)
          customerStatus
        }
        pageCurrent
        pageSize
        totalRecords
      }
    }

Micro script

When the value of val arg is of type String and matches the pattern %{.*}, you'll get this power.

example

document

query customers($page: Page, $customersInput: CustomersInput)
@mock(enable: true) {
  customers(page: $page, customersInput: $customersInput) {
    records @mock(len: "%{page.pageSize}") {
      customerId
        @mock(
          val: "%{path.prev.key + (page.pageCurrent - 1) * page.pageSize + 1}"
        )
      customerStatus
    }
    pageCurrent @mock(val: "%{page.pageCurrent}")
    pageSize @mock(val: "%{page.pageSize}")
    totalRecords @mock(val: "%{100}")
  }
}

variables

{
  "page": {
    "pageCurrent": 2,
    "pageSize": 5
  },
  "customersInput": {
    "keyword": "str",
    "attribute": "INTERNAL"
  }
}

response

{
  "data": {
    "customers": {
      "records": [
        {
          "customerId": 6,
          "customerStatus": "SUSPENSION"
        },
        {
          "customerId": 7,
          "customerStatus": "RESIGN"
        },
        {
          "customerId": 8,
          "customerStatus": "SUSPENSION"
        },
        {
          "customerId": 9,
          "customerStatus": "RESIGN"
        },
        {
          "customerId": 10,
          "customerStatus": "NORMAL"
        }
      ],
      "pageCurrent": 2,
      "pageSize": 5,
      "totalRecords": 100
    }
  }
}

As you can see, the query can response a result associated with your operation variables and some special global vars.

Global vars

  • path

    interface Path {
      // parent field path
      readonly prev: Path | undefined
      // current field name
      readonly key: string | number
      // parent field type
      readonly typename: string | undefined
    }

CLI Commands

init

Run config initialization wizard

start

Start a graphql server

check

Check some config options

help

Display help for command

FAQ

  • I run yarn qiufen start successfully, but i can't access the doc service in chrome.

    Be sure that your port is not in unsafe port list of chrome.