@vyriy/create 0.5.4 → 0.5.5

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/preset/gql.js CHANGED
@@ -9,11 +9,97 @@ const agentsPath = [
9
9
  ].find(existsSync) ?? '';
10
10
  const agentsContent = agentsPath ? readFileSync(agentsPath, 'utf8') : '';
11
11
  export const gql = (options) => ({
12
- 'README.md': `# ${options.name}\n\n${options.description}\n`,
12
+ 'README.md': `# GraphQL API
13
+
14
+ Calm cloud-ready GraphQL application.
15
+
16
+ This repository is a Yarn workspace monorepo with a reusable GraphQL API package and a runtime workspace that serves it over HTTP.
17
+
18
+ ## Requirements
19
+
20
+ - Node.js \`>=24.0.0\`
21
+ - Yarn \`4.16.0\`
22
+
23
+ ## Workspaces
24
+
25
+ - \`packages/graphql\` - reusable \`@p/graphql\` package that owns the GraphQL schema, embedded GraphiQL page, and public router export.
26
+ - \`workspaces/graphql\` - \`@w/graphql\` runtime workspace that mounts the shared router through \`@vyriy/handler\` and \`@vyriy/server\`.
27
+
28
+ ## Development
29
+
30
+ Install dependencies:
31
+
32
+ \`\`\`bash
33
+ yarn install
34
+ \`\`\`
35
+
36
+ Start the local GraphQL server:
37
+
38
+ \`\`\`bash
39
+ yarn start:graphql
40
+ \`\`\`
41
+
42
+ Open \`http://localhost:3000\` to use GraphiQL, or send a request directly:
43
+
44
+ \`\`\`bash
45
+ curl http://localhost:3000 \
46
+ --header 'Content-Type: application/json' \
47
+ --data '{"query":"{ hello test { ok message } }"}'
48
+ \`\`\`
49
+
50
+ ## Scripts
51
+
52
+ - \`yarn start\` - starts all runtime workspaces.
53
+ - \`yarn start:graphql\` - starts the GraphQL HTTP server.
54
+ - \`yarn build\` - builds all deployable outputs.
55
+ - \`yarn build:graphql\` - builds the GraphQL runtime to \`dist/graphql\`.
56
+ - \`yarn test\` - runs the Jest test suite.
57
+ - \`yarn lint\` - runs TypeScript, Prettier, and ESLint checks.
58
+ - \`yarn check\` - runs linting, builds, and tests.
59
+
60
+ ## GraphQL
61
+
62
+ The root endpoint is handled by \`@p/graphql\`:
63
+
64
+ - \`GET /\` serves the embedded GraphiQL page.
65
+ - \`POST /\` executes GraphQL requests.
66
+
67
+ Current schema fields:
68
+
69
+ \`\`\`graphql
70
+ type Query {
71
+ hello: String
72
+ test: Test
73
+ }
74
+
75
+ type Test {
76
+ ok: Boolean
77
+ message: String
78
+ }
79
+
80
+ type Mutation {
81
+ ping(message: String): String
82
+ }
83
+ \`\`\`
84
+
85
+ See the package and runtime READMEs for the detailed API and deployment notes:
86
+
87
+ - \`packages/graphql/README.md\`
88
+ - \`workspaces/graphql/README.md\`
89
+
90
+ ## Project Guidance
91
+
92
+ These articles describe the development approach behind this preset and provide practical guidance for evolving a project on top of it:
93
+
94
+ - [Calm Development Environment: Node.js, Corepack, Yarn and Static Preview](https://vyriy.dev/blog/calm-development-setup/) - how to keep the local development environment predictable and easy to reproduce.
95
+ - [Calm App Structure for the Vyriy Ecosystem](https://vyriy.dev/blog/vyriy-calm-app-structure/) - a practical project structure for Vyriy applications: shared configs, small packages, thin workspaces, Storybook docs, tests, and deployable entry points.
96
+ - [One Handler, Many Runtimes](https://vyriy.dev/examples/one-handler-many-runtimes/) - how @vyriy/handler, @vyriy/router, and @vyriy/server compose a calm Lambda-compatible API that can run locally, in Docker, Fargate-style HTTP runtimes, and AWS Lambda.
97
+ - [Storybook as Project Documentation](https://vyriy.dev/blog/storybook-as-project-documentation/) - how to use Storybook as living project documentation and a component playground.
98
+ `,
13
99
  'doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
14
100
  import ReadMe from './README.md?raw';
15
101
 
16
- <Meta title="${options.name}" />
102
+ <Meta title="GraphQL API" />
17
103
 
18
104
  <Markdown>{ReadMe}</Markdown>
19
105
  `,
@@ -317,41 +403,91 @@ describe('packages/graphql/index.ts', () => {
317
403
  "private": true
318
404
  }
319
405
  `,
320
- 'packages/graphql/README.md': `# @p/graphql
406
+ 'packages/graphql/README.md': `# GraphQL
321
407
 
322
408
  Reusable GraphQL API package for the application.
323
409
 
324
- ## Exports
410
+ The package owns the GraphQL schema, embeds the GraphiQL browser UI, and exposes an \`@vyriy/router\` router that can be mounted by an HTTP runtime.
411
+
412
+ ## Public API
325
413
 
326
- - \`router\` - an \`@vyriy/router\` instance that serves the GraphiQL page and GraphQL HTTP requests.
414
+ ### \`router\`
327
415
 
328
- ## Routes
416
+ \`router\` is the package public export. It handles the root GraphQL endpoint:
329
417
 
330
- ### \`GET /\`
418
+ - \`GET /\` returns the embedded GraphiQL page with \`Content-Type: text/html; charset=UTF-8\`.
419
+ - \`POST /\` executes a GraphQL request body against the package schema.
331
420
 
332
- Returns an embedded GraphiQL page for exploring the schema in a browser.
421
+ \`\`\`ts
422
+ import { router } from '@p/graphql';
423
+
424
+ const response = await router.route(event);
425
+ \`\`\`
333
426
 
334
- ### \`POST /\`
427
+ ## GraphQL HTTP
335
428
 
336
- The router expects a JSON body with a GraphQL request:
429
+ \`POST /\` expects a JSON body with a GraphQL request:
337
430
 
338
431
  \`\`\`json
339
432
  {
340
- "query": "{ hello }",
433
+ "query": "query Hello { hello }",
341
434
  "variables": {},
342
435
  "operationName": "Hello"
343
436
  }
344
437
  \`\`\`
345
438
 
346
- Invalid JSON or an empty body returns \`400\` with \`Invalid JSON body\`. A body without \`query\` returns \`400\` with \`Missing GraphQL query\`.
439
+ Supported fields:
440
+
441
+ - \`query\` - required GraphQL query or mutation source.
442
+ - \`variables\` - optional GraphQL variables object.
443
+ - \`operationName\` - optional operation name used when the request contains more than one operation.
444
+
445
+ Successful requests return the standard GraphQL execution result as JSON:
446
+
447
+ \`\`\`json
448
+ {
449
+ "data": {
450
+ "hello": "Hello from GraphQL"
451
+ }
452
+ }
453
+ \`\`\`
454
+
455
+ Invalid input returns a \`400\` response with a GraphQL-style \`errors\` array:
456
+
457
+ - Missing or invalid JSON body: \`Invalid JSON body\`
458
+ - Body without \`query\`: \`Missing GraphQL query\`
347
459
 
348
460
  ## Schema
349
461
 
350
- The package schema currently supports:
462
+ The current schema supports these fields:
463
+
464
+ \`\`\`graphql
465
+ type Query {
466
+ hello: String
467
+ test: Test
468
+ }
469
+
470
+ type Test {
471
+ ok: Boolean
472
+ message: String
473
+ }
474
+
475
+ type Mutation {
476
+ ping(message: String): String
477
+ }
478
+ \`\`\`
479
+
480
+ Example query:
351
481
 
352
- - \`hello: String\`
353
- - \`test: Test\`
354
- - \`ping(message: String): String\`
482
+ \`\`\`graphql
483
+ query Status {
484
+ hello
485
+ test {
486
+ ok
487
+ message
488
+ }
489
+ }
490
+ \`\`\`
355
491
 
356
492
  Example mutation:
357
493
 
@@ -360,6 +496,18 @@ mutation Ping($message: String) {
360
496
  ping(message: $message)
361
497
  }
362
498
  \`\`\`
499
+
500
+ ## GraphiQL
501
+
502
+ \`GET /\` serves the embedded GraphiQL page. The page loads GraphiQL, the explorer plugin, React, and GraphQL from pinned \`esm.sh\` URLs and configures the fetcher for \`http://localhost:3000\`.
503
+
504
+ ## Tests
505
+
506
+ Run the package tests from the repository root:
507
+
508
+ \`\`\`bash
509
+ yarn jest packages/graphql --runInBand --coverage=false
510
+ \`\`\`
363
511
  `,
364
512
  'packages/graphql/router.test.ts': `import { describe, expect, it } from '@jest/globals';
365
513
  import type { APIGatewayProxyEvent, APIGatewayProxyResult } from '@vyriy/router';
@@ -685,7 +833,7 @@ NODE_ENV=production LOG_LEVEL=info tsx $scriptdir/index.ts
685
833
  'workspaces/graphql/doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
686
834
  import ReadMe from './README.md?raw';
687
835
 
688
- <Meta title="Workspaces/Graphql" />
836
+ <Meta title="Workspaces/GraphQL" />
689
837
 
690
838
  <Markdown>{ReadMe}</Markdown>
691
839
  `,
@@ -784,7 +932,7 @@ import { api } from '@vyriy/handler';
784
932
 
785
933
  import { router } from '@p/graphql';
786
934
 
787
- server(api(async (event) => router.route(event)));
935
+ server(api(router.handle()));
788
936
  `,
789
937
  'workspaces/graphql/package.json': `{
790
938
  "name": "@w/graphql",
@@ -792,26 +940,28 @@ server(api(async (event) => router.route(event)));
792
940
  "private": true
793
941
  }
794
942
  `,
795
- 'workspaces/graphql/README.md': `# @w/graphql
943
+ 'workspaces/graphql/README.md': `# GraphQL
796
944
 
797
945
  GraphQL runtime workspace for the application.
798
946
 
799
947
  This workspace starts the HTTP server and mounts the reusable \`@p/graphql\` router through \`@vyriy/handler\` and \`@vyriy/server\`.
800
948
 
801
- ## Routes
802
-
803
- - \`GET /\` - serves the embedded GraphiQL page.
804
- - \`POST /\` - executes GraphQL requests against the package schema.
949
+ ## Runtime
805
950
 
806
- Example request body:
951
+ The workspace entrypoint is \`index.ts\`. It adapts API Gateway-style events with \`api()\` and passes the handler to \`server()\`:
807
952
 
808
- \`\`\`json
809
- {
810
- "query": "{ hello test { ok message } }"
811
- }
953
+ \`\`\`ts
954
+ server(api(router.handle()));
812
955
  \`\`\`
813
956
 
814
- ## Development
957
+ The shared router handles:
958
+
959
+ - \`GET /\` - serves the embedded GraphiQL page.
960
+ - \`POST /\` - executes GraphQL requests against the \`@p/graphql\` schema.
961
+
962
+ Other paths are handled by the router fallback and return \`404\`.
963
+
964
+ ## Local Development
815
965
 
816
966
  Start the local GraphQL server:
817
967
 
@@ -819,20 +969,34 @@ Start the local GraphQL server:
819
969
  yarn start:graphql
820
970
  \`\`\`
821
971
 
972
+ The start script runs \`workspaces/graphql/index.ts\` with \`NODE_ENV=production\` and \`LOG_LEVEL=info\`.
973
+
974
+ Example request:
975
+
976
+ \`\`\`bash
977
+ curl http://localhost:3000 \
978
+ --header 'Content-Type: application/json' \
979
+ --data '{"query":"{ hello test { ok message } }"}'
980
+ \`\`\`
981
+
982
+ Open \`http://localhost:3000\` in a browser to use GraphiQL.
983
+
984
+ ## Build
985
+
822
986
  Build the deployable bundle:
823
987
 
824
988
  \`\`\`bash
825
989
  yarn build:graphql
826
990
  \`\`\`
827
991
 
828
- The build output is written to \`dist/graphql\`.
992
+ The build writes a CommonJS server bundle to \`dist/graphql/index.js\`, copies the workspace \`package.json\`, and removes deployment-irrelevant \`type\` and \`private\` fields from the generated package metadata.
829
993
 
830
- ## Implementation
994
+ ## Tests
831
995
 
832
- The workspace entrypoint is \`index.ts\`. It wraps the shared router with \`api()\` and passes it to \`server()\`:
996
+ Run the workspace tests from the repository root:
833
997
 
834
- \`\`\`ts
835
- server(api(async (event) => router.route(event)));
998
+ \`\`\`bash
999
+ yarn jest workspaces/graphql --runInBand --coverage=false
836
1000
  \`\`\`
837
1001
  `,
838
1002
  'workspaces/graphql/webpack.config.ts': `import { path } from '@vyriy/path';