@ttoss/graphql-api-cli 0.9.2 → 0.9.3
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 +24 -16
- package/package.json +1 -1
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
|
@@ -13,7 +13,7 @@ import log from "npmlog";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "@ttoss/graphql-api-cli",
|
|
16
|
-
version: "0.9.
|
|
16
|
+
version: "0.9.2",
|
|
17
17
|
description: "A library for building GraphQL APIs types and schema.",
|
|
18
18
|
license: "MIT",
|
|
19
19
|
author: "ttoss",
|
|
@@ -56,33 +56,41 @@ var package_default = {
|
|
|
56
56
|
|
|
57
57
|
// src/index.ts
|
|
58
58
|
var logPrefix = "graphql-api";
|
|
59
|
-
var isMonorepo = process.env.TTOSS_MONOREPO === "true";
|
|
60
59
|
var importSchemaComposer = async ({
|
|
61
|
-
external,
|
|
60
|
+
external = [],
|
|
62
61
|
schemaComposerPath
|
|
63
62
|
}) => {
|
|
64
63
|
const lastEntryPointName = schemaComposerPath.split("/").pop();
|
|
65
64
|
const filename = lastEntryPointName?.split(".")[0];
|
|
66
65
|
const outfile = path.resolve(process.cwd(), "out", filename + ".js");
|
|
67
66
|
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
const getPackageDependencies = packageJsonPath2 => {
|
|
68
|
+
const packageJson = fs.readFileSync(packageJsonPath2, "utf-8");
|
|
69
|
+
const parsedPackageJson = JSON.parse(packageJson);
|
|
70
|
+
const dependencies2 = [];
|
|
71
|
+
for (const [dependency, version] of Object.entries(parsedPackageJson.dependencies || {})) {
|
|
72
|
+
if (dependency === "graphql") {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (version.startsWith("file:")) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (version.startsWith("workspace:")) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
dependencies2.push(dependency);
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
83
|
+
return dependencies2;
|
|
84
|
+
};
|
|
85
|
+
const dependencies = getPackageDependencies(packageJsonPath).filter((dep, index, self) => {
|
|
86
|
+
return self.indexOf(dep) === index;
|
|
87
|
+
}).sort((a, b) => {
|
|
88
|
+
return a.localeCompare(b);
|
|
81
89
|
});
|
|
82
90
|
const result = await esbuild.build({
|
|
83
91
|
bundle: true,
|
|
84
92
|
entryPoints: [schemaComposerPath],
|
|
85
|
-
external: external
|
|
93
|
+
external: [...external, ...dependencies],
|
|
86
94
|
format: "esm",
|
|
87
95
|
outfile,
|
|
88
96
|
platform: "node",
|