• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

2fd/graphdoc: Static page generator for documenting GraphQL Schema

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

2fd/graphdoc

开源软件地址(OpenSource Url):

https://github.com/2fd/graphdoc

开源编程语言(OpenSource Language):

TypeScript 50.7%

开源软件介绍(OpenSource Introduction):

Static page generator for documenting GraphQL Schema

build coverage npm tag

Demos

Install

  npm install -g @2fd/graphdoc

Use

Generate documentation from live endpoint

  > graphdoc -e http://localhost:8080/graphql -o ./doc/schema

Generate documentation from IDL file

  > graphdoc -s ./schema.graphql -o ./doc/schema

Generate documentation from for the "modularized schema" of graphql-tools

  > graphdoc -s ./schema.js -o ./doc/schema

./schema.graphql must be able to be interpreted with graphql-js/utilities#buildSchema

Generate documentation from json file

  > graphdoc -s ./schema.json -o ./doc/schema

./schema.json contains the result of GraphQL introspection query

Puts the options in your package.json

  // package.json

  {
    "name": "project",
    "graphdoc": {
      "endpoint": "http://localhost:8080/graphql",
      "output": "./doc/schema",
    }
  }

And execute

  > graphdoc

Help

  > graphdoc -h
  
    Static page generator for documenting GraphQL Schema v2.4.0

    Usage: node bin/graphdoc.js [OPTIONS] 

    
    [OPTIONS]:
    -c, --config                   Configuration file [./package.json].
    -e, --endpoint                 Graphql http endpoint ["https://domain.com/graphql"].
    -x, --header                   HTTP header for request (use with --endpoint). ["Authorization: Token cb8795e7"].
    -q, --query                    HTTP querystring for request (use with --endpoint) ["token=cb8795e7"].
    -s, --schema, --schema-file    Graphql Schema file ["./schema.json"].
    -p, --plugin                   Use plugins [default=graphdoc/plugins/default].
    -t, --template                 Use template [default=graphdoc/template/slds].
    -o, --output                   Output directory.
    -d, --data                     Inject custom data.
    -b, --base-url                 Base url for templates.
    -f, --force                    Delete outputDirectory if exists.
    -v, --verbose                  Output more information.
    -V, --version                  Show graphdoc version.
    -h, --help                     Print this help

Plugin

In graphdoc a plugin is simply an object that controls the content that is displayed on every page of your document.

This object should only implement the PluginInterface.

Make a Plugin

To create your own plugin you should only create it as a plain object or a constructor and export it as default

If you export your plugin as a constructor, when going to be initialized, will receive three parameters

  • schema: The full the result of GraphQL introspection query
  • projectPackage: The content of package.json of current project (or the content of file defined with --config flag).
  • graphdocPackage: The content of package.json of graphdoc.

For performance reasons all plugins receive the reference to the same object and therefore should not modify them directly as it could affect the behavior of other plugins (unless of course that is your intention)

Examples

  // es2015 export constructor

  export default class MyPlugin {

    constructor(schema, projectPackage, graphdocPackage) {}

    getAssets() {
      /* ... */
    }
  }
  // es2015 export plain object

  export default cost myPlugin = {
    getAssets() {
      /* ... */
    },
  }
  // export constructor

  function MyPlugin(schema, projectPackage, graphdocPackage) {
    /* ... */
  }

  MyPlugin.prototype.getAssets = function() {
    /* ... */
  };

  exports.default = MyPlugin;
  // export plain object

  exports.default = {
    getAssets: function() {
      /* ... */
    }
  };

Use plugin

You can use the plugins in 2 ways.

Use plugins with command line

  > graphdoc -p graphdoc/plugins/default \
  -p some-dependencies/plugin \
  -p ./lib/plugin/my-own-plugin \
  -s ./schema.json -o ./doc/schema

Use plugins with package.json

  // package.json

  {
    "name": "project",
    "graphdoc": {
      "endpoint": "http://localhost:8080/graphql",
      "output": "./doc/schema",
      "plugins": [
        "graphdoc/plugins/default",
        "some-dependencie/plugin",
        "./lib/plugin/my-own-plugin"
      ]
    }
  }

Build-in plugin

TODO

Template

TODO

Contributors




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap