@effect-gql/cli 0.1.0 → 1.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/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/dist/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/src/bin.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
)
|
|
@@ -1,240 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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"
|