@auto-engineer/server-generator-apollo-emmett 0.11.15 → 0.11.17
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/src/codegen/templates/command/mutation.resolver.specs.ts +66 -2
- package/dist/src/codegen/templates/command/mutation.resolver.ts.ejs +6 -5
- package/dist/src/codegen/templates/query/query.resolver.specs.ts +79 -0
- package/dist/src/codegen/templates/query/query.resolver.ts.ejs +45 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/codegen/templates/command/mutation.resolver.specs.ts +66 -2
- package/src/codegen/templates/command/mutation.resolver.ts.ejs +6 -5
- package/src/codegen/templates/query/query.resolver.specs.ts +79 -0
- package/src/codegen/templates/query/query.resolver.ts.ejs +45 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @auto-engineer/server-generator-apollo-emmett@0.11.
|
|
2
|
+
> @auto-engineer/server-generator-apollo-emmett@0.11.17 build /home/runner/work/auto-engineer/auto-engineer/packages/server-generator-apollo-emmett
|
|
3
3
|
> tsc && tsx ../../scripts/fix-esm-imports.ts && rm -rf dist/src/codegen/templates && mkdir -p dist/src/codegen && cp -r src/codegen/templates dist/src/codegen/templates && cp src/server.ts dist/src && cp -r src/utils dist/src && cp -r src/domain dist/src
|
|
4
4
|
|
|
5
5
|
Fixed ESM imports in dist/
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @auto-engineer/server-generator-apollo-emmett
|
|
2
2
|
|
|
3
|
+
## 0.11.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @auto-engineer/narrative@0.11.17
|
|
9
|
+
- @auto-engineer/message-bus@0.11.17
|
|
10
|
+
|
|
11
|
+
## 0.11.16
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- version bump
|
|
16
|
+
|
|
17
|
+
- Updated dependencies []:
|
|
18
|
+
- @auto-engineer/message-bus@0.11.16
|
|
19
|
+
- @auto-engineer/narrative@0.11.16
|
|
20
|
+
|
|
3
21
|
## 0.11.15
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -76,7 +76,7 @@ describe('mutation.resolver.ts.ejs', () => {
|
|
|
76
76
|
const mutationFile = plans.find((p) => p.outputPath.endsWith('mutation.resolver.ts'));
|
|
77
77
|
|
|
78
78
|
expect(mutationFile?.contents).toMatchInlineSnapshot(`
|
|
79
|
-
"import { Mutation, Resolver, Arg, Ctx, Field, InputType, GraphQLISODateTime } from 'type-graphql';
|
|
79
|
+
"import { Mutation, Resolver, Arg, Ctx, Field, InputType, Float, GraphQLISODateTime } from 'type-graphql';
|
|
80
80
|
import { GraphQLJSON } from 'graphql-type-json';
|
|
81
81
|
import { type GraphQLContext, sendCommand, MutationResponse } from '../../../shared';
|
|
82
82
|
|
|
@@ -322,7 +322,7 @@ describe('mutation.resolver.ts.ejs', () => {
|
|
|
322
322
|
);
|
|
323
323
|
|
|
324
324
|
expect(mutationFile?.contents).toMatchInlineSnapshot(`
|
|
325
|
-
"import { Mutation, Resolver, Arg, Ctx, Field, InputType } from 'type-graphql';
|
|
325
|
+
"import { Mutation, Resolver, Arg, Ctx, Field, InputType, Float } from 'type-graphql';
|
|
326
326
|
import { GraphQLJSON } from 'graphql-type-json';
|
|
327
327
|
import { type GraphQLContext, sendCommand, MutationResponse } from '../../../shared';
|
|
328
328
|
|
|
@@ -361,4 +361,68 @@ export class AddItemsToCartResolver {
|
|
|
361
361
|
"
|
|
362
362
|
`);
|
|
363
363
|
});
|
|
364
|
+
|
|
365
|
+
it('should import Float when Float fields are used', async () => {
|
|
366
|
+
const spec: SpecsSchema = {
|
|
367
|
+
variant: 'specs',
|
|
368
|
+
narratives: [
|
|
369
|
+
{
|
|
370
|
+
name: 'product-flow',
|
|
371
|
+
slices: [
|
|
372
|
+
{
|
|
373
|
+
type: 'command',
|
|
374
|
+
name: 'update-product-price',
|
|
375
|
+
client: {
|
|
376
|
+
description: '',
|
|
377
|
+
},
|
|
378
|
+
server: {
|
|
379
|
+
description: '',
|
|
380
|
+
specs: {
|
|
381
|
+
name: '',
|
|
382
|
+
rules: [
|
|
383
|
+
{
|
|
384
|
+
description: 'update price',
|
|
385
|
+
examples: [
|
|
386
|
+
{
|
|
387
|
+
description: 'happy path',
|
|
388
|
+
when: {
|
|
389
|
+
commandRef: 'UpdateProductPrice',
|
|
390
|
+
exampleData: {
|
|
391
|
+
productId: 'p-1',
|
|
392
|
+
price: 99.99,
|
|
393
|
+
discount: 10.5,
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
then: [],
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
messages: [
|
|
408
|
+
{
|
|
409
|
+
type: 'command',
|
|
410
|
+
name: 'UpdateProductPrice',
|
|
411
|
+
fields: [
|
|
412
|
+
{ name: 'productId', type: 'string', required: true },
|
|
413
|
+
{ name: 'price', type: 'number', required: true },
|
|
414
|
+
{ name: 'discount', type: 'number', required: true },
|
|
415
|
+
],
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const plans = await generateScaffoldFilePlans(spec.narratives, spec.messages, undefined, 'src/domain/flows');
|
|
421
|
+
const mutationFile = plans.find((p) => p.outputPath.endsWith('mutation.resolver.ts'));
|
|
422
|
+
|
|
423
|
+
expect(mutationFile?.contents).toContain(
|
|
424
|
+
"import { Mutation, Resolver, Arg, Ctx, Field, InputType, Float } from 'type-graphql';",
|
|
425
|
+
);
|
|
426
|
+
expect(mutationFile?.contents).toContain('@Field(() => Float)');
|
|
427
|
+
});
|
|
364
428
|
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const cmd = commands[0];
|
|
3
|
-
const usesDate = cmd.fields.some(f => fieldUsesDate(f.tsType));
|
|
4
|
-
const usesJSON = cmd.fields.some(f => fieldUsesJSON(f.tsType));
|
|
3
|
+
const usesDate = cmd.fields.some(f => fieldUsesDate(f.type ?? f.tsType));
|
|
4
|
+
const usesJSON = cmd.fields.some(f => fieldUsesJSON(f.type ?? f.tsType));
|
|
5
|
+
const usesFloat = cmd.fields.some(f => fieldUsesFloat(f.type ?? f.tsType));
|
|
5
6
|
const enumList = collectEnumNames(cmd.fields);
|
|
6
7
|
|
|
7
8
|
const embeddedInputs = [];
|
|
8
9
|
for (const f of cmd.fields) {
|
|
9
|
-
const tsType = f.tsType ?? 'string';
|
|
10
|
+
const tsType = f.type ?? f.tsType ?? 'string';
|
|
10
11
|
if (isInlineObjectArray(tsType) || isInlineObject(tsType)) {
|
|
11
12
|
embeddedInputs.push({
|
|
12
13
|
typeName: `${pascalCase(cmd.type)}${pascalCase(f.name)}Input`,
|
|
@@ -15,7 +16,7 @@ for (const f of cmd.fields) {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
%>
|
|
18
|
-
import { Mutation, Resolver, Arg, Ctx, Field, InputType<% if (usesDate) { %>, GraphQLISODateTime<% } %> } from 'type-graphql';
|
|
19
|
+
import { Mutation, Resolver, Arg, Ctx, Field, InputType<% if (usesFloat) { %>, Float<% } %><% if (usesDate) { %>, GraphQLISODateTime<% } %> } from 'type-graphql';
|
|
19
20
|
<% if (usesJSON) { %>import { GraphQLJSON } from 'graphql-type-json';
|
|
20
21
|
<% } %>import { type GraphQLContext, sendCommand, MutationResponse<% if (enumList.length > 0) { %>, <%= enumList.join(', ') %><% } %> } from '../../../shared';
|
|
21
22
|
|
|
@@ -46,7 +47,7 @@ export class <%= typeName %> {
|
|
|
46
47
|
@InputType()
|
|
47
48
|
export class <%= pascalCase(cmd.type) %>Input {
|
|
48
49
|
<% for (const field of cmd.fields) {
|
|
49
|
-
const tsType = field.tsType ?? 'string';
|
|
50
|
+
const tsType = field.type ?? field.tsType ?? 'string';
|
|
50
51
|
const gqlType = graphqlType(tsType);
|
|
51
52
|
const nestedName = `${pascalCase(cmd.type)}${pascalCase(field.name)}Input`;
|
|
52
53
|
|
|
@@ -610,4 +610,83 @@ describe('query.resolver.ts.ejs', () => {
|
|
|
610
610
|
expect(resolverFile?.contents).toContain('Float');
|
|
611
611
|
expect(resolverFile?.contents).toContain("@Arg('minPrice', () => Float");
|
|
612
612
|
});
|
|
613
|
+
|
|
614
|
+
it('should generate a singleton query resolver that returns a single object', async () => {
|
|
615
|
+
const spec: SpecsSchema = {
|
|
616
|
+
variant: 'specs',
|
|
617
|
+
narratives: [
|
|
618
|
+
{
|
|
619
|
+
name: 'todo-list-flow',
|
|
620
|
+
slices: [
|
|
621
|
+
{
|
|
622
|
+
type: 'query',
|
|
623
|
+
name: 'views-completion-summary',
|
|
624
|
+
request: `
|
|
625
|
+
query TodoListSummary {
|
|
626
|
+
todoListSummary {
|
|
627
|
+
totalTodos
|
|
628
|
+
pendingCount
|
|
629
|
+
inProgressCount
|
|
630
|
+
completedCount
|
|
631
|
+
completionPercentage
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
`,
|
|
635
|
+
client: {
|
|
636
|
+
description: '',
|
|
637
|
+
},
|
|
638
|
+
server: {
|
|
639
|
+
description: '',
|
|
640
|
+
data: [
|
|
641
|
+
{
|
|
642
|
+
origin: {
|
|
643
|
+
type: 'projection',
|
|
644
|
+
name: 'TodoSummary',
|
|
645
|
+
singleton: true,
|
|
646
|
+
},
|
|
647
|
+
target: {
|
|
648
|
+
type: 'State',
|
|
649
|
+
name: 'TodoListSummary',
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
specs: { name: '', rules: [] },
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
],
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
messages: [
|
|
660
|
+
{
|
|
661
|
+
type: 'state',
|
|
662
|
+
name: 'TodoListSummary',
|
|
663
|
+
fields: [
|
|
664
|
+
{ name: 'totalTodos', type: 'number', required: true },
|
|
665
|
+
{ name: 'pendingCount', type: 'number', required: true },
|
|
666
|
+
{ name: 'inProgressCount', type: 'number', required: true },
|
|
667
|
+
{ name: 'completedCount', type: 'number', required: true },
|
|
668
|
+
{ name: 'completionPercentage', type: 'number', required: true },
|
|
669
|
+
],
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
const plans = await generateScaffoldFilePlans(spec.narratives, spec.messages, undefined, 'src/domain/flows');
|
|
675
|
+
const resolverFile = plans.find((p) => p.outputPath.endsWith('query.resolver.ts'));
|
|
676
|
+
|
|
677
|
+
// Should return single object, not array
|
|
678
|
+
expect(resolverFile?.contents).toContain('@Query(() => TodoListSummary)');
|
|
679
|
+
expect(resolverFile?.contents).not.toContain('@Query(() => [TodoListSummary])');
|
|
680
|
+
|
|
681
|
+
// Should use collection.findOne() pattern
|
|
682
|
+
expect(resolverFile?.contents).toContain("ctx.database.collection<TodoListSummary>('TodoSummary').findOne()");
|
|
683
|
+
|
|
684
|
+
expect(resolverFile?.contents).toContain('if (!result)');
|
|
685
|
+
expect(resolverFile?.contents).toContain('totalTodos: 0');
|
|
686
|
+
expect(resolverFile?.contents).toContain('pendingCount: 0');
|
|
687
|
+
|
|
688
|
+
// Should NOT import ReadModel (unused for singletons)
|
|
689
|
+
expect(resolverFile?.contents).toContain("import { type GraphQLContext } from '../../../shared'");
|
|
690
|
+
expect(resolverFile?.contents).not.toContain(', ReadModel');
|
|
691
|
+
});
|
|
613
692
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const target = slice?.server?.data?.[0]?.target;
|
|
3
3
|
const projection = slice?.server?.data?.[0]?.origin;
|
|
4
|
+
const isSingleton = projection?.singleton === true;
|
|
4
5
|
const queryName = parsedRequest?.queryName ?? camelCase(sliceName);
|
|
5
6
|
const viewType = target?.name ? pascalCase(target.name) : 'UnknownView';
|
|
6
7
|
const projectionType = projection?.name ? pascalCase(projection.name) : 'UnknownProjection';
|
|
@@ -32,7 +33,7 @@ const hasArgs = parsedRequest?.args?.length > 0;
|
|
|
32
33
|
%>
|
|
33
34
|
import { Query, Resolver<% if (hasArgs) { %>, Arg<% } %>, Ctx, ObjectType, Field<% if (usesID) { %>, ID<% } %><% if (usesFloat) { %>, Float<% } %><% if (usesDate) { %>, GraphQLISODateTime<% } %> } from 'type-graphql';
|
|
34
35
|
<% if (usesJSON) { %>import { GraphQLJSON } from 'graphql-type-json';
|
|
35
|
-
<% } %>import { type GraphQLContext
|
|
36
|
+
<% } %>import { type GraphQLContext<% if (!isSingleton) { %>, ReadModel<% } %><% if (enumList.length > 0) { %>, <%= enumList.join(', ') %><% } %> } from '../../../shared';
|
|
36
37
|
|
|
37
38
|
<%
|
|
38
39
|
for (const { typeName, tsType } of embeddedTypes) {
|
|
@@ -88,6 +89,48 @@ export class <%= viewType %> {
|
|
|
88
89
|
|
|
89
90
|
@Resolver()
|
|
90
91
|
export class <%= resolverClassName %> {
|
|
92
|
+
<% if (isSingleton) { %>
|
|
93
|
+
@Query(() => <%= viewType %>)
|
|
94
|
+
async <%= queryName %>(
|
|
95
|
+
@Ctx() ctx: GraphQLContext<% if (parsedRequest?.args?.length) { %>,
|
|
96
|
+
<% for (let i = 0; i < parsedRequest.args.length; i++) {
|
|
97
|
+
const arg = parsedRequest.args[i];
|
|
98
|
+
const gqlType = graphqlType(arg.tsType);
|
|
99
|
+
const tsType = arg.tsType === 'ID' ? 'string' : arg.tsType;
|
|
100
|
+
%> @Arg('<%= arg.name %>', () => <%= gqlType %>, { nullable: true }) <%= arg.name %>?: <%= tsType %><%= i < parsedRequest.args.length - 1 ? ',' : '' %>
|
|
101
|
+
<% } } %>
|
|
102
|
+
): Promise<<%= viewType %>> {
|
|
103
|
+
const result = await ctx.database.collection<<%= viewType %>>('<%= projectionType %>').findOne();
|
|
104
|
+
|
|
105
|
+
if (!result) {
|
|
106
|
+
return {
|
|
107
|
+
<% for (let i = 0; i < messageFields.length; i++) {
|
|
108
|
+
const field = messageFields[i];
|
|
109
|
+
const tsType = field.type ?? 'string';
|
|
110
|
+
const baseType = tsType.replace(/\s*\|\s*null/g, '').trim();
|
|
111
|
+
let defaultValue = '0';
|
|
112
|
+
|
|
113
|
+
if (baseType === 'string' || baseType === 'ID') {
|
|
114
|
+
defaultValue = "''";
|
|
115
|
+
} else if (baseType === 'number') {
|
|
116
|
+
defaultValue = '0';
|
|
117
|
+
} else if (baseType === 'boolean') {
|
|
118
|
+
defaultValue = 'false';
|
|
119
|
+
} else if (baseType === 'Date') {
|
|
120
|
+
defaultValue = 'new Date()';
|
|
121
|
+
} else if (baseType.startsWith('Array<')) {
|
|
122
|
+
defaultValue = '[]';
|
|
123
|
+
} else if (baseType.includes('|') && (baseType.includes('"') || baseType.includes("'"))) {
|
|
124
|
+
const firstValue = baseType.match(/['"]([^'"]+)['"]/)?.[1] ?? '';
|
|
125
|
+
defaultValue = `'${firstValue}'`;
|
|
126
|
+
}
|
|
127
|
+
%> <%= field.name %>: <%= defaultValue %>,
|
|
128
|
+
<% } %> };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
<% } else { %>
|
|
91
134
|
@Query(() => [<%= viewType %>])
|
|
92
135
|
async <%= queryName %>(
|
|
93
136
|
@Ctx() ctx: GraphQLContext<% if (parsedRequest?.args?.length) { %>,
|
|
@@ -118,4 +161,5 @@ return model.find((<%= hasArgs ? 'item' : '_item' %>) => {
|
|
|
118
161
|
return true;
|
|
119
162
|
});
|
|
120
163
|
}
|
|
164
|
+
<% } %>
|
|
121
165
|
}
|