@effect-gql/cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Nick Fisher
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Effect GraphQL CLI
4
+ *
5
+ * Usage:
6
+ * effect-gql <command> [options]
7
+ *
8
+ * Commands:
9
+ * generate-schema Generate GraphQL SDL from a schema module
10
+ * create Create a new Effect GraphQL project (coming soon)
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
package/dist/bin.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Effect GraphQL CLI
5
+ *
6
+ * Usage:
7
+ * effect-gql <command> [options]
8
+ *
9
+ * Commands:
10
+ * generate-schema Generate GraphQL SDL from a schema module
11
+ * create Create a new Effect GraphQL project (coming soon)
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const effect_1 = require("effect");
15
+ const generate_schema_1 = require("./commands/generate-schema");
16
+ const VERSION = "0.1.0";
17
+ const printHelp = () => {
18
+ console.log(`
19
+ Effect GraphQL CLI v${VERSION}
20
+
21
+ Usage: effect-gql <command> [options]
22
+
23
+ Commands:
24
+ generate-schema Generate GraphQL SDL from a schema module
25
+ create Create a new Effect GraphQL project (coming soon)
26
+
27
+ Options:
28
+ -h, --help Show this help message
29
+ -v, --version Show version number
30
+
31
+ Examples:
32
+ effect-gql generate-schema ./src/schema.ts
33
+ effect-gql generate-schema ./src/schema.ts -o schema.graphql
34
+ effect-gql create my-app
35
+
36
+ Run 'effect-gql <command> --help' for command-specific help.
37
+ `);
38
+ };
39
+ const printVersion = () => {
40
+ console.log(`effect-gql v${VERSION}`);
41
+ };
42
+ const main = effect_1.Effect.gen(function* () {
43
+ const args = process.argv.slice(2);
44
+ if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
45
+ printHelp();
46
+ return;
47
+ }
48
+ if (args[0] === "-v" || args[0] === "--version") {
49
+ printVersion();
50
+ return;
51
+ }
52
+ const command = args[0];
53
+ const commandArgs = args.slice(1);
54
+ switch (command) {
55
+ case "generate-schema":
56
+ yield* (0, generate_schema_1.runGenerateSchema)(commandArgs);
57
+ break;
58
+ case "create":
59
+ yield* effect_1.Console.log("The 'create' command is coming soon!");
60
+ yield* effect_1.Console.log("It will help you scaffold new Effect GraphQL projects.");
61
+ break;
62
+ default:
63
+ yield* effect_1.Console.error(`Unknown command: ${command}`);
64
+ printHelp();
65
+ process.exitCode = 1;
66
+ }
67
+ });
68
+ effect_1.Effect.runPromise(main.pipe(effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`).pipe(effect_1.Effect.andThen(effect_1.Effect.sync(() => { process.exitCode = 1; }))))));
69
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;AACA;;;;;;;;;GASG;;AAEH,mCAAwC;AACxC,gEAA8D;AAE9D,MAAM,OAAO,GAAG,OAAO,CAAA;AAEvB,MAAM,SAAS,GAAG,GAAS,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC;sBACQ,OAAO;;;;;;;;;;;;;;;;;;CAkB5B,CAAC,CAAA;AACF,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAS,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,EAAE,CAAC,CAAA;AACvC,CAAC,CAAA;AAED,MAAM,IAAI,GAAG,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAElC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QAClE,SAAS,EAAE,CAAA;QACX,OAAM;IACR,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;QAChD,YAAY,EAAE,CAAA;QACd,OAAM;IACR,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACvB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAEjC,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,iBAAiB;YACpB,KAAK,CAAC,CAAC,IAAA,mCAAiB,EAAC,WAAW,CAAC,CAAA;YACrC,MAAK;QAEP,KAAK,QAAQ;YACX,KAAK,CAAC,CAAC,gBAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAA;YAC1D,KAAK,CAAC,CAAC,gBAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAA;YAC5E,MAAK;QAEP;YACE,KAAK,CAAC,CAAC,gBAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAA;YACnD,SAAS,EAAE,CAAA;YACX,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACxB,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,eAAM,CAAC,UAAU,CACf,IAAI,CAAC,IAAI,CACP,eAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CACxB,gBAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAC3C,eAAM,CAAC,OAAO,CAAC,eAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC,CAC5D,CACF,CACF,CACF,CAAA"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Generate GraphQL SDL from an effect-gql schema builder.
3
+ *
4
+ * Usage:
5
+ * effect-gql generate-schema <module-path> [options]
6
+ *
7
+ * The module should export one of:
8
+ * - `builder` - A GraphQLSchemaBuilder instance
9
+ * - `schema` - A GraphQLSchema instance
10
+ * - `default` - Either of the above as default export
11
+ */
12
+ import { Effect } from "effect";
13
+ import type { GraphQLSchema } from "graphql";
14
+ /**
15
+ * Load a schema from a module path.
16
+ * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
17
+ */
18
+ export declare const loadSchema: (modulePath: string) => Effect.Effect<GraphQLSchema, Error>;
19
+ /**
20
+ * Generate SDL from a schema
21
+ */
22
+ export declare const generateSDL: (schema: GraphQLSchema, options?: {
23
+ sort?: boolean;
24
+ }) => string;
25
+ /**
26
+ * Generate SDL from a module path
27
+ */
28
+ export declare const generateSDLFromModule: (modulePath: string, options?: {
29
+ sort?: boolean;
30
+ }) => Effect.Effect<string, Error>;
31
+ export declare const printGenerateSchemaHelp: () => void;
32
+ /**
33
+ * Entry point for the generate-schema command
34
+ */
35
+ export declare const runGenerateSchema: (args: string[]) => Effect.Effect<void, Error>;
36
+ //# sourceMappingURL=generate-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/commands/generate-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAW,MAAM,QAAQ,CAAA;AAExC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAe5C;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,YAAY,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,CAoD9E,CAAA;AAEJ;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,aAAa,EACrB,UAAS;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,KAC/B,MAGF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,YAAY,MAAM,EAClB,UAAS;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,KAC/B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CACqD,CAAA;AA0FnF,eAAO,MAAM,uBAAuB,QAAO,IAyB1C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAqBxE,CAAA"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * Generate GraphQL SDL from an effect-gql schema builder.
4
+ *
5
+ * Usage:
6
+ * effect-gql generate-schema <module-path> [options]
7
+ *
8
+ * The module should export one of:
9
+ * - `builder` - A GraphQLSchemaBuilder instance
10
+ * - `schema` - A GraphQLSchema instance
11
+ * - `default` - Either of the above as default export
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.runGenerateSchema = exports.printGenerateSchemaHelp = exports.generateSDLFromModule = exports.generateSDL = exports.loadSchema = void 0;
48
+ const effect_1 = require("effect");
49
+ const core_1 = require("@effect-gql/core");
50
+ const fs = __importStar(require("fs"));
51
+ const path = __importStar(require("path"));
52
+ /**
53
+ * Load a schema from a module path.
54
+ * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
55
+ */
56
+ const loadSchema = (modulePath) => effect_1.Effect.gen(function* () {
57
+ const absolutePath = path.resolve(process.cwd(), modulePath);
58
+ // Validate file exists
59
+ if (!fs.existsSync(absolutePath)) {
60
+ return yield* effect_1.Effect.fail(new Error(`File not found: ${absolutePath}`));
61
+ }
62
+ // Dynamic import (works with both ESM and CJS via tsx/ts-node)
63
+ const module = yield* effect_1.Effect.tryPromise({
64
+ try: async () => {
65
+ // Clear require cache for watch mode
66
+ const resolved = require.resolve(absolutePath);
67
+ delete require.cache[resolved];
68
+ // Try dynamic import first (ESM), fall back to require (CJS)
69
+ try {
70
+ return await Promise.resolve(`${absolutePath}`).then(s => __importStar(require(s)));
71
+ }
72
+ catch {
73
+ return require(absolutePath);
74
+ }
75
+ },
76
+ catch: (error) => new Error(`Failed to load module: ${error}`),
77
+ });
78
+ // Look for builder or schema export
79
+ const exported = module.builder ?? module.schema ?? module.default;
80
+ if (!exported) {
81
+ return yield* effect_1.Effect.fail(new Error(`Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`));
82
+ }
83
+ // If it's a builder, call buildSchema()
84
+ if (typeof exported.buildSchema === "function") {
85
+ return exported.buildSchema();
86
+ }
87
+ // If it's already a GraphQLSchema
88
+ if (exported.getQueryType && exported.getTypeMap) {
89
+ return exported;
90
+ }
91
+ return yield* effect_1.Effect.fail(new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`));
92
+ });
93
+ exports.loadSchema = loadSchema;
94
+ /**
95
+ * Generate SDL from a schema
96
+ */
97
+ const generateSDL = (schema, options = {}) => {
98
+ const finalSchema = options.sort !== false ? (0, core_1.lexicographicSortSchema)(schema) : schema;
99
+ return (0, core_1.printSchema)(finalSchema);
100
+ };
101
+ exports.generateSDL = generateSDL;
102
+ /**
103
+ * Generate SDL from a module path
104
+ */
105
+ const generateSDLFromModule = (modulePath, options = {}) => (0, exports.loadSchema)(modulePath).pipe(effect_1.Effect.map((schema) => (0, exports.generateSDL)(schema, options)));
106
+ exports.generateSDLFromModule = generateSDLFromModule;
107
+ /**
108
+ * Run the generate-schema command
109
+ */
110
+ const run = (options) => effect_1.Effect.gen(function* () {
111
+ const schema = yield* (0, exports.loadSchema)(options.modulePath);
112
+ const sdl = (0, exports.generateSDL)(schema, { sort: options.sort });
113
+ if (options.output) {
114
+ const outputPath = path.resolve(process.cwd(), options.output);
115
+ fs.writeFileSync(outputPath, sdl);
116
+ yield* effect_1.Console.log(`Schema written to ${outputPath}`);
117
+ }
118
+ else {
119
+ yield* effect_1.Console.log(sdl);
120
+ }
121
+ });
122
+ /**
123
+ * Watch mode - regenerate on file changes
124
+ */
125
+ const watch = (options) => effect_1.Effect.gen(function* () {
126
+ const absolutePath = path.resolve(process.cwd(), options.modulePath);
127
+ const dir = path.dirname(absolutePath);
128
+ yield* effect_1.Console.log(`Watching for changes in ${dir}...`);
129
+ // Initial generation
130
+ yield* run(options).pipe(effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`)));
131
+ // Watch for changes
132
+ yield* effect_1.Effect.async(() => {
133
+ const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {
134
+ if (filename?.endsWith(".ts") || filename?.endsWith(".js")) {
135
+ effect_1.Effect.runPromise(run(options).pipe(effect_1.Effect.tap(() => effect_1.Console.log(`\nRegenerated at ${new Date().toLocaleTimeString()}`)), effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`))));
136
+ }
137
+ });
138
+ return effect_1.Effect.sync(() => watcher.close());
139
+ });
140
+ });
141
+ /**
142
+ * Parse CLI arguments for generate-schema command
143
+ */
144
+ const parseArgs = (args) => {
145
+ const positional = [];
146
+ let output;
147
+ let sort = true;
148
+ let watchMode = false;
149
+ for (let i = 0; i < args.length; i++) {
150
+ const arg = args[i];
151
+ if (arg === "-h" || arg === "--help") {
152
+ return { help: true };
153
+ }
154
+ else if (arg === "-o" || arg === "--output") {
155
+ output = args[++i];
156
+ }
157
+ else if (arg === "--no-sort") {
158
+ sort = false;
159
+ }
160
+ else if (arg === "-w" || arg === "--watch") {
161
+ watchMode = true;
162
+ }
163
+ else if (!arg.startsWith("-")) {
164
+ positional.push(arg);
165
+ }
166
+ else {
167
+ return { error: `Unknown option: ${arg}` };
168
+ }
169
+ }
170
+ if (positional.length === 0) {
171
+ return { error: "Missing module path" };
172
+ }
173
+ return {
174
+ modulePath: positional[0],
175
+ output,
176
+ sort,
177
+ watch: watchMode,
178
+ };
179
+ };
180
+ const printGenerateSchemaHelp = () => {
181
+ console.log(`
182
+ Usage: effect-gql generate-schema <module-path> [options]
183
+
184
+ Generate GraphQL SDL from an effect-gql schema builder.
185
+
186
+ Arguments:
187
+ module-path Path to the schema module (.ts or .js)
188
+
189
+ Options:
190
+ -o, --output Write SDL to file instead of stdout
191
+ --no-sort Don't sort schema alphabetically
192
+ -w, --watch Watch for changes and regenerate
193
+ -h, --help Show this help message
194
+
195
+ Examples:
196
+ effect-gql generate-schema ./src/schema.ts
197
+ effect-gql generate-schema ./src/schema.ts -o schema.graphql
198
+ effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql
199
+
200
+ The module should export one of:
201
+ - builder: A GraphQLSchemaBuilder instance
202
+ - schema: A GraphQLSchema instance
203
+ - default: Either of the above as default export
204
+ `);
205
+ };
206
+ exports.printGenerateSchemaHelp = printGenerateSchemaHelp;
207
+ /**
208
+ * Entry point for the generate-schema command
209
+ */
210
+ const runGenerateSchema = (args) => effect_1.Effect.gen(function* () {
211
+ const parsed = parseArgs(args);
212
+ if ("help" in parsed) {
213
+ (0, exports.printGenerateSchemaHelp)();
214
+ return;
215
+ }
216
+ if ("error" in parsed) {
217
+ yield* effect_1.Console.error(`Error: ${parsed.error}`);
218
+ (0, exports.printGenerateSchemaHelp)();
219
+ process.exitCode = 1;
220
+ return;
221
+ }
222
+ if (parsed.watch) {
223
+ yield* watch(parsed);
224
+ }
225
+ else {
226
+ yield* run(parsed);
227
+ }
228
+ });
229
+ exports.runGenerateSchema = runGenerateSchema;
230
+ //# sourceMappingURL=generate-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-schema.js","sourceRoot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ACrB,IAAA,+BAAuB,GAAE,CAAA;QACzB,OAAM;IACR,CAAC;IAED,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,KAAK,CAAC,CAAC,gBAAO,CAAC,KAAK,CAAC,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QAC9C,IAAA,+BAAuB,GAAE,CAAA;QACzB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAM;IACR,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,CAAC;AACH,CAAC,CAAC,CAAA;AArBS,QAAA,iBAAiB,qBAqB1B"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @effect-gql/cli - CLI tools for Effect GraphQL development
3
+ *
4
+ * @example CLI usage
5
+ * ```bash
6
+ * # Generate SDL from schema
7
+ * effect-gql generate-schema ./src/schema.ts
8
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql
9
+ *
10
+ * # Watch mode
11
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql --watch
12
+ * ```
13
+ *
14
+ * @example Programmatic usage
15
+ * ```typescript
16
+ * import { generateSDL, generateSDLFromModule } from "@effect-gql/cli"
17
+ * import { Effect } from "effect"
18
+ *
19
+ * // From a schema directly
20
+ * const sdl = generateSDL(builder.buildSchema())
21
+ *
22
+ * // From a module path
23
+ * const sdl = await Effect.runPromise(
24
+ * generateSDLFromModule("./src/schema.ts")
25
+ * )
26
+ * ```
27
+ */
28
+ export { generateSDL, generateSDLFromModule, loadSchema, } from "./commands/generate-schema";
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,UAAU,GACX,MAAM,4BAA4B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * @effect-gql/cli - CLI tools for Effect GraphQL development
4
+ *
5
+ * @example CLI usage
6
+ * ```bash
7
+ * # Generate SDL from schema
8
+ * effect-gql generate-schema ./src/schema.ts
9
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql
10
+ *
11
+ * # Watch mode
12
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql --watch
13
+ * ```
14
+ *
15
+ * @example Programmatic usage
16
+ * ```typescript
17
+ * import { generateSDL, generateSDLFromModule } from "@effect-gql/cli"
18
+ * import { Effect } from "effect"
19
+ *
20
+ * // From a schema directly
21
+ * const sdl = generateSDL(builder.buildSchema())
22
+ *
23
+ * // From a module path
24
+ * const sdl = await Effect.runPromise(
25
+ * generateSDLFromModule("./src/schema.ts")
26
+ * )
27
+ * ```
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.loadSchema = exports.generateSDLFromModule = exports.generateSDL = void 0;
31
+ var generate_schema_1 = require("./commands/generate-schema");
32
+ Object.defineProperty(exports, "generateSDL", { enumerable: true, get: function () { return generate_schema_1.generateSDL; } });
33
+ Object.defineProperty(exports, "generateSDLFromModule", { enumerable: true, get: function () { return generate_schema_1.generateSDLFromModule; } });
34
+ Object.defineProperty(exports, "loadSchema", { enumerable: true, get: function () { return generate_schema_1.loadSchema; } });
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,8DAImC;AAHjC,8GAAA,WAAW,OAAA;AACX,wHAAA,qBAAqB,OAAA;AACrB,6GAAA,UAAU,OAAA"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@effect-gql/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI tools for Effect GraphQL development",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "effect-gql": "./dist/bin.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "peerDependencies": {
21
+ "@effect-gql/core": "^0.1.0",
22
+ "effect": "^3.19.0",
23
+ "graphql": "^16.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@effect-gql/core": "*",
27
+ "effect": "^3.19.13",
28
+ "graphql": "^16.0.0"
29
+ },
30
+ "keywords": [
31
+ "effect",
32
+ "graphql",
33
+ "cli",
34
+ "schema",
35
+ "codegen"
36
+ ],
37
+ "license": "MIT",
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "dev": "tsc --watch",
41
+ "clean": "rm -rf dist",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest"
44
+ }
45
+ }
package/src/bin.ts ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Effect GraphQL CLI
4
+ *
5
+ * Usage:
6
+ * effect-gql <command> [options]
7
+ *
8
+ * Commands:
9
+ * generate-schema Generate GraphQL SDL from a schema module
10
+ * create Create a new Effect GraphQL project (coming soon)
11
+ */
12
+
13
+ import { Effect, Console } from "effect"
14
+ import { runGenerateSchema } from "./commands/generate-schema"
15
+
16
+ const VERSION = "0.1.0"
17
+
18
+ const printHelp = (): void => {
19
+ console.log(`
20
+ Effect GraphQL CLI v${VERSION}
21
+
22
+ Usage: effect-gql <command> [options]
23
+
24
+ Commands:
25
+ generate-schema Generate GraphQL SDL from a schema module
26
+ create Create a new Effect GraphQL project (coming soon)
27
+
28
+ Options:
29
+ -h, --help Show this help message
30
+ -v, --version Show version number
31
+
32
+ Examples:
33
+ effect-gql generate-schema ./src/schema.ts
34
+ effect-gql generate-schema ./src/schema.ts -o schema.graphql
35
+ effect-gql create my-app
36
+
37
+ Run 'effect-gql <command> --help' for command-specific help.
38
+ `)
39
+ }
40
+
41
+ const printVersion = (): void => {
42
+ console.log(`effect-gql v${VERSION}`)
43
+ }
44
+
45
+ const main = Effect.gen(function* () {
46
+ const args = process.argv.slice(2)
47
+
48
+ if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
49
+ printHelp()
50
+ return
51
+ }
52
+
53
+ if (args[0] === "-v" || args[0] === "--version") {
54
+ printVersion()
55
+ return
56
+ }
57
+
58
+ const command = args[0]
59
+ const commandArgs = args.slice(1)
60
+
61
+ switch (command) {
62
+ case "generate-schema":
63
+ yield* runGenerateSchema(commandArgs)
64
+ break
65
+
66
+ case "create":
67
+ yield* Console.log("The 'create' command is coming soon!")
68
+ yield* Console.log("It will help you scaffold new Effect GraphQL projects.")
69
+ break
70
+
71
+ default:
72
+ yield* Console.error(`Unknown command: ${command}`)
73
+ printHelp()
74
+ process.exitCode = 1
75
+ }
76
+ })
77
+
78
+ Effect.runPromise(
79
+ main.pipe(
80
+ Effect.catchAll((error) =>
81
+ Console.error(`Error: ${error.message}`).pipe(
82
+ Effect.andThen(
83
+ Effect.sync(() => {
84
+ process.exitCode = 1
85
+ })
86
+ )
87
+ )
88
+ )
89
+ )
90
+ )
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Generate GraphQL SDL from an effect-gql schema builder.
3
+ *
4
+ * Usage:
5
+ * effect-gql generate-schema <module-path> [options]
6
+ *
7
+ * The module should export one of:
8
+ * - `builder` - A GraphQLSchemaBuilder instance
9
+ * - `schema` - A GraphQLSchema instance
10
+ * - `default` - Either of the above as default export
11
+ */
12
+
13
+ import { Effect, Console } from "effect"
14
+ import { printSchema, lexicographicSortSchema } from "@effect-gql/core"
15
+ import type { GraphQLSchema } from "graphql"
16
+ import * as fs from "fs"
17
+ import * as path from "path"
18
+
19
+ interface GenerateOptions {
20
+ /** Path to the schema module */
21
+ modulePath: string
22
+ /** Output file path (stdout if not specified) */
23
+ output?: string
24
+ /** Sort schema alphabetically */
25
+ sort?: boolean
26
+ /** Watch for changes */
27
+ watch?: boolean
28
+ }
29
+
30
+ /**
31
+ * Load a schema from a module path.
32
+ * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
33
+ */
34
+ export const loadSchema = (modulePath: string): Effect.Effect<GraphQLSchema, Error> =>
35
+ Effect.gen(function* () {
36
+ const absolutePath = path.resolve(process.cwd(), modulePath)
37
+
38
+ // Validate file exists
39
+ if (!fs.existsSync(absolutePath)) {
40
+ return yield* Effect.fail(new Error(`File not found: ${absolutePath}`))
41
+ }
42
+
43
+ // Dynamic import (works with both ESM and CJS via tsx/ts-node)
44
+ const module = yield* Effect.tryPromise({
45
+ try: async () => {
46
+ // Clear require cache for watch mode
47
+ const resolved = require.resolve(absolutePath)
48
+ delete require.cache[resolved]
49
+
50
+ // Try dynamic import first (ESM), fall back to require (CJS)
51
+ try {
52
+ return await import(absolutePath)
53
+ } catch {
54
+ return require(absolutePath)
55
+ }
56
+ },
57
+ catch: (error) => new Error(`Failed to load module: ${error}`),
58
+ })
59
+
60
+ // Look for builder or schema export
61
+ const exported = module.builder ?? module.schema ?? module.default
62
+
63
+ if (!exported) {
64
+ return yield* Effect.fail(
65
+ new Error(
66
+ `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`
67
+ )
68
+ )
69
+ }
70
+
71
+ // If it's a builder, call buildSchema()
72
+ if (typeof exported.buildSchema === "function") {
73
+ return exported.buildSchema() as GraphQLSchema
74
+ }
75
+
76
+ // If it's already a GraphQLSchema
77
+ if (exported.getQueryType && exported.getTypeMap) {
78
+ return exported as GraphQLSchema
79
+ }
80
+
81
+ return yield* Effect.fail(
82
+ new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)
83
+ )
84
+ })
85
+
86
+ /**
87
+ * Generate SDL from a schema
88
+ */
89
+ export const generateSDL = (schema: GraphQLSchema, options: { sort?: boolean } = {}): string => {
90
+ const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema
91
+ return printSchema(finalSchema)
92
+ }
93
+
94
+ /**
95
+ * Generate SDL from a module path
96
+ */
97
+ export const generateSDLFromModule = (
98
+ modulePath: string,
99
+ options: { sort?: boolean } = {}
100
+ ): Effect.Effect<string, Error> =>
101
+ loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)))
102
+
103
+ /**
104
+ * Run the generate-schema command
105
+ */
106
+ const run = (options: GenerateOptions): Effect.Effect<void, Error> =>
107
+ Effect.gen(function* () {
108
+ const schema = yield* loadSchema(options.modulePath)
109
+ const sdl = generateSDL(schema, { sort: options.sort })
110
+
111
+ if (options.output) {
112
+ const outputPath = path.resolve(process.cwd(), options.output)
113
+ fs.writeFileSync(outputPath, sdl)
114
+ yield* Console.log(`Schema written to ${outputPath}`)
115
+ } else {
116
+ yield* Console.log(sdl)
117
+ }
118
+ })
119
+
120
+ /**
121
+ * Watch mode - regenerate on file changes
122
+ */
123
+ const watch = (options: GenerateOptions): Effect.Effect<void, Error> =>
124
+ Effect.gen(function* () {
125
+ const absolutePath = path.resolve(process.cwd(), options.modulePath)
126
+ const dir = path.dirname(absolutePath)
127
+
128
+ yield* Console.log(`Watching for changes in ${dir}...`)
129
+
130
+ // Initial generation
131
+ yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)))
132
+
133
+ // Watch for changes
134
+ yield* Effect.async<void, Error>(() => {
135
+ const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {
136
+ if (filename?.endsWith(".ts") || filename?.endsWith(".js")) {
137
+ Effect.runPromise(
138
+ run(options).pipe(
139
+ Effect.tap(() => Console.log(`\nRegenerated at ${new Date().toLocaleTimeString()}`)),
140
+ Effect.catchAll((error) => Console.error(`Error: ${error.message}`))
141
+ )
142
+ )
143
+ }
144
+ })
145
+
146
+ return Effect.sync(() => watcher.close())
147
+ })
148
+ })
149
+
150
+ /**
151
+ * Parse CLI arguments for generate-schema command
152
+ */
153
+ const parseArgs = (args: string[]): GenerateOptions | { help: true } | { error: string } => {
154
+ const positional: string[] = []
155
+ let output: string | undefined
156
+ let sort = true
157
+ let watchMode = false
158
+
159
+ for (let i = 0; i < args.length; i++) {
160
+ const arg = args[i]
161
+
162
+ if (arg === "-h" || arg === "--help") {
163
+ return { help: true }
164
+ } else if (arg === "-o" || arg === "--output") {
165
+ output = args[++i]
166
+ } else if (arg === "--no-sort") {
167
+ sort = false
168
+ } else if (arg === "-w" || arg === "--watch") {
169
+ watchMode = true
170
+ } else if (!arg.startsWith("-")) {
171
+ positional.push(arg)
172
+ } else {
173
+ return { error: `Unknown option: ${arg}` }
174
+ }
175
+ }
176
+
177
+ if (positional.length === 0) {
178
+ return { error: "Missing module path" }
179
+ }
180
+
181
+ return {
182
+ modulePath: positional[0],
183
+ output,
184
+ sort,
185
+ watch: watchMode,
186
+ }
187
+ }
188
+
189
+ export const printGenerateSchemaHelp = (): void => {
190
+ console.log(`
191
+ Usage: effect-gql generate-schema <module-path> [options]
192
+
193
+ Generate GraphQL SDL from an effect-gql schema builder.
194
+
195
+ Arguments:
196
+ module-path Path to the schema module (.ts or .js)
197
+
198
+ Options:
199
+ -o, --output Write SDL to file instead of stdout
200
+ --no-sort Don't sort schema alphabetically
201
+ -w, --watch Watch for changes and regenerate
202
+ -h, --help Show this help message
203
+
204
+ Examples:
205
+ effect-gql generate-schema ./src/schema.ts
206
+ effect-gql generate-schema ./src/schema.ts -o schema.graphql
207
+ effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql
208
+
209
+ The module should export one of:
210
+ - builder: A GraphQLSchemaBuilder instance
211
+ - schema: A GraphQLSchema instance
212
+ - default: Either of the above as default export
213
+ `)
214
+ }
215
+
216
+ /**
217
+ * Entry point for the generate-schema command
218
+ */
219
+ export const runGenerateSchema = (args: string[]): Effect.Effect<void, Error> =>
220
+ Effect.gen(function* () {
221
+ const parsed = parseArgs(args)
222
+
223
+ if ("help" in parsed) {
224
+ printGenerateSchemaHelp()
225
+ return
226
+ }
227
+
228
+ if ("error" in parsed) {
229
+ yield* Console.error(`Error: ${parsed.error}`)
230
+ printGenerateSchemaHelp()
231
+ process.exitCode = 1
232
+ return
233
+ }
234
+
235
+ if (parsed.watch) {
236
+ yield* watch(parsed)
237
+ } else {
238
+ yield* run(parsed)
239
+ }
240
+ })
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @effect-gql/cli - CLI tools for Effect GraphQL development
3
+ *
4
+ * @example CLI usage
5
+ * ```bash
6
+ * # Generate SDL from schema
7
+ * effect-gql generate-schema ./src/schema.ts
8
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql
9
+ *
10
+ * # Watch mode
11
+ * effect-gql generate-schema ./src/schema.ts -o schema.graphql --watch
12
+ * ```
13
+ *
14
+ * @example Programmatic usage
15
+ * ```typescript
16
+ * import { generateSDL, generateSDLFromModule } from "@effect-gql/cli"
17
+ * import { Effect } from "effect"
18
+ *
19
+ * // From a schema directly
20
+ * const sdl = generateSDL(builder.buildSchema())
21
+ *
22
+ * // From a module path
23
+ * const sdl = await Effect.runPromise(
24
+ * generateSDLFromModule("./src/schema.ts")
25
+ * )
26
+ * ```
27
+ */
28
+
29
+ export { generateSDL, generateSDLFromModule, loadSchema } from "./commands/generate-schema"