@auto-engineer/server-generator-apollo-emmett 0.11.14 → 0.11.16
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/extract/messages.d.ts +1 -0
- package/dist/src/codegen/extract/messages.d.ts.map +1 -1
- package/dist/src/codegen/extract/messages.js +4 -1
- package/dist/src/codegen/extract/messages.js.map +1 -1
- package/dist/src/codegen/extract/projection.d.ts +1 -0
- package/dist/src/codegen/extract/projection.d.ts.map +1 -1
- package/dist/src/codegen/extract/projection.js +12 -0
- package/dist/src/codegen/extract/projection.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +3 -2
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- 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/projection.specs.specs.ts +1 -3
- package/dist/src/codegen/templates/query/projection.specs.ts +9 -5
- package/dist/src/codegen/templates/query/projection.specs.ts.ejs +6 -2
- package/dist/src/codegen/templates/query/projection.ts.ejs +9 -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/extract/messages.ts +6 -1
- package/src/codegen/extract/projection.ts +14 -0
- package/src/codegen/scaffoldFromSchema.ts +3 -0
- 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/projection.specs.specs.ts +1 -3
- package/src/codegen/templates/query/projection.specs.ts +9 -5
- package/src/codegen/templates/query/projection.specs.ts.ejs +6 -2
- package/src/codegen/templates/query/projection.ts.ejs +9 -5
- package/src/codegen/templates/query/query.resolver.specs.ts +79 -0
- package/src/codegen/templates/query/query.resolver.ts.ejs +45 -1
|
@@ -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
|
}
|