@ttoss/graphql-api-cli 0.9.0 → 0.9.2

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 CHANGED
@@ -1,10 +1,6 @@
1
1
  # @ttoss/graphql-api-cli
2
2
 
3
- This package generates schema and TypeScript types for your GraphQL API.
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
- ## Usage
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
- As Relay needs an introspection query to work, this package provides a way to build the GraphQL schema by running `ttoss-graphql-api build-schema`. It build the schema using the `schemaComposer` from `src/schemaComposer.ts` file and save the schema in `schema/schema.graphql` file and TypeScript types in `schema/types.ts` file.
21
+ ## Basic Usage
18
22
 
19
23
  ```bash
20
24
  ttoss-graphql-api build-schema
21
25
  ```
22
26
 
23
- You can add the `build-schema` script to your `package.json`:
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
- ## Options
37
+ This command:
34
38
 
35
- ### `--directory`/`-d`
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
- If your `schemaComposer` is in a different directory, you can pass the `--directory`/`-d` option to `ttoss-graphql-api build-schema` command:
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 tests
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 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 dependencies and devDependencies from your `package.json`, except:
67
+
68
+ - `graphql` package (required for proper schema generation)
69
+
70
+ ## Integration Examples
71
+
72
+ ### Basic Project Structure
73
+
74
+ ```
75
+ my-graphql-api/
76
+ ├── schema/ # Generated files
77
+ │ ├── schema.graphql # SDL schema
78
+ │ └── types.ts # TypeScript types
79
+ ├── src/
80
+ │ ├── schemaComposer.ts # Your schema definition
81
+ │ └── modules/ # GraphQL modules
82
+ └── package.json
83
+ ```
84
+
85
+ ### Schema Composer Example
86
+
87
+ ```typescript
88
+ // src/schemaComposer.ts
89
+ import { schemaComposer } from '@ttoss/graphql-api';
90
+ import './modules/User/composer';
91
+ import './modules/Post/composer';
92
+
93
+ export { schemaComposer };
41
94
  ```
42
95
 
43
- ### `--external`
96
+ ### Advanced Configuration
44
97
 
45
- External dependencies to ignore during build. If you don't set this option, the `build-schema` command will use the `dependencies` from your `package.json` file.
98
+ For complex projects requiring specific external handling:
46
99
 
47
100
  ```bash
48
- ttoss-graphql-api build-schema --external graphql-compose,graphql
101
+ # Custom directory with specific externals
102
+ ttoss-graphql-api build-schema \
103
+ --directory src/api \
104
+ --external graphql-compose,dataloader,aws-sdk
49
105
  ```
106
+
107
+ ### CI/CD Integration
108
+
109
+ ```json
110
+ {
111
+ "scripts": {
112
+ "build": "pnpm build-schema && pnpm compile",
113
+ "build-schema": "ttoss-graphql-api build-schema",
114
+ "dev": "pnpm build-schema && tsx watch server.ts"
115
+ }
116
+ }
117
+ ```
118
+
119
+ ## Technical Details
120
+
121
+ **ESM Only**: This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) and requires Node.js with ES modules support.
122
+
123
+ **Bundling Process**: Uses esbuild to bundle your schema composer and its dependencies, ensuring all imports are resolved correctly before schema extraction.
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.8.7",
16
+ version: "0.9.1",
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.2",
38
- commander: "^12.1.0",
39
- esbuild: "^0.25.5",
40
- graphql: "^16.9.0",
37
+ "@graphql-codegen/typescript": "^4.1.6",
38
+ commander: "^14.0.0",
39
+ esbuild: "^0.25.8",
40
+ graphql: "^16.11.0",
41
41
  npmlog: "^7.0.1"
42
42
  },
43
43
  peerDependencies: {
@@ -66,7 +66,11 @@ var importSchemaComposer = async ({
66
66
  const outfile = path.resolve(process.cwd(), "out", filename + ".js");
67
67
  const packageJsonPath = path.resolve(process.cwd(), "package.json");
68
68
  const packageJson = await fs.promises.readFile(packageJsonPath, "utf-8");
69
- const dependencies = Object.keys(JSON.parse(packageJson).dependencies).filter(dependency => {
69
+ const parsedPackageJson = JSON.parse(packageJson);
70
+ const dependencies = Object.keys({
71
+ ...(parsedPackageJson.dependencies || {}),
72
+ ...(parsedPackageJson.devDependencies || {})
73
+ }).filter(dependency => {
70
74
  if (isMonorepo && dependency.startsWith("@ttoss/")) {
71
75
  return false;
72
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/graphql-api-cli",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
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.2",
26
- "commander": "^12.1.0",
27
- "esbuild": "^0.25.5",
28
- "graphql": "^16.9.0",
25
+ "@graphql-codegen/typescript": "^4.1.6",
26
+ "commander": "^14.0.0",
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.4"
36
+ "@ttoss/config": "^1.35.6"
37
37
  },
38
38
  "keywords": [
39
39
  "api",