@ttoss/graphql-api-cli 0.9.1 → 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 +97 -15
- package/dist/esm/index.js +27 -15
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# @ttoss/graphql-api-cli
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## ESM Only
|
|
6
|
-
|
|
7
|
-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
3
|
+
CLI tool that generates GraphQL schemas and TypeScript types from your [`@ttoss/graphql-api`](https://ttoss.dev/docs/modules/packages/graphql-api/) schema composer, enabling seamless integration with Relay and providing type safety for your GraphQL operations.
|
|
8
4
|
|
|
9
5
|
## Installation
|
|
10
6
|
|
|
@@ -12,15 +8,23 @@ This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908
|
|
|
12
8
|
pnpm add -D @ttoss/graphql-api-cli
|
|
13
9
|
```
|
|
14
10
|
|
|
15
|
-
##
|
|
11
|
+
## Core Functionality
|
|
12
|
+
|
|
13
|
+
This CLI is essential for GraphQL development workflows using the ttoss ecosystem, providing automated generation of:
|
|
14
|
+
|
|
15
|
+
- **GraphQL Schema (SDL)**: Creates `schema/schema.graphql` file required for Relay introspection queries
|
|
16
|
+
- **TypeScript Types**: Generates `schema/types.ts` with strongly-typed interfaces for your GraphQL schema
|
|
17
|
+
- **Development Integration**: Seamlessly integrates with your build pipeline and development workflow
|
|
18
|
+
|
|
19
|
+
The tool operates by importing your `schemaComposer.ts` file, extracting the schema definition, and generating both the SDL schema file and corresponding TypeScript types using GraphQL Code Generator.
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
## Basic Usage
|
|
18
22
|
|
|
19
23
|
```bash
|
|
20
24
|
ttoss-graphql-api build-schema
|
|
21
25
|
```
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
Add the build script to your `package.json` for easy integration:
|
|
24
28
|
|
|
25
29
|
```json
|
|
26
30
|
{
|
|
@@ -30,20 +34,98 @@ You can add the `build-schema` script to your `package.json`:
|
|
|
30
34
|
}
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
This command:
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
1. Reads your `src/schemaComposer.ts` file
|
|
40
|
+
2. Bundles it using esbuild to resolve all dependencies
|
|
41
|
+
3. Extracts the schema definition using the schemaComposer
|
|
42
|
+
4. Generates `schema/schema.graphql` in SDL format
|
|
43
|
+
5. Creates `schema/types.ts` with TypeScript type definitions
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
## Command Options
|
|
46
|
+
|
|
47
|
+
### Schema Composer Directory (`-d`, `--directory`)
|
|
48
|
+
|
|
49
|
+
Specify a custom directory for your `schemaComposer.ts` file:
|
|
38
50
|
|
|
39
51
|
```bash
|
|
40
|
-
ttoss-graphql-api build-schema -d
|
|
52
|
+
ttoss-graphql-api build-schema -d src/graphql
|
|
53
|
+
ttoss-graphql-api build-schema --directory tests
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Default:** `src`
|
|
57
|
+
|
|
58
|
+
### External Dependencies (`--external`)
|
|
59
|
+
|
|
60
|
+
Control which additional dependencies are marked as external during the bundling process:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ttoss-graphql-api build-schema --external graphql-compose,@aws-sdk/client-dynamodb
|
|
64
|
+
```
|
|
65
|
+
|
|
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.
|
|
67
|
+
|
|
68
|
+
## Integration Examples
|
|
69
|
+
|
|
70
|
+
### Basic Project Structure
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
my-graphql-api/
|
|
74
|
+
├── schema/ # Generated files
|
|
75
|
+
│ ├── schema.graphql # SDL schema
|
|
76
|
+
│ └── types.ts # TypeScript types
|
|
77
|
+
├── src/
|
|
78
|
+
│ ├── schemaComposer.ts # Your schema definition
|
|
79
|
+
│ └── modules/ # GraphQL modules
|
|
80
|
+
└── package.json
|
|
41
81
|
```
|
|
42
82
|
|
|
43
|
-
###
|
|
83
|
+
### Schema Composer Example
|
|
44
84
|
|
|
45
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
// src/schemaComposer.ts
|
|
87
|
+
import { schemaComposer } from '@ttoss/graphql-api';
|
|
88
|
+
import './modules/User/composer';
|
|
89
|
+
import './modules/Post/composer';
|
|
90
|
+
|
|
91
|
+
export { schemaComposer };
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Advanced Configuration
|
|
95
|
+
|
|
96
|
+
For complex projects requiring specific external handling:
|
|
46
97
|
|
|
47
98
|
```bash
|
|
48
|
-
|
|
99
|
+
# Custom directory with specific externals
|
|
100
|
+
ttoss-graphql-api build-schema \
|
|
101
|
+
--directory src/api \
|
|
102
|
+
--external graphql-compose,dataloader,aws-sdk
|
|
49
103
|
```
|
|
104
|
+
|
|
105
|
+
### CI/CD Integration
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"scripts": {
|
|
110
|
+
"build": "pnpm build-schema && pnpm compile",
|
|
111
|
+
"build-schema": "ttoss-graphql-api build-schema",
|
|
112
|
+
"dev": "pnpm build-schema && tsx watch server.ts"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Technical Details
|
|
118
|
+
|
|
119
|
+
**ESM Only**: This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) and requires Node.js with ES modules support.
|
|
120
|
+
|
|
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
|
+
|
|
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
|
+
|
|
127
|
+
## Related Packages
|
|
128
|
+
|
|
129
|
+
- **[@ttoss/graphql-api](https://ttoss.dev/docs/modules/packages/graphql-api/)**: Core GraphQL API building library
|
|
130
|
+
- **[@ttoss/graphql-api-server](https://ttoss.dev/docs/modules/packages/graphql-api-server/)**: Local development server
|
|
131
|
+
- **[@ttoss/appsync-api](https://ttoss.dev/docs/modules/packages/appsync-api/)**: AWS AppSync integration
|
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",
|
|
@@ -34,10 +34,10 @@ var package_default = {
|
|
|
34
34
|
sideEffects: false,
|
|
35
35
|
dependencies: {
|
|
36
36
|
"@graphql-codegen/core": "^4.0.2",
|
|
37
|
-
"@graphql-codegen/typescript": "^4.1.
|
|
37
|
+
"@graphql-codegen/typescript": "^4.1.6",
|
|
38
38
|
commander: "^14.0.0",
|
|
39
|
-
esbuild: "^0.25.
|
|
40
|
-
graphql: "^16.
|
|
39
|
+
esbuild: "^0.25.8",
|
|
40
|
+
graphql: "^16.11.0",
|
|
41
41
|
npmlog: "^7.0.1"
|
|
42
42
|
},
|
|
43
43
|
peerDependencies: {
|
|
@@ -56,29 +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
|
-
|
|
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);
|
|
72
82
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
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);
|
|
77
89
|
});
|
|
78
90
|
const result = await esbuild.build({
|
|
79
91
|
bundle: true,
|
|
80
92
|
entryPoints: [schemaComposerPath],
|
|
81
|
-
external: external
|
|
93
|
+
external: [...external, ...dependencies],
|
|
82
94
|
format: "esm",
|
|
83
95
|
outfile,
|
|
84
96
|
platform: "node",
|
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.3",
|
|
4
4
|
"description": "A library for building GraphQL APIs types and schema.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@graphql-codegen/core": "^4.0.2",
|
|
25
|
-
"@graphql-codegen/typescript": "^4.1.
|
|
25
|
+
"@graphql-codegen/typescript": "^4.1.6",
|
|
26
26
|
"commander": "^14.0.0",
|
|
27
|
-
"esbuild": "^0.25.
|
|
28
|
-
"graphql": "^16.
|
|
27
|
+
"esbuild": "^0.25.8",
|
|
28
|
+
"graphql": "^16.11.0",
|
|
29
29
|
"npmlog": "^7.0.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -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.6"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"api",
|