@graphql-markdown/docusaurus 1.14.0 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -20
- package/package.json +7 -146
- package/src/index.js +4 -3
- package/assets/generated.md +0 -19
- package/assets/sidebar.json +0 -8
- package/src/config.js +0 -83
- package/src/const/mdx.js +0 -7
- package/src/const/strings.js +0 -30
- package/src/lib/diff.js +0 -79
- package/src/lib/generator.js +0 -78
- package/src/lib/graphql.js +0 -372
- package/src/lib/group-info.js +0 -76
- package/src/lib/printer.js +0 -581
- package/src/lib/renderer.js +0 -150
- package/src/utils/helpers/fs.js +0 -33
- package/src/utils/helpers/prettier.js +0 -29
- package/src/utils/scalars/array.js +0 -18
- package/src/utils/scalars/object.js +0 -16
- package/src/utils/scalars/string.js +0 -86
- package/src/utils/scalars/url.js +0 -8
package/src/lib/graphql.js
DELETED
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
GraphQLEnumType,
|
|
3
|
-
GraphQLUnionType,
|
|
4
|
-
GraphQLScalarType,
|
|
5
|
-
isListType,
|
|
6
|
-
GraphQLBoolean,
|
|
7
|
-
GraphQLInt,
|
|
8
|
-
GraphQLFloat,
|
|
9
|
-
GraphQLID,
|
|
10
|
-
GraphQLString,
|
|
11
|
-
GraphQLObjectType,
|
|
12
|
-
GraphQLInterfaceType,
|
|
13
|
-
GraphQLInputObjectType,
|
|
14
|
-
isDirective: isDirectiveType,
|
|
15
|
-
getNamedType,
|
|
16
|
-
isScalarType,
|
|
17
|
-
isEnumType,
|
|
18
|
-
isUnionType,
|
|
19
|
-
isInterfaceType,
|
|
20
|
-
isObjectType,
|
|
21
|
-
isInputObjectType: isInputType,
|
|
22
|
-
isNonNullType,
|
|
23
|
-
isLeafType,
|
|
24
|
-
printSchema,
|
|
25
|
-
GraphQLSchema,
|
|
26
|
-
OperationTypeNode,
|
|
27
|
-
} = require("graphql");
|
|
28
|
-
const { loadSchema: asyncLoadSchema } = require("@graphql-tools/load");
|
|
29
|
-
|
|
30
|
-
const { hasMethod, hasProperty } = require("../utils/scalars/object");
|
|
31
|
-
|
|
32
|
-
const OperationTypeNodes = [
|
|
33
|
-
OperationTypeNode.QUERY,
|
|
34
|
-
OperationTypeNode.MUTATION,
|
|
35
|
-
OperationTypeNode.SUBSCRIPTION,
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const DefaultLoaders = {
|
|
39
|
-
GraphQLFileLoader: "@graphql-tools/graphql-file-loader",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
async function loadSchema(schemaLocation, options) {
|
|
43
|
-
const rootTypes = hasProperty(options, "rootTypes")
|
|
44
|
-
? options.rootTypes
|
|
45
|
-
: undefined;
|
|
46
|
-
|
|
47
|
-
if (hasProperty(options, "rootTypes")) {
|
|
48
|
-
delete options["rootTypes"];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const schema = await asyncLoadSchema(schemaLocation, options);
|
|
52
|
-
|
|
53
|
-
if (typeof rootTypes === "undefined") {
|
|
54
|
-
return schema;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const config = {
|
|
58
|
-
...schema.toConfig(),
|
|
59
|
-
query: schema.getType(rootTypes.query ?? "Query"),
|
|
60
|
-
mutation: schema.getType(rootTypes.mutation ?? "Mutation"),
|
|
61
|
-
subscription: schema.getType(rootTypes.subscription ?? "Subscription"),
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return new GraphQLSchema(config);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function getDocumentLoaders(extraLoaders = {}) {
|
|
68
|
-
const loadersList = { ...DefaultLoaders, ...extraLoaders };
|
|
69
|
-
|
|
70
|
-
const loaders = [];
|
|
71
|
-
const loaderOptions = {};
|
|
72
|
-
|
|
73
|
-
Object.entries(loadersList).forEach(([className, graphqlDocumentLoader]) => {
|
|
74
|
-
try {
|
|
75
|
-
if (typeof graphqlDocumentLoader === "string") {
|
|
76
|
-
const { [className]: Loader } = require(graphqlDocumentLoader);
|
|
77
|
-
loaders.push(new Loader());
|
|
78
|
-
} else {
|
|
79
|
-
if (!graphqlDocumentLoader.module) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
`Wrong format for plugin loader "${className}", it should be {module: String, options?: Object}`,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
const { [className]: Loader } = require(graphqlDocumentLoader.module);
|
|
85
|
-
loaders.push(new Loader());
|
|
86
|
-
Object.assign(loaderOptions, graphqlDocumentLoader.options);
|
|
87
|
-
}
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.warn(graphqlDocumentLoader, error.message);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (loaders.length < 1) {
|
|
94
|
-
throw new Error("No GraphQL document loaders available.");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return { loaders, loaderOptions };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getListDefaultValues(type, value) {
|
|
101
|
-
const defaultValues = Array.isArray(value) ? value : [value];
|
|
102
|
-
|
|
103
|
-
const defaultValuesString = defaultValues.map((defaultValue) =>
|
|
104
|
-
getDefaultValue({ type, defaultValue }),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return `[${defaultValuesString.join(", ")}]`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function getDefaultValue({ type, defaultValue }) {
|
|
111
|
-
if (defaultValue === null || typeof defaultValue === "undefined") {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (isListType(type)) {
|
|
116
|
-
return getListDefaultValues(getNamedType(type), defaultValue);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return formatDefaultValue(type, defaultValue);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function formatDefaultValue(type, defaultValue) {
|
|
123
|
-
if (isEnumType(type)) {
|
|
124
|
-
return defaultValue;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
switch (type) {
|
|
128
|
-
case GraphQLInt:
|
|
129
|
-
case GraphQLFloat:
|
|
130
|
-
case GraphQLBoolean:
|
|
131
|
-
return defaultValue;
|
|
132
|
-
case GraphQLID:
|
|
133
|
-
case GraphQLString:
|
|
134
|
-
return `"${defaultValue}"`;
|
|
135
|
-
default:
|
|
136
|
-
return defaultValue;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function getTypeFromSchema(schema, type) {
|
|
141
|
-
if (typeof schema == "undefined" || schema == null) {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const operationKinds = [];
|
|
146
|
-
OperationTypeNodes.forEach((operationTypeNode) => {
|
|
147
|
-
const operationType = schema.getRootType(operationTypeNode);
|
|
148
|
-
if (typeof operationType !== "undefined") {
|
|
149
|
-
operationKinds.push(operationType.name);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const filterOperationFragmentRegExp =
|
|
154
|
-
operationKinds.length > 0 ? [...operationKinds, ""].join("$|") : "";
|
|
155
|
-
const excludeListRegExp = new RegExp(
|
|
156
|
-
`^(?!${filterOperationFragmentRegExp}__.+$).*$`,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const typeMap = schema.getTypeMap();
|
|
160
|
-
|
|
161
|
-
return Object.keys(typeMap)
|
|
162
|
-
.filter((key) => excludeListRegExp.test(key))
|
|
163
|
-
.filter((key) => typeMap[key] instanceof type)
|
|
164
|
-
.reduce((res, key) => ({ ...res, [key]: typeMap[key] }), {});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getIntrospectionFieldsList(queryType) {
|
|
168
|
-
if (
|
|
169
|
-
typeof queryType == "undefined" ||
|
|
170
|
-
queryType == null ||
|
|
171
|
-
!hasMethod(queryType, "getFields")
|
|
172
|
-
) {
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
return queryType.getFields();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function getFields(type) {
|
|
179
|
-
if (!hasMethod(type, "getFields")) {
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
const fieldMap = type.getFields();
|
|
183
|
-
return Object.keys(fieldMap).map((name) => fieldMap[name]);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function getTypeName(type, defaultName = "") {
|
|
187
|
-
switch (true) {
|
|
188
|
-
case hasProperty(type, "name"):
|
|
189
|
-
return type.name;
|
|
190
|
-
case hasMethod(type, "toString"):
|
|
191
|
-
return type.toString();
|
|
192
|
-
case typeof type === "undefined":
|
|
193
|
-
case type == null:
|
|
194
|
-
default:
|
|
195
|
-
return defaultName;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function getSchemaMap(schema) {
|
|
200
|
-
return {
|
|
201
|
-
queries: getIntrospectionFieldsList(
|
|
202
|
-
schema.getQueryType && schema.getQueryType(),
|
|
203
|
-
),
|
|
204
|
-
mutations: getIntrospectionFieldsList(
|
|
205
|
-
schema.getMutationType && schema.getMutationType(),
|
|
206
|
-
),
|
|
207
|
-
subscriptions: getIntrospectionFieldsList(
|
|
208
|
-
schema.getSubscriptionType && schema.getSubscriptionType(),
|
|
209
|
-
),
|
|
210
|
-
directives: schema.getDirectives(),
|
|
211
|
-
objects: getTypeFromSchema(schema, GraphQLObjectType),
|
|
212
|
-
unions: getTypeFromSchema(schema, GraphQLUnionType),
|
|
213
|
-
interfaces: getTypeFromSchema(schema, GraphQLInterfaceType),
|
|
214
|
-
enums: getTypeFromSchema(schema, GraphQLEnumType),
|
|
215
|
-
inputs: getTypeFromSchema(schema, GraphQLInputObjectType),
|
|
216
|
-
scalars: getTypeFromSchema(schema, GraphQLScalarType),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function mapRelationOf(relations, schema, callback) {
|
|
221
|
-
const schemaMap = getSchemaMap(schema);
|
|
222
|
-
|
|
223
|
-
for (const relation of Object.keys(relations)) {
|
|
224
|
-
const entity = schemaMap[relation];
|
|
225
|
-
if (typeof entity === "undefined") {
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
let results = [];
|
|
230
|
-
for (const [relationName, relationType] of Object.entries(entity)) {
|
|
231
|
-
results = callback(relationName, relationType, results);
|
|
232
|
-
}
|
|
233
|
-
relations[relation] = results;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return relations;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function getRelationOfReturn(type, schema) {
|
|
240
|
-
const relations = { queries: [], mutations: [], subscriptions: [] };
|
|
241
|
-
|
|
242
|
-
return mapRelationOf(
|
|
243
|
-
relations,
|
|
244
|
-
schema,
|
|
245
|
-
(relationName, relationType, results) => {
|
|
246
|
-
if (getNamedType(relationType.type).name === type.name) {
|
|
247
|
-
if (!results.find((r) => r.name === relationName)) {
|
|
248
|
-
results.push(relationType);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return results;
|
|
252
|
-
},
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function getRelationOfField(type, schema) {
|
|
257
|
-
const relations = {
|
|
258
|
-
queries: [],
|
|
259
|
-
mutations: [],
|
|
260
|
-
subscriptions: [],
|
|
261
|
-
objects: [],
|
|
262
|
-
interfaces: [],
|
|
263
|
-
inputs: [],
|
|
264
|
-
directives: [],
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
return mapRelationOf(
|
|
268
|
-
relations,
|
|
269
|
-
schema,
|
|
270
|
-
(relationName, relationType, results) => {
|
|
271
|
-
// directives are handled as flat array instead of map
|
|
272
|
-
const key = isDirectiveType(relationType)
|
|
273
|
-
? relationType.name
|
|
274
|
-
: relationName;
|
|
275
|
-
|
|
276
|
-
const fields = Object.assign(
|
|
277
|
-
{},
|
|
278
|
-
relationType.args ?? {},
|
|
279
|
-
relationType._fields ?? {},
|
|
280
|
-
);
|
|
281
|
-
for (const fieldDef of Object.values(fields)) {
|
|
282
|
-
if (getNamedType(fieldDef.type).name === type.name) {
|
|
283
|
-
if (!results.find((r) => r === key || r.name === key)) {
|
|
284
|
-
results.push(relationType);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return results;
|
|
289
|
-
},
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function getRelationOfUnion(type, schema) {
|
|
294
|
-
const relations = { unions: [] };
|
|
295
|
-
|
|
296
|
-
return mapRelationOf(
|
|
297
|
-
relations,
|
|
298
|
-
schema,
|
|
299
|
-
(relationName, relationType, results) => {
|
|
300
|
-
if (relationType._types.find((subType) => subType.name === type.name)) {
|
|
301
|
-
if (!results.find((r) => r.name === relationName)) {
|
|
302
|
-
results.push(relationType);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return results;
|
|
306
|
-
},
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function getRelationOfInterface(type, schema) {
|
|
311
|
-
const relations = { objects: [], interfaces: [] };
|
|
312
|
-
|
|
313
|
-
return mapRelationOf(
|
|
314
|
-
relations,
|
|
315
|
-
schema,
|
|
316
|
-
(relationName, relationType, results) => {
|
|
317
|
-
if (
|
|
318
|
-
relationType._interfaces.find((subType) => subType.name === type.name)
|
|
319
|
-
) {
|
|
320
|
-
if (!results.find((r) => r.name === relationName)) {
|
|
321
|
-
results.push(relationType);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return results;
|
|
325
|
-
},
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function getRelationOfImplementation(type, schema) {
|
|
330
|
-
return {
|
|
331
|
-
...getRelationOfInterface(type, schema),
|
|
332
|
-
...getRelationOfUnion(type, schema),
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function isParametrizedField(type) {
|
|
337
|
-
return hasProperty(type, "args") && type.args.length > 0;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function isOperation(type) {
|
|
341
|
-
return hasProperty(type, "type");
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
module.exports = {
|
|
345
|
-
loadSchema,
|
|
346
|
-
getDocumentLoaders,
|
|
347
|
-
isDirectiveType,
|
|
348
|
-
isObjectType,
|
|
349
|
-
getNamedType,
|
|
350
|
-
isScalarType,
|
|
351
|
-
isEnumType,
|
|
352
|
-
isUnionType,
|
|
353
|
-
getSchemaMap,
|
|
354
|
-
getTypeName,
|
|
355
|
-
isParametrizedField,
|
|
356
|
-
getFields,
|
|
357
|
-
getDefaultValue,
|
|
358
|
-
isOperation,
|
|
359
|
-
isInterfaceType,
|
|
360
|
-
isInputType,
|
|
361
|
-
isNonNullType,
|
|
362
|
-
isLeafType,
|
|
363
|
-
isListType,
|
|
364
|
-
printSchema,
|
|
365
|
-
getIntrospectionFieldsList,
|
|
366
|
-
getTypeFromSchema,
|
|
367
|
-
getRelationOfReturn,
|
|
368
|
-
getRelationOfField,
|
|
369
|
-
getRelationOfUnion,
|
|
370
|
-
getRelationOfInterface,
|
|
371
|
-
getRelationOfImplementation,
|
|
372
|
-
};
|
package/src/lib/group-info.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { convertArrayToObject } = require("../utils/scalars/array");
|
|
2
|
-
|
|
3
|
-
const DEFAULT_GROUP = "Miscellaneous";
|
|
4
|
-
const OPTION_REGEX =
|
|
5
|
-
/^@(?<directive>\w+)\((?<field>\w+)(?:\|=(?<fallback>\w+))?\)/;
|
|
6
|
-
|
|
7
|
-
function parseGroupByOption(groupOptions) {
|
|
8
|
-
if (typeof groupOptions !== "string") {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const parsedOptions = OPTION_REGEX.exec(groupOptions);
|
|
13
|
-
|
|
14
|
-
if (typeof parsedOptions == "undefined" || parsedOptions == null) {
|
|
15
|
-
throw new Error(`Invalid "${groupOptions}"`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const { directive, field, fallback = DEFAULT_GROUP } = parsedOptions.groups;
|
|
19
|
-
return { directive, field, fallback };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getGroups(rootTypes, groupByDirective) {
|
|
23
|
-
let groups = {};
|
|
24
|
-
|
|
25
|
-
if (typeof groupByDirective == "undefined" || groupByDirective == null) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Object.keys(rootTypes).forEach((typeName) => {
|
|
30
|
-
if (
|
|
31
|
-
typeof rootTypes[typeName] != "undefined" &&
|
|
32
|
-
rootTypes[typeName] != null
|
|
33
|
-
) {
|
|
34
|
-
if (Array.isArray(rootTypes[typeName])) {
|
|
35
|
-
rootTypes[typeName] = convertArrayToObject(rootTypes[typeName]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
Object.keys(rootTypes[typeName]).forEach((name) => {
|
|
39
|
-
if (
|
|
40
|
-
typeof rootTypes[typeName][name]["astNode"] != "undefined" &&
|
|
41
|
-
rootTypes[typeName][name]["astNode"] != null
|
|
42
|
-
) {
|
|
43
|
-
const allDirectives =
|
|
44
|
-
rootTypes[typeName][name]["astNode"]["directives"];
|
|
45
|
-
groups[name] = getGroupInfo(allDirectives, groupByDirective);
|
|
46
|
-
} else {
|
|
47
|
-
groups[name] = groupByDirective.fallback;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return groups;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getGroupInfo(allDirectives, groupByDirective) {
|
|
57
|
-
let group = groupByDirective.fallback; // default value is fallback, and it will be only overridden if a group is found
|
|
58
|
-
|
|
59
|
-
if (!Array.isArray(allDirectives)) {
|
|
60
|
-
return group;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (const directive of allDirectives) {
|
|
64
|
-
if (directive.name.value !== groupByDirective.directive) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const field = directive.arguments.find(
|
|
68
|
-
({ name }) => name.value === groupByDirective.field,
|
|
69
|
-
);
|
|
70
|
-
return field.value.value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return group;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = { getGroups, parseGroupByOption };
|