-
Notifications
You must be signed in to change notification settings - Fork 135
/
interface.d.ts
226 lines (205 loc) · 5.27 KB
/
interface.d.ts
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/**
* PluginConstructor
*/
export interface PluginConstructor {
new (
document: Schema,
graphdocPackage: any,
projectPackage: any
): PluginInterface;
}
/**
* PluginInterface
*/
export interface PluginInterface {
/**
* Return section elements that is going to be
* inserted into the side navigation bar.
*
* @example plain javascript:
* [
* {
* title: 'Schema',
* items: [
* {
* text: 'Query',
* href: './query.doc.html',
* isActive: false
* },
* // ...
* }
* // ...
* ]
*
* @example with graphdoc utilities:
* import { NavigationSection, NavigationItem } from 'graphdoc/lib/utility';
*
* [
* new NavigationSection('Schema', [
* new NavigationItem('Query', ./query.doc.html', false)
* ]),
* // ...
* ]
*
* @param {string} [buildForType] -
* the name of the element for which the navigation section is being generated,
* if it is `undefined it means that the index of documentation is being generated
*/
getNavigations?: (
buildForType?: string
) => NavigationSectionInterface[] | PromiseLike<NavigationSectionInterface[]>;
/**
* Return section elements that is going to be
* inserted into the main section.
*
* @example plain javascript:
* [
* {
* title: 'GraphQL Schema definition',
* description: 'HTML'
* },
* // ...
* ]
*
* @example with graphdoc utilities:
* import { DocumentSection } from 'graphdoc/lib/utility';
*
* [
* new DocumentSection('GraphQL Schema definition', 'HTML'),
* // ...
* ]
*
* @param {string} [buildForType] -
* the name of the element for which the navigation section is being generated,
* if it is `undefined it means that the index of documentation is being generated
*
*/
getDocuments?: (
buildForType?: string
) => DocumentSectionInterface[] | PromiseLike<DocumentSectionInterface[]>;
/**
* Return a list of html tags that is going to be
* inserted into the head tag of each page.
*
* @example
* [
* '<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>',
* '<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">',
* ]
*/
getHeaders?: (buildForType?: string) => string[] | PromiseLike<string[]>;
/**
* Return a list of absolute path to files that is going to be
* copied to the assets directory.
*
* Unlike the previous methods that are executed each time that a page generated,
* this method is called a single time before starting to generate the documentation
*
* @example
* [
* '/local/path/to/my-custom-style.css',
* '/local/path/to/my-custom-image.png',
* ]
*
* there's will be copied to
* /local/path/to/my-custom-style.css -> [OUTPUT_DIRECTORY]/assets/my-custom-style.css
* /local/path/to/my-custom-image.png -> [OUTPUT_DIRECTORY]/assets/my-custom-image.png
*
* If you want to insert styles or scripts to the documentation,
* you must combine this method with getHeaders
*
* @example
* getAssets(): ['/local/path/to/my-custom-style.css']
* getHeaders(): ['<link href="assets/my-custom-style.css" rel="stylesheet">']
*/
getAssets?: () => string[] | PromiseLike<string[]>;
}
export interface PluginImplementedInterface {
document: Schema;
url: refToUrl;
queryType: SchemaType | null;
mutationType: SchemaType | null;
subscriptionType: SchemaType | null;
}
export interface NavigationSectionInterface {
title: string;
items: NavigationItemInterface[];
}
export interface NavigationItemInterface {
href: string;
text: string;
isActive: boolean;
}
export interface DocumentSectionInterface {
title: string;
description: string;
}
/**
* Convert TypeRef
*/
type refToUrl = (typeName: TypeRef) => string;
/**
* Introspection types
*/
type GraphQLIntrospection = {
data: {
__schema: Schema;
};
};
type ApolloIntrospection = {
__schema: Schema;
};
type Introspection = GraphQLIntrospection | ApolloIntrospection;
type Schema = {
queryType: Description | null;
mutationType: Description | null;
subscriptionType: Description | null;
types: SchemaType[];
directives: Directive[];
};
type Description = {
name: string;
description: string | null;
kind?: string;
};
type Deprecation = {
isDeprecated: boolean;
deprecationReason: string | null;
};
type SchemaType = Description & {
fields: Field[] | null;
inputFields: InputValue[] | null;
interfaces: TypeRef[] | null;
enumValues: EnumValue[] | null;
possibleTypes: TypeRef[] | null;
kind: string;
};
type Directive = Description & {
locations: string[];
args: InputValue[];
};
type EnumValue = Description & Deprecation;
type InputValue = Description & {
type: DeepTypeRef | TypeRef;
defaultValue: string | number | null;
};
type Field = Description &
Deprecation & {
args: InputValue[];
type: DeepTypeRef | TypeRef;
};
type TypeRef = {
name: string;
description: string | null;
kind: string;
ofType: null;
};
type DeepTypeRef = {
name: string | null;
description: null;
kind: "LIST" | "NON_NULL" | string;
ofType: DeepTypeRef | TypeRef;
};
export interface SchemaLoader {
(options: any): Promise<Schema>;
}