@ttoss/graphql-api-cli 0.9.2 → 0.9.4
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 +5 -5
- package/dist/esm/index.js +33 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,15 +57,13 @@ ttoss-graphql-api build-schema --directory tests
|
|
|
57
57
|
|
|
58
58
|
### External Dependencies (`--external`)
|
|
59
59
|
|
|
60
|
-
Control which dependencies are marked as external during the bundling process:
|
|
60
|
+
Control which additional dependencies are marked as external during the bundling process:
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
63
|
ttoss-graphql-api build-schema --external graphql-compose,@aws-sdk/client-dynamodb
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
**Default behavior:** Automatically excludes all dependencies and
|
|
67
|
-
|
|
68
|
-
- `graphql` package (required for proper schema generation)
|
|
66
|
+
**Default behavior:** Automatically excludes all package.json dependencies (except workspace packages and `graphql`) and appends any specified external dependencies to this list. Workspace dependencies (those with `workspace:` prefix) are automatically excluded from external handling to prevent bundling issues in monorepo environments. The `graphql` dependency is always bundled to avoid dynamic require errors.
|
|
69
67
|
|
|
70
68
|
## Integration Examples
|
|
71
69
|
|
|
@@ -120,7 +118,9 @@ ttoss-graphql-api build-schema \
|
|
|
120
118
|
|
|
121
119
|
**ESM Only**: This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) and requires Node.js with ES modules support.
|
|
122
120
|
|
|
123
|
-
**Bundling Process**: Uses esbuild to bundle your schema composer and its dependencies, ensuring all imports are resolved correctly before schema extraction.
|
|
121
|
+
**Bundling Process**: Uses esbuild to bundle your schema composer and its dependencies, ensuring all imports are resolved correctly before schema extraction. Automatically excludes all package.json dependencies as external (except workspace packages and `graphql`), with support for additional external dependencies via the `--external` option. The `graphql` package is always bundled to prevent "Dynamic require of 'graphql' is not supported" errors.
|
|
122
|
+
|
|
123
|
+
**Workspace Dependencies**: Dependencies with `workspace:` prefix are automatically excluded from external handling to prevent TypeScript import errors in monorepo environments where workspace packages may export `.ts` files directly.
|
|
124
124
|
|
|
125
125
|
**Type Generation**: Leverages [@graphql-codegen/typescript](https://www.npmjs.com/package/@graphql-codegen/typescript) for precise TypeScript type generation with interface declarations and preserved naming conventions.
|
|
126
126
|
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
4
|
+
value,
|
|
5
|
+
configurable: true
|
|
6
|
+
});
|
|
2
7
|
|
|
3
8
|
// src/index.ts
|
|
4
9
|
import * as fs from "fs";
|
|
@@ -13,7 +18,7 @@ import log from "npmlog";
|
|
|
13
18
|
// package.json
|
|
14
19
|
var package_default = {
|
|
15
20
|
name: "@ttoss/graphql-api-cli",
|
|
16
|
-
version: "0.9.
|
|
21
|
+
version: "0.9.3",
|
|
17
22
|
description: "A library for building GraphQL APIs types and schema.",
|
|
18
23
|
license: "MIT",
|
|
19
24
|
author: "ttoss",
|
|
@@ -56,33 +61,41 @@ var package_default = {
|
|
|
56
61
|
|
|
57
62
|
// src/index.ts
|
|
58
63
|
var logPrefix = "graphql-api";
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
external,
|
|
64
|
+
var importSchemaComposer = /* @__PURE__ */__name(async ({
|
|
65
|
+
external = [],
|
|
62
66
|
schemaComposerPath
|
|
63
67
|
}) => {
|
|
64
68
|
const lastEntryPointName = schemaComposerPath.split("/").pop();
|
|
65
69
|
const filename = lastEntryPointName?.split(".")[0];
|
|
66
70
|
const outfile = path.resolve(process.cwd(), "out", filename + ".js");
|
|
67
71
|
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
const getPackageDependencies = /* @__PURE__ */__name(packageJsonPath2 => {
|
|
73
|
+
const packageJson = fs.readFileSync(packageJsonPath2, "utf-8");
|
|
74
|
+
const parsedPackageJson = JSON.parse(packageJson);
|
|
75
|
+
const dependencies2 = [];
|
|
76
|
+
for (const [dependency, version] of Object.entries(parsedPackageJson.dependencies || {})) {
|
|
77
|
+
if (dependency === "graphql") {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (version.startsWith("file:")) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (version.startsWith("workspace:")) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
dependencies2.push(dependency);
|
|
79
87
|
}
|
|
80
|
-
return
|
|
88
|
+
return dependencies2;
|
|
89
|
+
}, "getPackageDependencies");
|
|
90
|
+
const dependencies = getPackageDependencies(packageJsonPath).filter((dep, index, self) => {
|
|
91
|
+
return self.indexOf(dep) === index;
|
|
92
|
+
}).sort((a, b) => {
|
|
93
|
+
return a.localeCompare(b);
|
|
81
94
|
});
|
|
82
95
|
const result = await esbuild.build({
|
|
83
96
|
bundle: true,
|
|
84
97
|
entryPoints: [schemaComposerPath],
|
|
85
|
-
external: external
|
|
98
|
+
external: [...external, ...dependencies],
|
|
86
99
|
format: "esm",
|
|
87
100
|
outfile,
|
|
88
101
|
platform: "node",
|
|
@@ -99,8 +112,8 @@ var importSchemaComposer = async ({
|
|
|
99
112
|
console.error("Failed importing build config file: ", filename);
|
|
100
113
|
throw error;
|
|
101
114
|
}
|
|
102
|
-
};
|
|
103
|
-
var buildSchema = async ({
|
|
115
|
+
}, "importSchemaComposer");
|
|
116
|
+
var buildSchema = /* @__PURE__ */__name(async ({
|
|
104
117
|
directory,
|
|
105
118
|
external
|
|
106
119
|
}) => {
|
|
@@ -146,7 +159,7 @@ var buildSchema = async ({
|
|
|
146
159
|
await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
|
|
147
160
|
${typesOutput}`);
|
|
148
161
|
log.info(logPrefix, "Schema and types generated!");
|
|
149
|
-
};
|
|
162
|
+
}, "buildSchema");
|
|
150
163
|
var program = new Command();
|
|
151
164
|
program.name("ttoss-graphql-api").version(package_default.version, "-v, --version", "Output the current version of the GraphQL API");
|
|
152
165
|
program.command("build-schema").option("-d, --directory <directory>", "Schema composer directory", "src").option("--external <external...>", "External dependencies to ignore during build").action(options => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "A library for building GraphQL APIs types and schema.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsup": "^8.5.0",
|
|
36
|
-
"@ttoss/config": "^1.35.
|
|
36
|
+
"@ttoss/config": "^1.35.7"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"api",
|