Generate GraphQL docs from schema.
Forked from the excellent but unfortunately unmaintained graphdoc package.
Install
To install globally:
npm install -g graphqldoc
Use
Generate documentation from live endpoint
> graphqldoc -e http://localhost:8080/graphql -o ./doc/schema
Generate documentation from IDL file
> graphqldoc -s ./schema.graphql -o ./doc/schema
"modularized schema" of graphql-tools
Generate documentation from for the > graphqldoc -s ./schema.js -o ./doc/schema
./schema.graphql
must be able to be interpreted with graphql-js/utilities#buildSchema
Generate documentation from json file
> graphqldoc -s ./schema.json -o ./doc/schema
./schema.json
contains the result of GraphQL introspection query.
package.json
Puts the options in your // package.json "name": "project" // [...] "graphqldoc": "endpoint": "http://localhost:8080/graphql" "output": "./doc/schema"
And execute
> graphqldoc
Help
> graphqldoc -h Static page generator
Plugin
In graphqldoc 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 instrospection query.projectPackage
: The content ofpackage.json
of current project (or the content of file defined with--config
flag).graphqldocPackage
: The content ofpackage.json
of graphqldoc.
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
// es2015 export plain object
// export constructor { /* ... */ } MyPluginprototype { /* ... */ }; /* ... */ exportsdefault = MyPlugin;
// export plain object exportsdefault = { /* ... */ } /* ... */
Use plugin
You can use the plugins in 2 ways.
Use plugins with command line
> graphqldoc -p graphqldoc/plugins/default \ -p some-dependencie/plugin \ -p ./lib/plugin/my-own-plugin \ -s ./schema.json -o ./doc/schema
package.json
Use plugins with // package.json "name": "project" // [...] "graphqldoc": "endpoint": "http://localhost:8080/graphql" "output": "./doc/schema" "plugins": "graphqldoc/plugins/default" "some-dependencie/plugin" "./lib/plugin/my-own-plugin"