@effect-gql/cli 0.1.0 → 1.0.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/README.md +100 -0
- package/bin.cjs +249 -0
- package/bin.cjs.map +1 -0
- package/bin.d.cts +1 -0
- package/bin.d.ts +1 -0
- package/bin.js +226 -0
- package/bin.js.map +1 -0
- package/index.cjs +80 -0
- package/index.cjs.map +1 -0
- package/{dist/commands/generate-schema.d.ts → index.d.cts} +9 -11
- package/index.d.ts +34 -0
- package/index.js +55 -0
- package/index.js.map +1 -0
- package/package.json +15 -25
- package/dist/bin.d.ts +0 -13
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -69
- package/dist/bin.js.map +0 -1
- package/dist/commands/generate-schema.d.ts.map +0 -1
- package/dist/commands/generate-schema.js +0 -230
- package/dist/commands/generate-schema.js.map +0 -1
- package/dist/index.d.ts +0 -29
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -35
- package/dist/index.js.map +0 -1
- package/src/bin.ts +0 -90
- package/src/commands/generate-schema.ts +0 -240
- package/src/index.ts +0 -29
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Effect GraphQL
|
|
2
|
+
|
|
3
|
+
A GraphQL framework for Effect-TS that brings full type safety, composability, and functional programming to your GraphQL servers.
|
|
4
|
+
|
|
5
|
+
> **Note:** This is an experimental prototype exploring the integration between Effect Schema, Effect's service system, and GraphQL.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Type-Safe End-to-End** - Define schemas once with Effect Schema, get TypeScript types and GraphQL types automatically
|
|
10
|
+
- **Effect-Powered Resolvers** - Resolvers are Effect programs with built-in error handling and service injection
|
|
11
|
+
- **Immutable Builder** - Fluent, pipe-able API for composing schemas from reusable parts
|
|
12
|
+
- **Service Integration** - Use Effect's Layer system for dependency injection
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @effect-gql/core effect graphql
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Effect, Layer } from "effect"
|
|
24
|
+
import * as S from "effect/Schema"
|
|
25
|
+
import { GraphQLSchemaBuilder, execute } from "@effect-gql/core"
|
|
26
|
+
|
|
27
|
+
// Define your schema with Effect Schema
|
|
28
|
+
const UserSchema = S.Struct({
|
|
29
|
+
id: S.String,
|
|
30
|
+
name: S.String,
|
|
31
|
+
email: S.String,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Build your GraphQL schema
|
|
35
|
+
const schema = GraphQLSchemaBuilder.empty
|
|
36
|
+
.objectType({ name: "User", schema: UserSchema })
|
|
37
|
+
.query("users", {
|
|
38
|
+
type: S.Array(UserSchema),
|
|
39
|
+
resolve: () => Effect.succeed([
|
|
40
|
+
{ id: "1", name: "Alice", email: "alice@example.com" },
|
|
41
|
+
{ id: "2", name: "Bob", email: "bob@example.com" },
|
|
42
|
+
]),
|
|
43
|
+
})
|
|
44
|
+
.query("user", {
|
|
45
|
+
type: UserSchema,
|
|
46
|
+
args: S.Struct({ id: S.String }),
|
|
47
|
+
resolve: (args) => Effect.succeed({
|
|
48
|
+
id: args.id,
|
|
49
|
+
name: "Alice",
|
|
50
|
+
email: "alice@example.com",
|
|
51
|
+
}),
|
|
52
|
+
})
|
|
53
|
+
.buildSchema()
|
|
54
|
+
|
|
55
|
+
// Execute a query
|
|
56
|
+
const result = await Effect.runPromise(
|
|
57
|
+
execute(schema, Layer.empty)(`
|
|
58
|
+
query {
|
|
59
|
+
users { id name email }
|
|
60
|
+
}
|
|
61
|
+
`)
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
For full documentation, guides, and API reference, visit the [documentation site](https://nrf110.github.io/effect-gql/).
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Install dependencies
|
|
73
|
+
npm install
|
|
74
|
+
|
|
75
|
+
# Build the project
|
|
76
|
+
npm run build
|
|
77
|
+
|
|
78
|
+
# Run tests
|
|
79
|
+
npm test
|
|
80
|
+
|
|
81
|
+
# Development mode with watch
|
|
82
|
+
npm run dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
Contributions are welcome! Here's how you can help:
|
|
88
|
+
|
|
89
|
+
1. **Report bugs** - Open an issue describing the problem and steps to reproduce
|
|
90
|
+
2. **Suggest features** - Open an issue describing your idea
|
|
91
|
+
3. **Submit PRs** - Fork the repo, make your changes, and open a pull request
|
|
92
|
+
|
|
93
|
+
Please ensure your code:
|
|
94
|
+
- Passes all existing tests (`npm test`)
|
|
95
|
+
- Includes tests for new functionality
|
|
96
|
+
- Follows the existing code style
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
package/bin.cjs
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var effect = require('effect');
|
|
5
|
+
var core = require('@effect-gql/core');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
28
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
29
|
+
|
|
30
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
31
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
32
|
+
}) : x)(function(x) {
|
|
33
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
34
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
35
|
+
});
|
|
36
|
+
var loadSchema = (modulePath) => effect.Effect.gen(function* () {
|
|
37
|
+
const absolutePath = path__namespace.resolve(process.cwd(), modulePath);
|
|
38
|
+
if (!fs__namespace.existsSync(absolutePath)) {
|
|
39
|
+
return yield* effect.Effect.fail(new Error(`File not found: ${absolutePath}`));
|
|
40
|
+
}
|
|
41
|
+
const module = yield* effect.Effect.tryPromise({
|
|
42
|
+
try: async () => {
|
|
43
|
+
const resolved = __require.resolve(absolutePath);
|
|
44
|
+
delete __require.cache[resolved];
|
|
45
|
+
try {
|
|
46
|
+
return await import(absolutePath);
|
|
47
|
+
} catch {
|
|
48
|
+
return __require(absolutePath);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
catch: (error) => new Error(`Failed to load module: ${error}`)
|
|
52
|
+
});
|
|
53
|
+
const exported = module.builder ?? module.schema ?? module.default;
|
|
54
|
+
if (!exported) {
|
|
55
|
+
return yield* effect.Effect.fail(
|
|
56
|
+
new Error(
|
|
57
|
+
`Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (typeof exported.buildSchema === "function") {
|
|
62
|
+
return exported.buildSchema();
|
|
63
|
+
}
|
|
64
|
+
if (exported.getQueryType && exported.getTypeMap) {
|
|
65
|
+
return exported;
|
|
66
|
+
}
|
|
67
|
+
return yield* effect.Effect.fail(
|
|
68
|
+
new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
var generateSDL = (schema, options = {}) => {
|
|
72
|
+
const finalSchema = options.sort !== false ? core.lexicographicSortSchema(schema) : schema;
|
|
73
|
+
return core.printSchema(finalSchema);
|
|
74
|
+
};
|
|
75
|
+
var run = (options) => effect.Effect.gen(function* () {
|
|
76
|
+
const schema = yield* loadSchema(options.modulePath);
|
|
77
|
+
const sdl = generateSDL(schema, { sort: options.sort });
|
|
78
|
+
if (options.output) {
|
|
79
|
+
const outputPath = path__namespace.resolve(process.cwd(), options.output);
|
|
80
|
+
fs__namespace.writeFileSync(outputPath, sdl);
|
|
81
|
+
yield* effect.Console.log(`Schema written to ${outputPath}`);
|
|
82
|
+
} else {
|
|
83
|
+
yield* effect.Console.log(sdl);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
var watch2 = (options) => effect.Effect.gen(function* () {
|
|
87
|
+
const absolutePath = path__namespace.resolve(process.cwd(), options.modulePath);
|
|
88
|
+
const dir = path__namespace.dirname(absolutePath);
|
|
89
|
+
yield* effect.Console.log(`Watching for changes in ${dir}...`);
|
|
90
|
+
yield* run(options).pipe(effect.Effect.catchAll((error) => effect.Console.error(`Error: ${error.message}`)));
|
|
91
|
+
yield* effect.Effect.async(() => {
|
|
92
|
+
const watcher = fs__namespace.watch(dir, { recursive: true }, (_, filename) => {
|
|
93
|
+
if (filename?.endsWith(".ts") || filename?.endsWith(".js")) {
|
|
94
|
+
effect.Effect.runPromise(
|
|
95
|
+
run(options).pipe(
|
|
96
|
+
effect.Effect.tap(() => effect.Console.log(`
|
|
97
|
+
Regenerated at ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`)),
|
|
98
|
+
effect.Effect.catchAll((error) => effect.Console.error(`Error: ${error.message}`))
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return effect.Effect.sync(() => watcher.close());
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
var parseArgs = (args) => {
|
|
107
|
+
const positional = [];
|
|
108
|
+
let output;
|
|
109
|
+
let sort = true;
|
|
110
|
+
let watchMode = false;
|
|
111
|
+
for (let i = 0; i < args.length; i++) {
|
|
112
|
+
const arg = args[i];
|
|
113
|
+
if (arg === "-h" || arg === "--help") {
|
|
114
|
+
return { help: true };
|
|
115
|
+
} else if (arg === "-o" || arg === "--output") {
|
|
116
|
+
output = args[++i];
|
|
117
|
+
} else if (arg === "--no-sort") {
|
|
118
|
+
sort = false;
|
|
119
|
+
} else if (arg === "-w" || arg === "--watch") {
|
|
120
|
+
watchMode = true;
|
|
121
|
+
} else if (!arg.startsWith("-")) {
|
|
122
|
+
positional.push(arg);
|
|
123
|
+
} else {
|
|
124
|
+
return { error: `Unknown option: ${arg}` };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (positional.length === 0) {
|
|
128
|
+
return { error: "Missing module path" };
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
modulePath: positional[0],
|
|
132
|
+
output,
|
|
133
|
+
sort,
|
|
134
|
+
watch: watchMode
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
var printGenerateSchemaHelp = () => {
|
|
138
|
+
console.log(`
|
|
139
|
+
Usage: effect-gql generate-schema <module-path> [options]
|
|
140
|
+
|
|
141
|
+
Generate GraphQL SDL from an effect-gql schema builder.
|
|
142
|
+
|
|
143
|
+
Arguments:
|
|
144
|
+
module-path Path to the schema module (.ts or .js)
|
|
145
|
+
|
|
146
|
+
Options:
|
|
147
|
+
-o, --output Write SDL to file instead of stdout
|
|
148
|
+
--no-sort Don't sort schema alphabetically
|
|
149
|
+
-w, --watch Watch for changes and regenerate
|
|
150
|
+
-h, --help Show this help message
|
|
151
|
+
|
|
152
|
+
Examples:
|
|
153
|
+
effect-gql generate-schema ./src/schema.ts
|
|
154
|
+
effect-gql generate-schema ./src/schema.ts -o schema.graphql
|
|
155
|
+
effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql
|
|
156
|
+
|
|
157
|
+
The module should export one of:
|
|
158
|
+
- builder: A GraphQLSchemaBuilder instance
|
|
159
|
+
- schema: A GraphQLSchema instance
|
|
160
|
+
- default: Either of the above as default export
|
|
161
|
+
`);
|
|
162
|
+
};
|
|
163
|
+
var runGenerateSchema = (args) => effect.Effect.gen(function* () {
|
|
164
|
+
const parsed = parseArgs(args);
|
|
165
|
+
if ("help" in parsed) {
|
|
166
|
+
printGenerateSchemaHelp();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if ("error" in parsed) {
|
|
170
|
+
yield* effect.Console.error(`Error: ${parsed.error}`);
|
|
171
|
+
printGenerateSchemaHelp();
|
|
172
|
+
process.exitCode = 1;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (parsed.watch) {
|
|
176
|
+
yield* watch2(parsed);
|
|
177
|
+
} else {
|
|
178
|
+
yield* run(parsed);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// src/bin.ts
|
|
183
|
+
var VERSION = "0.1.0";
|
|
184
|
+
var printHelp = () => {
|
|
185
|
+
console.log(`
|
|
186
|
+
Effect GraphQL CLI v${VERSION}
|
|
187
|
+
|
|
188
|
+
Usage: effect-gql <command> [options]
|
|
189
|
+
|
|
190
|
+
Commands:
|
|
191
|
+
generate-schema Generate GraphQL SDL from a schema module
|
|
192
|
+
create Create a new Effect GraphQL project (coming soon)
|
|
193
|
+
|
|
194
|
+
Options:
|
|
195
|
+
-h, --help Show this help message
|
|
196
|
+
-v, --version Show version number
|
|
197
|
+
|
|
198
|
+
Examples:
|
|
199
|
+
effect-gql generate-schema ./src/schema.ts
|
|
200
|
+
effect-gql generate-schema ./src/schema.ts -o schema.graphql
|
|
201
|
+
effect-gql create my-app
|
|
202
|
+
|
|
203
|
+
Run 'effect-gql <command> --help' for command-specific help.
|
|
204
|
+
`);
|
|
205
|
+
};
|
|
206
|
+
var printVersion = () => {
|
|
207
|
+
console.log(`effect-gql v${VERSION}`);
|
|
208
|
+
};
|
|
209
|
+
var main = effect.Effect.gen(function* () {
|
|
210
|
+
const args = process.argv.slice(2);
|
|
211
|
+
if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
|
|
212
|
+
printHelp();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (args[0] === "-v" || args[0] === "--version") {
|
|
216
|
+
printVersion();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const command = args[0];
|
|
220
|
+
const commandArgs = args.slice(1);
|
|
221
|
+
switch (command) {
|
|
222
|
+
case "generate-schema":
|
|
223
|
+
yield* runGenerateSchema(commandArgs);
|
|
224
|
+
break;
|
|
225
|
+
case "create":
|
|
226
|
+
yield* effect.Console.log("The 'create' command is coming soon!");
|
|
227
|
+
yield* effect.Console.log("It will help you scaffold new Effect GraphQL projects.");
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
yield* effect.Console.error(`Unknown command: ${command}`);
|
|
231
|
+
printHelp();
|
|
232
|
+
process.exitCode = 1;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
effect.Effect.runPromise(
|
|
236
|
+
main.pipe(
|
|
237
|
+
effect.Effect.catchAll(
|
|
238
|
+
(error) => effect.Console.error(`Error: ${error.message}`).pipe(
|
|
239
|
+
effect.Effect.andThen(
|
|
240
|
+
effect.Effect.sync(() => {
|
|
241
|
+
process.exitCode = 1;
|
|
242
|
+
})
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
//# sourceMappingURL=bin.cjs.map
|
|
249
|
+
//# sourceMappingURL=bin.cjs.map
|
package/bin.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/generate-schema.ts","../src/bin.ts"],"names":["Effect","path","fs","lexicographicSortSchema","printSchema","Console","watch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,UAAA,GAAa,CAAC,UAAA,KACzBA,aAAA,CAAO,IAAI,aAAa;AACtB,EAAA,MAAM,YAAA,GAAoBC,eAAA,CAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,IAAO,UAAU,CAAA;AAG3D,EAAA,IAAI,CAAIC,aAAA,CAAA,UAAA,CAAW,YAAY,CAAA,EAAG;AAChC,IAAA,OAAO,OAAOF,cAAO,IAAA,CAAK,IAAI,MAAM,CAAA,gBAAA,EAAmB,YAAY,EAAE,CAAC,CAAA;AAAA,EACxE;AAGA,EAAA,MAAM,MAAA,GAAS,OAAOA,aAAA,CAAO,UAAA,CAAW;AAAA,IACtC,KAAK,YAAY;AAEf,MAAA,MAAM,QAAA,GAAW,SAAA,CAAQ,OAAA,CAAQ,YAAY,CAAA;AAC7C,MAAA,OAAO,SAAA,CAAQ,MAAM,QAAQ,CAAA;AAG7B,MAAA,IAAI;AACF,QAAA,OAAO,MAAM,OAAO,YAAA,CAAA;AAAA,MACtB,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,UAAQ,YAAY,CAAA;AAAA,MAC7B;AAAA,IACF,CAAA;AAAA,IACA,OAAO,CAAC,KAAA,KAAU,IAAI,KAAA,CAAM,CAAA,uBAAA,EAA0B,KAAK,CAAA,CAAE;AAAA,GAC9D,CAAA;AAGD,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,OAAA,IAAW,MAAA,CAAO,UAAU,MAAA,CAAO,OAAA;AAE3D,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,OAAOA,aAAA,CAAO,IAAA;AAAA,MACnB,IAAI,KAAA;AAAA,QACF,CAAA,kGAAA;AAAA;AACF,KACF;AAAA,EACF;AAGA,EAAA,IAAI,OAAO,QAAA,CAAS,WAAA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AACH;AACF;AACF;AAEJ,CAAA","file":"bin.cjs","sourcesContent":["/**\n * Generate GraphQL SDL from an effect-gql schema builder.\n *\n * Usage:\n * effect-gql generate-schema <module-path> [options]\n *\n * The module should export one of:\n * - `builder` - A GraphQLSchemaBuilder instance\n * - `schema` - A GraphQLSchema instance\n * - `default` - Either of the above as default export\n */\n\nimport { Effect, Console } from \"effect\"\nimport { printSchema, lexicographicSortSchema } from \"@effect-gql/core\"\nimport type { GraphQLSchema } from \"graphql\"\nimport * as fs from \"fs\"\nimport * as path from \"path\"\n\ninterface GenerateOptions {\n /** Path to the schema module */\n modulePath: string\n /** Output file path (stdout if not specified) */\n output?: string\n /** Sort schema alphabetically */\n sort?: boolean\n /** Watch for changes */\n watch?: boolean\n}\n\n/**\n * Load a schema from a module path.\n * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.\n */\nexport const loadSchema = (modulePath: string): Effect.Effect<GraphQLSchema, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), modulePath)\n\n // Validate file exists\n if (!fs.existsSync(absolutePath)) {\n return yield* Effect.fail(new Error(`File not found: ${absolutePath}`))\n }\n\n // Dynamic import (works with both ESM and CJS via tsx/ts-node)\n const module = yield* Effect.tryPromise({\n try: async () => {\n // Clear require cache for watch mode\n const resolved = require.resolve(absolutePath)\n delete require.cache[resolved]\n\n // Try dynamic import first (ESM), fall back to require (CJS)\n try {\n return await import(absolutePath)\n } catch {\n return require(absolutePath)\n }\n },\n catch: (error) => new Error(`Failed to load module: ${error}`),\n })\n\n // Look for builder or schema export\n const exported = module.builder ?? module.schema ?? module.default\n\n if (!exported) {\n return yield* Effect.fail(\n new Error(\n `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`\n )\n )\n }\n\n // If it's a builder, call buildSchema()\n if (typeof exported.buildSchema === \"function\") {\n return exported.buildSchema() as GraphQLSchema\n }\n\n // If it's already a GraphQLSchema\n if (exported.getQueryType && exported.getTypeMap) {\n return exported as GraphQLSchema\n }\n\n return yield* Effect.fail(\n new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)\n )\n })\n\n/**\n * Generate SDL from a schema\n */\nexport const generateSDL = (schema: GraphQLSchema, options: { sort?: boolean } = {}): string => {\n const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema\n return printSchema(finalSchema)\n}\n\n/**\n * Generate SDL from a module path\n */\nexport const generateSDLFromModule = (\n modulePath: string,\n options: { sort?: boolean } = {}\n): Effect.Effect<string, Error> =>\n loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)))\n\n/**\n * Run the generate-schema command\n */\nconst run = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const schema = yield* loadSchema(options.modulePath)\n const sdl = generateSDL(schema, { sort: options.sort })\n\n if (options.output) {\n const outputPath = path.resolve(process.cwd(), options.output)\n fs.writeFileSync(outputPath, sdl)\n yield* Console.log(`Schema written to ${outputPath}`)\n } else {\n yield* Console.log(sdl)\n }\n })\n\n/**\n * Watch mode - regenerate on file changes\n */\nconst watch = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), options.modulePath)\n const dir = path.dirname(absolutePath)\n\n yield* Console.log(`Watching for changes in ${dir}...`)\n\n // Initial generation\n yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)))\n\n // Watch for changes\n yield* Effect.async<void, Error>(() => {\n const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {\n if (filename?.endsWith(\".ts\") || filename?.endsWith(\".js\")) {\n Effect.runPromise(\n run(options).pipe(\n Effect.tap(() => Console.log(`\\nRegenerated at ${new Date().toLocaleTimeString()}`)),\n Effect.catchAll((error) => Console.error(`Error: ${error.message}`))\n )\n )\n }\n })\n\n return Effect.sync(() => watcher.close())\n })\n })\n\n/**\n * Parse CLI arguments for generate-schema command\n */\nconst parseArgs = (args: string[]): GenerateOptions | { help: true } | { error: string } => {\n const positional: string[] = []\n let output: string | undefined\n let sort = true\n let watchMode = false\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n\n if (arg === \"-h\" || arg === \"--help\") {\n return { help: true }\n } else if (arg === \"-o\" || arg === \"--output\") {\n output = args[++i]\n } else if (arg === \"--no-sort\") {\n sort = false\n } else if (arg === \"-w\" || arg === \"--watch\") {\n watchMode = true\n } else if (!arg.startsWith(\"-\")) {\n positional.push(arg)\n } else {\n return { error: `Unknown option: ${arg}` }\n }\n }\n\n if (positional.length === 0) {\n return { error: \"Missing module path\" }\n }\n\n return {\n modulePath: positional[0],\n output,\n sort,\n watch: watchMode,\n }\n}\n\nexport const printGenerateSchemaHelp = (): void => {\n console.log(`\nUsage: effect-gql generate-schema <module-path> [options]\n\nGenerate GraphQL SDL from an effect-gql schema builder.\n\nArguments:\n module-path Path to the schema module (.ts or .js)\n\nOptions:\n -o, --output Write SDL to file instead of stdout\n --no-sort Don't sort schema alphabetically\n -w, --watch Watch for changes and regenerate\n -h, --help Show this help message\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql\n\nThe module should export one of:\n - builder: A GraphQLSchemaBuilder instance\n - schema: A GraphQLSchema instance\n - default: Either of the above as default export\n`)\n}\n\n/**\n * Entry point for the generate-schema command\n */\nexport const runGenerateSchema = (args: string[]): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const parsed = parseArgs(args)\n\n if (\"help\" in parsed) {\n printGenerateSchemaHelp()\n return\n }\n\n if (\"error\" in parsed) {\n yield* Console.error(`Error: ${parsed.error}`)\n printGenerateSchemaHelp()\n process.exitCode = 1\n return\n }\n\n if (parsed.watch) {\n yield* watch(parsed)\n } else {\n yield* run(parsed)\n }\n })\n","#!/usr/bin/env node\n/**\n * Effect GraphQL CLI\n *\n * Usage:\n * effect-gql <command> [options]\n *\n * Commands:\n * generate-schema Generate GraphQL SDL from a schema module\n * create Create a new Effect GraphQL project (coming soon)\n */\n\nimport { Effect, Console } from \"effect\"\nimport { runGenerateSchema } from \"./commands/generate-schema\"\n\nconst VERSION = \"0.1.0\"\n\nconst printHelp = (): void => {\n console.log(`\nEffect GraphQL CLI v${VERSION}\n\nUsage: effect-gql <command> [options]\n\nCommands:\n generate-schema Generate GraphQL SDL from a schema module\n create Create a new Effect GraphQL project (coming soon)\n\nOptions:\n -h, --help Show this help message\n -v, --version Show version number\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql create my-app\n\nRun 'effect-gql <command> --help' for command-specific help.\n`)\n}\n\nconst printVersion = (): void => {\n console.log(`effect-gql v${VERSION}`)\n}\n\nconst main = Effect.gen(function* () {\n const args = process.argv.slice(2)\n\n if (args.length === 0 || args[0] === \"-h\" || args[0] === \"--help\") {\n printHelp()\n return\n }\n\n if (args[0] === \"-v\" || args[0] === \"--version\") {\n printVersion()\n return\n }\n\n const command = args[0]\n const commandArgs = args.slice(1)\n\n switch (command) {\n case \"generate-schema\":\n yield* runGenerateSchema(commandArgs)\n break\n\n case \"create\":\n yield* Console.log(\"The 'create' command is coming soon!\")\n yield* Console.log(\"It will help you scaffold new Effect GraphQL projects.\")\n break\n\n default:\n yield* Console.error(`Unknown command: ${command}`)\n printHelp()\n process.exitCode = 1\n }\n})\n\nEffect.runPromise(\n main.pipe(\n Effect.catchAll((error) =>\n Console.error(`Error: ${error.message}`).pipe(\n Effect.andThen(\n Effect.sync(() => {\n process.exitCode = 1\n })\n )\n )\n )\n )\n)\n"]}
|
package/bin.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/bin.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Effect, Console } from 'effect';
|
|
3
|
+
import { lexicographicSortSchema, printSchema } from '@effect-gql/core';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var loadSchema = (modulePath) => Effect.gen(function* () {
|
|
14
|
+
const absolutePath = path.resolve(process.cwd(), modulePath);
|
|
15
|
+
if (!fs.existsSync(absolutePath)) {
|
|
16
|
+
return yield* Effect.fail(new Error(`File not found: ${absolutePath}`));
|
|
17
|
+
}
|
|
18
|
+
const module = yield* Effect.tryPromise({
|
|
19
|
+
try: async () => {
|
|
20
|
+
const resolved = __require.resolve(absolutePath);
|
|
21
|
+
delete __require.cache[resolved];
|
|
22
|
+
try {
|
|
23
|
+
return await import(absolutePath);
|
|
24
|
+
} catch {
|
|
25
|
+
return __require(absolutePath);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
catch: (error) => new Error(`Failed to load module: ${error}`)
|
|
29
|
+
});
|
|
30
|
+
const exported = module.builder ?? module.schema ?? module.default;
|
|
31
|
+
if (!exported) {
|
|
32
|
+
return yield* Effect.fail(
|
|
33
|
+
new Error(
|
|
34
|
+
`Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (typeof exported.buildSchema === "function") {
|
|
39
|
+
return exported.buildSchema();
|
|
40
|
+
}
|
|
41
|
+
if (exported.getQueryType && exported.getTypeMap) {
|
|
42
|
+
return exported;
|
|
43
|
+
}
|
|
44
|
+
return yield* Effect.fail(
|
|
45
|
+
new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
var generateSDL = (schema, options = {}) => {
|
|
49
|
+
const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema;
|
|
50
|
+
return printSchema(finalSchema);
|
|
51
|
+
};
|
|
52
|
+
var run = (options) => Effect.gen(function* () {
|
|
53
|
+
const schema = yield* loadSchema(options.modulePath);
|
|
54
|
+
const sdl = generateSDL(schema, { sort: options.sort });
|
|
55
|
+
if (options.output) {
|
|
56
|
+
const outputPath = path.resolve(process.cwd(), options.output);
|
|
57
|
+
fs.writeFileSync(outputPath, sdl);
|
|
58
|
+
yield* Console.log(`Schema written to ${outputPath}`);
|
|
59
|
+
} else {
|
|
60
|
+
yield* Console.log(sdl);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var watch2 = (options) => Effect.gen(function* () {
|
|
64
|
+
const absolutePath = path.resolve(process.cwd(), options.modulePath);
|
|
65
|
+
const dir = path.dirname(absolutePath);
|
|
66
|
+
yield* Console.log(`Watching for changes in ${dir}...`);
|
|
67
|
+
yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)));
|
|
68
|
+
yield* Effect.async(() => {
|
|
69
|
+
const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {
|
|
70
|
+
if (filename?.endsWith(".ts") || filename?.endsWith(".js")) {
|
|
71
|
+
Effect.runPromise(
|
|
72
|
+
run(options).pipe(
|
|
73
|
+
Effect.tap(() => Console.log(`
|
|
74
|
+
Regenerated at ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`)),
|
|
75
|
+
Effect.catchAll((error) => Console.error(`Error: ${error.message}`))
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return Effect.sync(() => watcher.close());
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var parseArgs = (args) => {
|
|
84
|
+
const positional = [];
|
|
85
|
+
let output;
|
|
86
|
+
let sort = true;
|
|
87
|
+
let watchMode = false;
|
|
88
|
+
for (let i = 0; i < args.length; i++) {
|
|
89
|
+
const arg = args[i];
|
|
90
|
+
if (arg === "-h" || arg === "--help") {
|
|
91
|
+
return { help: true };
|
|
92
|
+
} else if (arg === "-o" || arg === "--output") {
|
|
93
|
+
output = args[++i];
|
|
94
|
+
} else if (arg === "--no-sort") {
|
|
95
|
+
sort = false;
|
|
96
|
+
} else if (arg === "-w" || arg === "--watch") {
|
|
97
|
+
watchMode = true;
|
|
98
|
+
} else if (!arg.startsWith("-")) {
|
|
99
|
+
positional.push(arg);
|
|
100
|
+
} else {
|
|
101
|
+
return { error: `Unknown option: ${arg}` };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (positional.length === 0) {
|
|
105
|
+
return { error: "Missing module path" };
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
modulePath: positional[0],
|
|
109
|
+
output,
|
|
110
|
+
sort,
|
|
111
|
+
watch: watchMode
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
var printGenerateSchemaHelp = () => {
|
|
115
|
+
console.log(`
|
|
116
|
+
Usage: effect-gql generate-schema <module-path> [options]
|
|
117
|
+
|
|
118
|
+
Generate GraphQL SDL from an effect-gql schema builder.
|
|
119
|
+
|
|
120
|
+
Arguments:
|
|
121
|
+
module-path Path to the schema module (.ts or .js)
|
|
122
|
+
|
|
123
|
+
Options:
|
|
124
|
+
-o, --output Write SDL to file instead of stdout
|
|
125
|
+
--no-sort Don't sort schema alphabetically
|
|
126
|
+
-w, --watch Watch for changes and regenerate
|
|
127
|
+
-h, --help Show this help message
|
|
128
|
+
|
|
129
|
+
Examples:
|
|
130
|
+
effect-gql generate-schema ./src/schema.ts
|
|
131
|
+
effect-gql generate-schema ./src/schema.ts -o schema.graphql
|
|
132
|
+
effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql
|
|
133
|
+
|
|
134
|
+
The module should export one of:
|
|
135
|
+
- builder: A GraphQLSchemaBuilder instance
|
|
136
|
+
- schema: A GraphQLSchema instance
|
|
137
|
+
- default: Either of the above as default export
|
|
138
|
+
`);
|
|
139
|
+
};
|
|
140
|
+
var runGenerateSchema = (args) => Effect.gen(function* () {
|
|
141
|
+
const parsed = parseArgs(args);
|
|
142
|
+
if ("help" in parsed) {
|
|
143
|
+
printGenerateSchemaHelp();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if ("error" in parsed) {
|
|
147
|
+
yield* Console.error(`Error: ${parsed.error}`);
|
|
148
|
+
printGenerateSchemaHelp();
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (parsed.watch) {
|
|
153
|
+
yield* watch2(parsed);
|
|
154
|
+
} else {
|
|
155
|
+
yield* run(parsed);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// src/bin.ts
|
|
160
|
+
var VERSION = "0.1.0";
|
|
161
|
+
var printHelp = () => {
|
|
162
|
+
console.log(`
|
|
163
|
+
Effect GraphQL CLI v${VERSION}
|
|
164
|
+
|
|
165
|
+
Usage: effect-gql <command> [options]
|
|
166
|
+
|
|
167
|
+
Commands:
|
|
168
|
+
generate-schema Generate GraphQL SDL from a schema module
|
|
169
|
+
create Create a new Effect GraphQL project (coming soon)
|
|
170
|
+
|
|
171
|
+
Options:
|
|
172
|
+
-h, --help Show this help message
|
|
173
|
+
-v, --version Show version number
|
|
174
|
+
|
|
175
|
+
Examples:
|
|
176
|
+
effect-gql generate-schema ./src/schema.ts
|
|
177
|
+
effect-gql generate-schema ./src/schema.ts -o schema.graphql
|
|
178
|
+
effect-gql create my-app
|
|
179
|
+
|
|
180
|
+
Run 'effect-gql <command> --help' for command-specific help.
|
|
181
|
+
`);
|
|
182
|
+
};
|
|
183
|
+
var printVersion = () => {
|
|
184
|
+
console.log(`effect-gql v${VERSION}`);
|
|
185
|
+
};
|
|
186
|
+
var main = Effect.gen(function* () {
|
|
187
|
+
const args = process.argv.slice(2);
|
|
188
|
+
if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
|
|
189
|
+
printHelp();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (args[0] === "-v" || args[0] === "--version") {
|
|
193
|
+
printVersion();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const command = args[0];
|
|
197
|
+
const commandArgs = args.slice(1);
|
|
198
|
+
switch (command) {
|
|
199
|
+
case "generate-schema":
|
|
200
|
+
yield* runGenerateSchema(commandArgs);
|
|
201
|
+
break;
|
|
202
|
+
case "create":
|
|
203
|
+
yield* Console.log("The 'create' command is coming soon!");
|
|
204
|
+
yield* Console.log("It will help you scaffold new Effect GraphQL projects.");
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
yield* Console.error(`Unknown command: ${command}`);
|
|
208
|
+
printHelp();
|
|
209
|
+
process.exitCode = 1;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
Effect.runPromise(
|
|
213
|
+
main.pipe(
|
|
214
|
+
Effect.catchAll(
|
|
215
|
+
(error) => Console.error(`Error: ${error.message}`).pipe(
|
|
216
|
+
Effect.andThen(
|
|
217
|
+
Effect.sync(() => {
|
|
218
|
+
process.exitCode = 1;
|
|
219
|
+
})
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
//# sourceMappingURL=bin.js.map
|
|
226
|
+
//# sourceMappingURL=bin.js.map
|
package/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/generate-schema.ts","../src/bin.ts"],"names":["watch","Effect","Console"],"mappings":";;;;;;;;;;;;AAiCO,IAAM,UAAA,GAAa,CAAC,UAAA,KACzB,MAAA,CAAO,IAAI,aAAa;AACtB,EAAA,MAAM,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AC,CAAA,KAAM,QAAQ,IAAA,CAAK,CAAC,MAAM,WAAA,EAAa;AAC/C,IAAA,YAAA,EAAa;AACb,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,OAAA,GAAU,KAAK,CAAC,CAAA;AACtB,EAAA,MAAM,WAAA,GAAc,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA;AAEhC,EAAA,QAAQ,OAAA;AAAS,IACf,KAAK,iBAAA;AACH,MAAA,OAAO,kBAAkB,WAAW,CAAA;AACpC,MAAA;AAAA,IAEF,KAAK,QAAA;AACH,MAAA,OAAOC,OAAAA,CAAQ,IAAI,sCAAsC,CAAA;AACzD,MAAA,OAAOA,OAAAA,CAAQ,IAAI,wDAAwD,CAAA;AAC3E,MAAA;AAAA,IAEF;AACE,MAAA,OAAOA,OAAAA,CAAQ,KAAA,CAAM,CAAA,iBAAA,EAAoB,OAAO,CAAA,CAAE,CAAA;AAClD,MAAA,SAAA,EAAU;AACV,MAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AAAA;AAEzB,CAAC,CAAA;AAEDD,MAAAA,CAAO,UAAA;AAAA,EACL,IAAA,CAAK,IAAA;AAAA,IACHA,MAAAA,CAAO,QAAA;AAAA,MAAS,CAAC,UACfC,OAAAA,CAAQ,KAAA,CAAM,UAAU,KAAA,CAAM,OAAO,EAAE,CAAA,CAAE,IAAA;AAAA,QACvCD,MAAAA,CAAO,OAAA;AAAA,UACLA,MAAAA,CAAO,KAAK,MAAM;AAChB,YAAA,OAAA,CAAQ,QAAA,GAAW,CAAA;AAAA,UACrB,CAAC;AAAA;AACH;AACF;AACF;AAEJ,CAAA","file":"bin.js","sourcesContent":["/**\n * Generate GraphQL SDL from an effect-gql schema builder.\n *\n * Usage:\n * effect-gql generate-schema <module-path> [options]\n *\n * The module should export one of:\n * - `builder` - A GraphQLSchemaBuilder instance\n * - `schema` - A GraphQLSchema instance\n * - `default` - Either of the above as default export\n */\n\nimport { Effect, Console } from \"effect\"\nimport { printSchema, lexicographicSortSchema } from \"@effect-gql/core\"\nimport type { GraphQLSchema } from \"graphql\"\nimport * as fs from \"fs\"\nimport * as path from \"path\"\n\ninterface GenerateOptions {\n /** Path to the schema module */\n modulePath: string\n /** Output file path (stdout if not specified) */\n output?: string\n /** Sort schema alphabetically */\n sort?: boolean\n /** Watch for changes */\n watch?: boolean\n}\n\n/**\n * Load a schema from a module path.\n * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.\n */\nexport const loadSchema = (modulePath: string): Effect.Effect<GraphQLSchema, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), modulePath)\n\n // Validate file exists\n if (!fs.existsSync(absolutePath)) {\n return yield* Effect.fail(new Error(`File not found: ${absolutePath}`))\n }\n\n // Dynamic import (works with both ESM and CJS via tsx/ts-node)\n const module = yield* Effect.tryPromise({\n try: async () => {\n // Clear require cache for watch mode\n const resolved = require.resolve(absolutePath)\n delete require.cache[resolved]\n\n // Try dynamic import first (ESM), fall back to require (CJS)\n try {\n return await import(absolutePath)\n } catch {\n return require(absolutePath)\n }\n },\n catch: (error) => new Error(`Failed to load module: ${error}`),\n })\n\n // Look for builder or schema export\n const exported = module.builder ?? module.schema ?? module.default\n\n if (!exported) {\n return yield* Effect.fail(\n new Error(\n `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`\n )\n )\n }\n\n // If it's a builder, call buildSchema()\n if (typeof exported.buildSchema === \"function\") {\n return exported.buildSchema() as GraphQLSchema\n }\n\n // If it's already a GraphQLSchema\n if (exported.getQueryType && exported.getTypeMap) {\n return exported as GraphQLSchema\n }\n\n return yield* Effect.fail(\n new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)\n )\n })\n\n/**\n * Generate SDL from a schema\n */\nexport const generateSDL = (schema: GraphQLSchema, options: { sort?: boolean } = {}): string => {\n const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema\n return printSchema(finalSchema)\n}\n\n/**\n * Generate SDL from a module path\n */\nexport const generateSDLFromModule = (\n modulePath: string,\n options: { sort?: boolean } = {}\n): Effect.Effect<string, Error> =>\n loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)))\n\n/**\n * Run the generate-schema command\n */\nconst run = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const schema = yield* loadSchema(options.modulePath)\n const sdl = generateSDL(schema, { sort: options.sort })\n\n if (options.output) {\n const outputPath = path.resolve(process.cwd(), options.output)\n fs.writeFileSync(outputPath, sdl)\n yield* Console.log(`Schema written to ${outputPath}`)\n } else {\n yield* Console.log(sdl)\n }\n })\n\n/**\n * Watch mode - regenerate on file changes\n */\nconst watch = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), options.modulePath)\n const dir = path.dirname(absolutePath)\n\n yield* Console.log(`Watching for changes in ${dir}...`)\n\n // Initial generation\n yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)))\n\n // Watch for changes\n yield* Effect.async<void, Error>(() => {\n const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {\n if (filename?.endsWith(\".ts\") || filename?.endsWith(\".js\")) {\n Effect.runPromise(\n run(options).pipe(\n Effect.tap(() => Console.log(`\\nRegenerated at ${new Date().toLocaleTimeString()}`)),\n Effect.catchAll((error) => Console.error(`Error: ${error.message}`))\n )\n )\n }\n })\n\n return Effect.sync(() => watcher.close())\n })\n })\n\n/**\n * Parse CLI arguments for generate-schema command\n */\nconst parseArgs = (args: string[]): GenerateOptions | { help: true } | { error: string } => {\n const positional: string[] = []\n let output: string | undefined\n let sort = true\n let watchMode = false\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n\n if (arg === \"-h\" || arg === \"--help\") {\n return { help: true }\n } else if (arg === \"-o\" || arg === \"--output\") {\n output = args[++i]\n } else if (arg === \"--no-sort\") {\n sort = false\n } else if (arg === \"-w\" || arg === \"--watch\") {\n watchMode = true\n } else if (!arg.startsWith(\"-\")) {\n positional.push(arg)\n } else {\n return { error: `Unknown option: ${arg}` }\n }\n }\n\n if (positional.length === 0) {\n return { error: \"Missing module path\" }\n }\n\n return {\n modulePath: positional[0],\n output,\n sort,\n watch: watchMode,\n }\n}\n\nexport const printGenerateSchemaHelp = (): void => {\n console.log(`\nUsage: effect-gql generate-schema <module-path> [options]\n\nGenerate GraphQL SDL from an effect-gql schema builder.\n\nArguments:\n module-path Path to the schema module (.ts or .js)\n\nOptions:\n -o, --output Write SDL to file instead of stdout\n --no-sort Don't sort schema alphabetically\n -w, --watch Watch for changes and regenerate\n -h, --help Show this help message\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql\n\nThe module should export one of:\n - builder: A GraphQLSchemaBuilder instance\n - schema: A GraphQLSchema instance\n - default: Either of the above as default export\n`)\n}\n\n/**\n * Entry point for the generate-schema command\n */\nexport const runGenerateSchema = (args: string[]): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const parsed = parseArgs(args)\n\n if (\"help\" in parsed) {\n printGenerateSchemaHelp()\n return\n }\n\n if (\"error\" in parsed) {\n yield* Console.error(`Error: ${parsed.error}`)\n printGenerateSchemaHelp()\n process.exitCode = 1\n return\n }\n\n if (parsed.watch) {\n yield* watch(parsed)\n } else {\n yield* run(parsed)\n }\n })\n","#!/usr/bin/env node\n/**\n * Effect GraphQL CLI\n *\n * Usage:\n * effect-gql <command> [options]\n *\n * Commands:\n * generate-schema Generate GraphQL SDL from a schema module\n * create Create a new Effect GraphQL project (coming soon)\n */\n\nimport { Effect, Console } from \"effect\"\nimport { runGenerateSchema } from \"./commands/generate-schema\"\n\nconst VERSION = \"0.1.0\"\n\nconst printHelp = (): void => {\n console.log(`\nEffect GraphQL CLI v${VERSION}\n\nUsage: effect-gql <command> [options]\n\nCommands:\n generate-schema Generate GraphQL SDL from a schema module\n create Create a new Effect GraphQL project (coming soon)\n\nOptions:\n -h, --help Show this help message\n -v, --version Show version number\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql create my-app\n\nRun 'effect-gql <command> --help' for command-specific help.\n`)\n}\n\nconst printVersion = (): void => {\n console.log(`effect-gql v${VERSION}`)\n}\n\nconst main = Effect.gen(function* () {\n const args = process.argv.slice(2)\n\n if (args.length === 0 || args[0] === \"-h\" || args[0] === \"--help\") {\n printHelp()\n return\n }\n\n if (args[0] === \"-v\" || args[0] === \"--version\") {\n printVersion()\n return\n }\n\n const command = args[0]\n const commandArgs = args.slice(1)\n\n switch (command) {\n case \"generate-schema\":\n yield* runGenerateSchema(commandArgs)\n break\n\n case \"create\":\n yield* Console.log(\"The 'create' command is coming soon!\")\n yield* Console.log(\"It will help you scaffold new Effect GraphQL projects.\")\n break\n\n default:\n yield* Console.error(`Unknown command: ${command}`)\n printHelp()\n process.exitCode = 1\n }\n})\n\nEffect.runPromise(\n main.pipe(\n Effect.catchAll((error) =>\n Console.error(`Error: ${error.message}`).pipe(\n Effect.andThen(\n Effect.sync(() => {\n process.exitCode = 1\n })\n )\n )\n )\n )\n)\n"]}
|