项目作者: 2fd

项目描述 :
Static page generator for documenting GraphQL Schema
高级语言: TypeScript
项目地址: git://github.com/2fd/graphdoc.git
创建时间: 2016-08-09T01:33:28Z
项目社区:https://github.com/2fd/graphdoc

开源协议:MIT License

下载


Static page generator for documenting GraphQL Schema

build
coverage
@2fd/graphdoc.svg" alt="npm">
tag

Demos

Install

  1. npm install -g @2fd/graphdoc

Use

Generate documentation from live endpoint

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

Generate documentation from IDL file

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

Generate documentation from for the “modularized schema” of graphql-tools

  1. > 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

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

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

Puts the options in your package.json

  1. // package.json
  2. {
  3. "name": "project",
  4. "graphdoc": {
  5. "endpoint": "http://localhost:8080/graphql",
  6. "output": "./doc/schema",
  7. }
  8. }

And execute

  1. > graphdoc

Help

  1. > graphdoc -h
  2. Static page generator for documenting GraphQL Schema v2.4.0
  3. Usage: node bin/graphdoc.js [OPTIONS]
  4. [OPTIONS]:
  5. -c, --config Configuration file [./package.json].
  6. -e, --endpoint Graphql http endpoint ["https://domain.com/graphql"].
  7. -x, --header HTTP header for request (use with --endpoint). ["Authorization: Token cb8795e7"].
  8. -q, --query HTTP querystring for request (use with --endpoint) ["token=cb8795e7"].
  9. -s, --schema, --schema-file Graphql Schema file ["./schema.json"].
  10. -p, --plugin Use plugins [default=graphdoc/plugins/default].
  11. -t, --template Use template [default=graphdoc/template/slds].
  12. -o, --output Output directory.
  13. -d, --data Inject custom data.
  14. -b, --base-url Base url for templates.
  15. -f, --force Delete outputDirectory if exists.
  16. -v, --verbose Output more information.
  17. -V, --version Show graphdoc version.
  18. -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

  1. // es2015 export constructor
  2. export default class MyPlugin {
  3. constructor(schema, projectPackage, graphdocPackage) {}
  4. getAssets() {
  5. /* ... */
  6. }
  7. }
  1. // es2015 export plain object
  2. export default cost myPlugin = {
  3. getAssets() {
  4. /* ... */
  5. },
  6. }
  1. // export constructor
  2. function MyPlugin(schema, projectPackage, graphdocPackage) {
  3. /* ... */
  4. }
  5. MyPlugin.prototype.getAssets = function() {
  6. /* ... */
  7. };
  8. exports.default = MyPlugin;
  1. // export plain object
  2. exports.default = {
  3. getAssets: function() {
  4. /* ... */
  5. }
  6. };

Use plugin

You can use the plugins in 2 ways.

Use plugins with command line

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

Use plugins with package.json

  1. // package.json
  2. {
  3. "name": "project",
  4. "graphdoc": {
  5. "endpoint": "http://localhost:8080/graphql",
  6. "output": "./doc/schema",
  7. "plugins": [
  8. "graphdoc/plugins/default",
  9. "some-dependencie/plugin",
  10. "./lib/plugin/my-own-plugin"
  11. ]
  12. }
  13. }

Build-in plugin

TODO

Template

TODO

Contributors