@graphql-markdown/core 1.5.0 → 1.6.0
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/package.json +8 -3
- package/src/config.js +7 -8
- package/src/graphql-config.js +61 -0
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.6.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "src/index.js",
|
|
11
11
|
"repository": {
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"@graphql-markdown/utils": "^1.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
+
"@graphql-markdown/diff": "^1.0.13",
|
|
35
36
|
"@graphql-markdown/printer-legacy": "^1.4.0",
|
|
36
|
-
"
|
|
37
|
+
"graphql-config": "^5.0.2",
|
|
37
38
|
"prettier": "^2.8"
|
|
38
39
|
},
|
|
39
40
|
"peerDependenciesMeta": {
|
|
@@ -43,12 +44,16 @@
|
|
|
43
44
|
"@graphql-markdown/diff": {
|
|
44
45
|
"optional": true
|
|
45
46
|
},
|
|
47
|
+
"graphql-config": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
46
50
|
"prettier": {
|
|
47
51
|
"optional": true
|
|
48
52
|
}
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"@graphql-markdown/printer-legacy": "^1.1.3"
|
|
55
|
+
"@graphql-markdown/printer-legacy": "^1.1.3",
|
|
56
|
+
"graphql-config": "^5.0.2"
|
|
52
57
|
},
|
|
53
58
|
"directories": {
|
|
54
59
|
"test": "tests"
|
package/src/config.js
CHANGED
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
object: { hasProperty },
|
|
6
6
|
} = require("@graphql-markdown/utils");
|
|
7
7
|
|
|
8
|
+
const { loadConfiguration } = require("./graphql-config");
|
|
9
|
+
|
|
8
10
|
const PACKAGE_NAME = "@graphql-markdown/docusaurus";
|
|
9
11
|
const ASSETS_LOCATION = join(__dirname, "../assets/");
|
|
10
12
|
|
|
@@ -35,17 +37,14 @@ const DEFAULT_OPTIONS = {
|
|
|
35
37
|
skipDocDirective: [],
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
function buildConfig(configFileOpts, cliOpts) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (typeof configFileOpts !== "undefined" && configFileOpts != null) {
|
|
42
|
-
config = { ...DEFAULT_OPTIONS, ...configFileOpts };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (typeof cliOpts === "undefined" || cliOpts == null) {
|
|
40
|
+
function buildConfig(configFileOpts, cliOpts, id = undefined) {
|
|
41
|
+
if (typeof cliOpts === "undefined" || cliOpts === null) {
|
|
46
42
|
cliOpts = {};
|
|
47
43
|
}
|
|
48
44
|
|
|
45
|
+
const graphqlConfig = loadConfiguration(id);
|
|
46
|
+
const config = { ...DEFAULT_OPTIONS, ...graphqlConfig, ...configFileOpts };
|
|
47
|
+
|
|
49
48
|
const baseURL = cliOpts.base ?? config.baseURL;
|
|
50
49
|
const skipDocDirective = getSkipDocDirectives(cliOpts, config);
|
|
51
50
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const logger = require("@graphql-markdown/utils").logger.getInstance();
|
|
2
|
+
|
|
3
|
+
const EXTENSION_NAME = "graphql-markdown";
|
|
4
|
+
|
|
5
|
+
const loadConfiguration = (
|
|
6
|
+
id = undefined,
|
|
7
|
+
options = undefined,
|
|
8
|
+
{ throwOnMissing, throwOnEmpty } = {
|
|
9
|
+
throwOnMissing: false,
|
|
10
|
+
throwOnEmpty: false,
|
|
11
|
+
},
|
|
12
|
+
) => {
|
|
13
|
+
let GraphQLConfig;
|
|
14
|
+
try {
|
|
15
|
+
// eslint-disable-next-line node/no-missing-require
|
|
16
|
+
GraphQLConfig = require("graphql-config");
|
|
17
|
+
} catch (error) {
|
|
18
|
+
logger.log("Cannot find module 'graphql-config'!");
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const config = GraphQLConfig.loadConfigSync({
|
|
23
|
+
...options,
|
|
24
|
+
extensions: [() => ({ name: EXTENSION_NAME })],
|
|
25
|
+
throwOnMissing,
|
|
26
|
+
throwOnEmpty,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const projectConfig = config.getProject(id).extension(EXTENSION_NAME);
|
|
31
|
+
|
|
32
|
+
if (typeof projectConfig?.schema !== "string") {
|
|
33
|
+
const schema = projectConfig?.schema[0];
|
|
34
|
+
if (typeof schema === "string") {
|
|
35
|
+
projectConfig.schema = schema;
|
|
36
|
+
} else {
|
|
37
|
+
projectConfig.schema = Object.keys(schema)[0];
|
|
38
|
+
projectConfig.loaders = setLoaderOptions(
|
|
39
|
+
projectConfig.loaders,
|
|
40
|
+
Object.values(schema)[0],
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return projectConfig;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const setLoaderOptions = (loaders, options) => {
|
|
51
|
+
for (const loader in loaders) {
|
|
52
|
+
if (typeof loaders[loader] === "string") {
|
|
53
|
+
loaders[loader] = { module: loaders[loader], options };
|
|
54
|
+
} else {
|
|
55
|
+
loaders[loader].options = { ...options, ...loaders[loader].options };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return loaders;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = { loadConfiguration, EXTENSION_NAME };
|