Skip to content

Commit 64bdd46

Browse files
authored
feat: add yes option for router cli and fix ts demo plugin example (#2367)
1 parent 53e16d6 commit 64bdd46

File tree

14 files changed

+450
-1826
lines changed

14 files changed

+450
-1826
lines changed

.github/workflows/router-ci.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ jobs:
4949
- name: Install tools
5050
run: make setup-build-tools
5151

52+
- uses: ./.github/actions/node
53+
54+
- name: Install Cli Node Dependencies
55+
run: |
56+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic install --frozen-lockfile
57+
pnpm buf generate --template buf.ts.gen.yaml
58+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic run build
59+
5260
- name: Install Bun For Plugin Building
5361
uses: oven-sh/setup-bun@v2
5462
with:
@@ -132,6 +140,14 @@ jobs:
132140
- name: Install tools
133141
run: make setup-build-tools
134142

143+
- uses: ./.github/actions/node
144+
145+
- name: Install Cli Node Dependencies
146+
run: |
147+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic install --frozen-lockfile
148+
pnpm buf generate --template buf.ts.gen.yaml
149+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic run build
150+
135151
- name: Install Bun For Plugin Building
136152
uses: oven-sh/setup-bun@v2
137153
with:
@@ -307,9 +323,18 @@ jobs:
307323
with:
308324
cache-dependency-path: |
309325
router-tests/go.sum
326+
310327
- name: Install tools
311328
run: make setup-build-tools
312329

330+
- uses: ./.github/actions/node
331+
332+
- name: Install Cli Node Dependencies
333+
run: |
334+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic install --frozen-lockfile
335+
pnpm buf generate --template buf.ts.gen.yaml
336+
pnpm --filter ./cli --filter ./connect --filter ./shared --filter ./composition --filter ./protographic run build
337+
313338
- name: Install Bun For Plugin Building
314339
uses: oven-sh/setup-bun@v2
315340
with:

cli/src/commands/router/commands/plugin/commands/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,23 @@ export default (opts: BaseCommandOptions) => {
3333
[],
3434
);
3535
command.option('--all-platforms', 'Build for all supported platforms', false);
36+
3637
command.option('--skip-tools-installation', 'Skip tool installation', false);
3738
command.option(
3839
'--force-tools-installation',
3940
'Force tools installation regardless of version check or confirmation',
4041
false,
4142
);
43+
command.option('-y, --yes', 'Automatically answer yes to all prompts', false);
44+
4245
command.option('--go-module-path <path>', 'Go module path to use for the plugin');
4346

4447
command.action(async (directory, options) => {
4548
const startTime = performance.now();
4649
const pluginDir = resolve(directory);
4750
const spinner = Spinner();
4851
const pluginName = path.basename(pluginDir);
52+
const autoConfirmPrompts: boolean = options.yes;
4953

5054
const language = getLanguage(pluginDir);
5155
if (!language) {
@@ -61,7 +65,7 @@ export default (opts: BaseCommandOptions) => {
6165
try {
6266
// Check and install tools if needed
6367
if (!options.skipToolsInstallation) {
64-
await checkAndInstallTools(options.forceToolsInstallation, language);
68+
await checkAndInstallTools(options.forceToolsInstallation, language, autoConfirmPrompts);
6569
}
6670

6771
// Start the main build process

cli/src/commands/router/commands/plugin/commands/generate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ export default (opts: BaseCommandOptions) => {
2828
false,
2929
);
3030
command.option('--go-module-path <path>', 'Go module path to use for the plugin');
31+
command.option('-y, --yes', 'Automatically answer yes to all prompts', false);
3132

3233
command.action(async (directory, options) => {
3334
const startTime = performance.now();
3435
const pluginDir = resolve(directory);
3536
const spinner = Spinner();
3637
const pluginName = path.basename(pluginDir);
38+
const autoConfirmPrompts: boolean = options.yes;
3739

3840
const language = getLanguage(pluginDir);
3941
if (!language) {
@@ -48,7 +50,7 @@ export default (opts: BaseCommandOptions) => {
4850
try {
4951
// Check and install tools if needed
5052
if (!options.skipToolsInstallation) {
51-
await checkAndInstallTools(options.forceToolsInstallation, language);
53+
await checkAndInstallTools(options.forceToolsInstallation, language, autoConfirmPrompts);
5254
}
5355

5456
// Start the generation process

cli/src/commands/router/commands/plugin/commands/test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ export default (opts: BaseCommandOptions) => {
2424
'Force tools installation regardless of version check or confirmation',
2525
false,
2626
);
27+
command.option('-y, --yes', 'Automatically answer yes to all prompts', false);
2728

2829
command.action(async (directory, options) => {
2930
const startTime = performance.now();
3031
const pluginDir = resolve(directory);
3132
const spinner = Spinner({ text: 'Running tests...' });
3233
const pluginName = path.basename(pluginDir);
34+
const autoConfirmPrompts: boolean = options.yes;
3335

3436
const language = getLanguage(pluginDir);
3537
if (!language) {
@@ -42,7 +44,7 @@ export default (opts: BaseCommandOptions) => {
4244
try {
4345
// Check and install tools if needed
4446
if (!options.skipToolsInstallation) {
45-
await checkAndInstallTools(options.forceToolsInstallation, language);
47+
await checkAndInstallTools(options.forceToolsInstallation, language, autoConfirmPrompts);
4648
}
4749

4850
spinner.start();

cli/src/commands/router/commands/plugin/toolchain.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -354,22 +354,22 @@ export function validateAndGetGoModulePath(language: string, goModulePath: strin
354354
/**
355355
* Check if tools need installation and ask the user if needed
356356
*/
357-
export async function checkAndInstallTools(force = false, language: string): Promise<boolean> {
357+
export async function checkAndInstallTools(
358+
force = false,
359+
language: string,
360+
autoConfirmPrompts: boolean,
361+
): Promise<boolean> {
358362
const [needsReinstall, shouldCleanup] = await shouldReinstallTools(force, language);
359363

360364
if (!needsReinstall) {
361365
return true;
362366
}
363367

364-
// Ask user for confirmation to install tools
365-
const installMessage = existsSync(TOOLS_DIR)
366-
? 'Version changes detected. Install required toolchain?'
367-
: 'Install required toolchain?';
368-
369368
const toolVersionsForLanguage = LanguageSpecificTools[language];
370369

371370
// Create a more informative message with simple formatting
372371
const toolsInfo = Object.entries(toolVersionsForLanguage)
372+
.filter(([tool]) => shouldCleanup || !Object.keys(COMMON_TOOL_VERSIONS).includes(tool))
373373
.map(([tool, { range: version }]) => ` ${pc.cyan('•')} ${pc.bold(tool)}: ${version}`)
374374
.join('\n');
375375

@@ -379,22 +379,35 @@ export async function checkAndInstallTools(force = false, language: string): Pro
379379
pc.white('The following tools are needed to build the router plugin:') +
380380
'\n\n' +
381381
toolsInfo +
382-
'\n\n' +
383-
pc.white('You can install them automatically or manually install them yourself') +
384-
'\n' +
385-
pc.white('by following the documentation at https://cosmo-docs.wundergraph.com') +
386-
'\n',
382+
'\n\n',
387383
);
388384

389-
const response = await prompts({
390-
type: 'confirm',
391-
name: 'installTools',
392-
message: installMessage,
393-
});
385+
// In case of auto-confirm, skip the prompt
386+
if (autoConfirmPrompts) {
387+
console.log(pc.white('These tools will now be automatically installed') + '\n');
388+
} else {
389+
console.log(
390+
pc.white('You can install them automatically or manually install them yourself') +
391+
'\n' +
392+
pc.white('by following the documentation at https://cosmo-docs.wundergraph.com') +
393+
'\n',
394+
);
395+
396+
// Ask user for confirmation to install tools
397+
const installMessage = existsSync(TOOLS_DIR)
398+
? 'Version changes detected. Install required toolchain?'
399+
: 'Install required toolchain?';
400+
401+
const response = await prompts({
402+
type: 'confirm',
403+
name: 'installTools',
404+
message: installMessage,
405+
});
394406

395-
if (!response.installTools) {
396-
console.log(pc.yellow('Tools installation skipped. Build may fail.'));
397-
return false;
407+
if (!response.installTools) {
408+
console.log(pc.yellow('Tools installation skipped. Build may fail.'));
409+
return false;
410+
}
398411
}
399412

400413
try {

demo/Makefile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SHELL := bash
2-
wgc_router = pnpx tsx --env-file ../cli/.env ../cli/src/index.ts router
2+
wgc_router = pnpm dlx tsx --env-file ../cli/.env ../cli/src/index.ts router
3+
wgc_router_ci = pnpm dlx tsx ../cli/src/index.ts router
34

45
generate:
56
go generate ./...
@@ -10,7 +11,7 @@ compose-integration:
1011
bump-deps:
1112
./bump-deps.sh
1213

13-
.PHONY: plugin-build plugin-generate plugin-build-bun-binary plugin-build-go-binary plugin-build-integration
14+
.PHONY: plugin-build plugin-generate plugin-build-ci-bun-binary plugin-build-ci-go-binary plugin-build-integration
1415

1516
plugin-build:
1617
$(wgc_router) plugin build ./pkg/subgraphs/projects --debug --go-module-path github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects
@@ -20,14 +21,11 @@ plugin-generate:
2021
$(wgc_router) plugin build ./pkg/subgraphs/projects --generate-only --go-module-path github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects
2122
$(wgc_router) plugin build ./pkg/subgraphs/courses --generate-only
2223

23-
plugin-build-bun-binary:
24-
cd pkg/subgraphs/courses/ && \
25-
bun install && bun build src/plugin.ts --compile --outfile bin/$(shell go env GOOS)_$(shell go env GOARCH) && \
26-
mkdir -p bin/grpc-health-check && \
27-
cp -r node_modules/grpc-health-check/proto bin/grpc-health-check
24+
plugin-build-ci-bun-binary:
25+
$(wgc_router_ci) plugin build ./pkg/subgraphs/courses --yes
2826

29-
plugin-build-go-binary:
30-
cd pkg/subgraphs/projects/ && go build -o ./bin/$(shell go env GOOS)_$(shell go env GOARCH) ./src
27+
plugin-build-ci-go-binary:
28+
$(wgc_router_ci) plugin build ./pkg/subgraphs/projects --yes
3129

3230
plugin-compose:
3331
$(wgc_router) compose -i ./graph-with-plugin.yaml -o ./configWithPlugins.json
@@ -39,7 +37,7 @@ plugin-build-integration: plugin-build plugin-compose
3937
cp -a pkg/subgraphs/courses ../router/plugins/
4038
mv configWithPlugins.json ../router-tests/testenv/testdata/configWithPlugins.json
4139

42-
plugin-build-ci: plugin-build-go-binary plugin-build-bun-binary
40+
plugin-build-ci: plugin-build-ci-go-binary plugin-build-ci-bun-binary
4341
rm -rf ../router/plugins/*
4442
mkdir -p ../router/plugins/projects/bin
4543
mkdir -p ../router/plugins/courses/bin

demo/pkg/subgraphs/courses/generated/mapping.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,6 @@
5353
}
5454
],
5555
"entityMappings": [
56-
{
57-
"typeName": "Course",
58-
"kind": "entity",
59-
"key": "id",
60-
"rpc": "LookupCourseById",
61-
"request": "LookupCourseByIdRequest",
62-
"response": "LookupCourseByIdResponse"
63-
},
64-
{
65-
"typeName": "Lesson",
66-
"kind": "entity",
67-
"key": "id",
68-
"rpc": "LookupLessonById",
69-
"request": "LookupLessonByIdRequest",
70-
"response": "LookupLessonByIdResponse"
71-
},
7256
{
7357
"typeName": "Employee",
7458
"kind": "entity",

demo/pkg/subgraphs/courses/generated/service.proto

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import "google/protobuf/wrappers.proto";
55

66
// Service definition for CoursesService
77
service CoursesService {
8-
// Lookup Course entity by id
9-
rpc LookupCourseById(LookupCourseByIdRequest) returns (LookupCourseByIdResponse) {}
108
// Lookup Employee entity by id
119
rpc LookupEmployeeById(LookupEmployeeByIdRequest) returns (LookupEmployeeByIdResponse) {}
12-
// Lookup Lesson entity by id
13-
rpc LookupLessonById(LookupLessonByIdRequest) returns (LookupLessonByIdResponse) {}
1410
rpc MutationAddCourse(MutationAddCourseRequest) returns (MutationAddCourseResponse) {}
1511
rpc MutationAddLesson(MutationAddLessonRequest) returns (MutationAddLessonResponse) {}
1612
rpc QueryCourse(QueryCourseRequest) returns (QueryCourseResponse) {}
@@ -20,74 +16,6 @@ service CoursesService {
2016
rpc QueryThrowErrorCourses(QueryThrowErrorCoursesRequest) returns (QueryThrowErrorCoursesResponse) {}
2117
}
2218

23-
// Key message for Course entity lookup
24-
message LookupCourseByIdRequestKey {
25-
// Key field for Course entity lookup.
26-
string id = 1;
27-
}
28-
29-
// Request message for Course entity lookup.
30-
message LookupCourseByIdRequest {
31-
/*
32-
* List of keys to look up Course entities.
33-
* Order matters - each key maps to one entity in LookupCourseByIdResponse.
34-
*/
35-
repeated LookupCourseByIdRequestKey keys = 1;
36-
}
37-
38-
// Response message for Course entity lookup.
39-
message LookupCourseByIdResponse {
40-
/*
41-
* List of Course entities in the same order as the keys in LookupCourseByIdRequest.
42-
* Always return the same number of entities as keys. Use null for entities that cannot be found.
43-
*
44-
* Example:
45-
* LookupUserByIdRequest:
46-
* keys:
47-
* - id: 1
48-
* - id: 2
49-
* LookupUserByIdResponse:
50-
* result:
51-
* - id: 1 # User with id 1 found
52-
* - null # User with id 2 not found
53-
*/
54-
repeated Course result = 1;
55-
}
56-
57-
// Key message for Lesson entity lookup
58-
message LookupLessonByIdRequestKey {
59-
// Key field for Lesson entity lookup.
60-
string id = 1;
61-
}
62-
63-
// Request message for Lesson entity lookup.
64-
message LookupLessonByIdRequest {
65-
/*
66-
* List of keys to look up Lesson entities.
67-
* Order matters - each key maps to one entity in LookupLessonByIdResponse.
68-
*/
69-
repeated LookupLessonByIdRequestKey keys = 1;
70-
}
71-
72-
// Response message for Lesson entity lookup.
73-
message LookupLessonByIdResponse {
74-
/*
75-
* List of Lesson entities in the same order as the keys in LookupLessonByIdRequest.
76-
* Always return the same number of entities as keys. Use null for entities that cannot be found.
77-
*
78-
* Example:
79-
* LookupUserByIdRequest:
80-
* keys:
81-
* - id: 1
82-
* - id: 2
83-
* LookupUserByIdResponse:
84-
* result:
85-
* - id: 1 # User with id 1 found
86-
* - null # User with id 2 not found
87-
*/
88-
repeated Lesson result = 1;
89-
}
90-
9119
// Key message for Employee entity lookup
9220
message LookupEmployeeByIdRequestKey {
9321
// Key field for Employee entity lookup.
@@ -179,6 +107,11 @@ message MutationAddLessonResponse {
179107
Lesson add_lesson = 1;
180108
}
181109

110+
message Employee {
111+
int32 id = 1;
112+
repeated Course taught_courses = 2;
113+
}
114+
182115
message Course {
183116
string id = 1;
184117
string title = 2;
@@ -194,9 +127,4 @@ message Lesson {
194127
google.protobuf.StringValue description = 4;
195128
int32 order = 5;
196129
Course course = 6;
197-
}
198-
199-
message Employee {
200-
int32 id = 1;
201-
repeated Course taught_courses = 2;
202130
}

0 commit comments

Comments
 (0)