@nestledjs/api 2.6.1 → 2.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestledjs/api",
3
- "version": "2.6.1",
3
+ "version": "2.7.0",
4
4
  "generators": "./generators.json",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -197,7 +197,11 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
197
197
  const usesBigInt = models.some(model =>
198
198
  model.fields.some((field: { type: string }) => field.type === 'BigInt'),
199
199
  )
200
- let output = `import { Field, ObjectType${usesFloat ? ', Float' : ''}, Int } from '@nestjs/graphql';\n`
200
+ // Check if any model field uses DateTime
201
+ const usesDateTime = models.some(model =>
202
+ model.fields.some((field: { type: string }) => field.type === 'DateTime'),
203
+ )
204
+ let output = `import { Field, ObjectType${usesFloat ? ', Float' : ''}${usesDateTime ? ', GraphQLISODateTime' : ''}, Int } from '@nestjs/graphql';\n`
201
205
  output += `import { GraphQLJSONObject } from 'graphql-type-json';\n`
202
206
 
203
207
  // Check if any model field uses Decimal
@@ -281,7 +285,7 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
281
285
  else if (originalType === 'Json') listItemGraphQLType = 'GraphQLJSONObject'
282
286
  else if (isEnum || isRelation)
283
287
  listItemGraphQLType = originalType // Assumes enum/type is registered with GraphQL
284
- else if (originalType === 'DateTime') listItemGraphQLType = 'Date'
288
+ else if (originalType === 'DateTime') listItemGraphQLType = 'GraphQLISODateTime'
285
289
  else if (originalType === 'Boolean') listItemGraphQLType = 'Boolean'
286
290
  else if (originalType.toLowerCase() === 'string' || originalType === 'ID') {
287
291
  listItemGraphQLType = 'String'
@@ -297,7 +301,7 @@ function generateModels(models: readonly any[], enums: readonly any[]): string {
297
301
  else if (originalType === 'BigInt') decoratorType = '() => GraphQLBigInt'
298
302
  else if (originalType === 'Json') decoratorType = '() => GraphQLJSONObject'
299
303
  else if (isEnum || isRelation) decoratorType = `() => ${originalType}`
300
- else if (originalType === 'DateTime') decoratorType = '() => Date'
304
+ else if (originalType === 'DateTime') decoratorType = '() => GraphQLISODateTime'
301
305
  else if (originalType === 'Boolean') decoratorType = '() => Boolean'
302
306
  else if (originalType.toLowerCase() === 'string' || originalType === 'ID')
303
307
  decoratorType = '() => String'
@@ -3,6 +3,7 @@
3
3
  let gqlImports = new Set(['Field', 'InputType'])
4
4
  let usesGraphQLJSON = false
5
5
  let usesGraphQLBigInt = false
6
+ let usesDateTime = false
6
7
  let usesInt = false
7
8
  let usesFloat = false
8
9
  let usesID = false
@@ -72,6 +73,7 @@ for (const model of models) {
72
73
  if (field.type === 'Float' || field.type === 'Decimal') usesFloat = true
73
74
  if (field.type === 'Json') usesGraphQLJSON = true
74
75
  if (field.type === 'BigInt') usesGraphQLBigInt = true
76
+ if (field.type === 'DateTime') usesDateTime = true
75
77
  if (field.type === 'ID') usesID = true
76
78
  if (field.kind === 'enum') {
77
79
  enumNames.add(field.type)
@@ -82,6 +84,7 @@ for (const model of models) {
82
84
  if (usesInt) gqlImports.add('Int')
83
85
  if (usesFloat) gqlImports.add('Float')
84
86
  if (usesID) gqlImports.add('ID')
87
+ if (usesDateTime) gqlImports.add('GraphQLISODateTime')
85
88
  usesPartialType = models.length > 0 // If we generate any Update input, we need PartialType
86
89
  %>
87
90
  import { <%= Array.from(gqlImports).join(', ') %> } from '@nestjs/graphql'
@@ -109,7 +112,7 @@ export class Create<%= model.modelName %>Input {
109
112
  else if (field.type === 'Float') { baseGqlType = 'Float'; tsType = 'number'; }
110
113
  else if (field.type === 'Decimal') { baseGqlType = 'Float'; tsType = 'number'; }
111
114
  else if (field.type === 'Boolean') { baseGqlType = 'Boolean'; tsType = 'boolean'; }
112
- else if (field.type === 'DateTime') { baseGqlType = 'Date'; tsType = 'Date'; }
115
+ else if (field.type === 'DateTime') { baseGqlType = 'GraphQLISODateTime'; tsType = 'Date'; }
113
116
  else if (field.type === 'Json') { baseGqlType = 'GraphQLJSON'; tsType = 'typeof GraphQLJSON'; }
114
117
  else if (field.type === 'ID') { baseGqlType = 'ID'; tsType = 'string'; }
115
118
  else if (field.kind === 'enum') {
@@ -153,7 +156,7 @@ export class Update<%= model.modelName %>Input {
153
156
  else if (field.type === 'Float') { baseGqlType = 'Float'; tsType = 'number'; }
154
157
  else if (field.type === 'Decimal') { baseGqlType = 'Float'; tsType = 'number'; }
155
158
  else if (field.type === 'Boolean') { baseGqlType = 'Boolean'; tsType = 'boolean'; }
156
- else if (field.type === 'DateTime') { baseGqlType = 'Date'; tsType = 'Date'; }
159
+ else if (field.type === 'DateTime') { baseGqlType = 'GraphQLISODateTime'; tsType = 'Date'; }
157
160
  else if (field.type === 'Json') { baseGqlType = 'GraphQLJSON'; tsType = 'typeof GraphQLJSON'; }
158
161
  else if (field.type === 'ID') { baseGqlType = 'ID'; tsType = 'string'; }
159
162
  else if (field.kind === 'enum') {
@@ -190,7 +193,7 @@ export class List<%= model.modelName %>Input extends CorePagingInput {
190
193
  else if (field.type === 'Float') { baseGqlType = 'Float'; tsType = 'number'; }
191
194
  else if (field.type === 'Decimal') { baseGqlType = 'Float'; tsType = 'number'; }
192
195
  else if (field.type === 'Boolean') { baseGqlType = 'Boolean'; tsType = 'boolean'; }
193
- else if (field.type === 'DateTime') { baseGqlType = 'Date'; tsType = 'Date'; }
196
+ else if (field.type === 'DateTime') { baseGqlType = 'GraphQLISODateTime'; tsType = 'Date'; }
194
197
  else if (field.type === 'Json') { baseGqlType = 'GraphQLJSON'; tsType = 'typeof GraphQLJSON'; }
195
198
  else if (field.type === 'ID') { baseGqlType = 'ID'; tsType = 'string'; }
196
199
  else if (field.kind === 'enum') {