-
Notifications
You must be signed in to change notification settings - Fork 135
/
README.handlebars
205 lines (146 loc) · 4.55 KB
/
README.handlebars
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# {{project.description}}
[![build](https://github.com/2fd/graphdoc/workflows/build/badge.svg?branch=master)](https://github.com/2fd/graphdoc/actions?query=workflow%3Abuild+branch%3Amaster+)
[![coverage](https://coveralls.io/repos/github/2fd/graphdoc/badge.svg?branch=master)](https://coveralls.io/github/2fd/graphdoc?branch=master)
![npm](https://img.shields.io/npm/v/@2fd/graphdoc.svg)
![tag](https://img.shields.io/github/tag/2fd/graphdoc.svg)
- [demos](#demos)
- [install](#install)
- [use](#use)
- [plugin](#plugin)
- [template](#template)
- [contributors](#contributors)
## Demos
- Facebook Test [Star Wars](https://2fd.github.io/graphdoc/star-wars)
- [Github V4 API](https://2fd.github.io/graphdoc/github)
- [Shopify API](https://2fd.github.io/graphdoc/shopify/)
- [Pokemon GraphQL](https://2fd.github.io/graphdoc/pokemon)
## Install
```bash
npm install -g @2fd/graphdoc
```
## Use
### Generate documentation from live endpoint
```bash
> graphdoc -e http://localhost:8080/graphql -o ./doc/schema
```
### Generate documentation from IDL file
```bash
> graphdoc -s ./schema.graphql -o ./doc/schema
```
### Generate documentation from for the ["modularized schema"](http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing) of graphql-tools
```bash
> graphdoc -s ./schema.js -o ./doc/schema
```
> [`./schema.graphql`](https://github.com/2fd/graphdoc/blob/master/test/starwars.graphql) must be able to be interpreted
> with [graphql-js/utilities#buildSchema](http://graphql.org/graphql-js/utilities/#buildschema)
### Generate documentation from json file
```bash
> graphdoc -s ./schema.json -o ./doc/schema
```
> `./schema.json` contains the result of [GraphQL introspection
> query](https://github.com/2fd/graphdoc/blob/gh-pages/introspection.graphql)
### Puts the options in your `package.json`
```javascript
// package.json
{
"name": "project",
"graphdoc": {
"endpoint": "http://localhost:8080/graphql",
"output": "./doc/schema",
}
}
```
And execute
```bash
> graphdoc
```
### Help
```bash
> graphdoc -h
{{{bash "node ./bin/graphdoc.js --no-color --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`](https://github.com/2fd/graphdoc/blob/master/lib/interface.d.ts#L12-L117).
### 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](https://github.com/2fd/graphdoc/blob/gh-pages/introspection.graphql)
- `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
```typescript
// es2015 export constructor
export default class MyPlugin {
constructor(schema, projectPackage, graphdocPackage) {}
getAssets() {
/* ... */
}
}
```
```typescript
// es2015 export plain object
export default cost myPlugin = {
getAssets() {
/* ... */
},
}
```
```javascript
// export constructor
function MyPlugin(schema, projectPackage, graphdocPackage) {
/* ... */
}
MyPlugin.prototype.getAssets = function() {
/* ... */
};
exports.default = MyPlugin;
```
```javascript
// export plain object
exports.default = {
getAssets: function() {
/* ... */
}
};
```
### Use plugin
You can use the plugins in 2 ways.
#### Use plugins with command line
```bash
> 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`
```javascript
// 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
{{#each contributors}}- [<img src="{{{avatar_url}}}" width="40"> {{{login}}}]({{{html_url}}})
{{/each}}