@@ -3,7 +3,8 @@ import { GraphQLSchema } from "graphql";
3
3
import { Argument , AssociationType , Field , Fields , FieldType , ModelAttribute , ModelIntrospectionSchema , PrimaryKeyInfo , SchemaEnum , SchemaModel , SchemaMutation , SchemaNonModel , SchemaQuery , SchemaSubscription , Input , InputFieldType , SchemaConversationRoute } from "../interfaces/introspection" ;
4
4
import { METADATA_SCALAR_MAP } from "../scalars" ;
5
5
import { CodeGenConnectionType } from "../utils/process-connections" ;
6
- import { RawAppSyncModelConfig , ParsedAppSyncModelConfig , AppSyncModelVisitor , CodeGenEnum , CodeGenField , CodeGenModel , CodeGenPrimaryKeyType , CodeGenQuery , CodeGenSubscription , CodeGenMutation , CodeGenInputObject } from "./appsync-visitor" ;
6
+ import { RawAppSyncModelConfig , ParsedAppSyncModelConfig , AppSyncModelVisitor , CodeGenEnum , CodeGenField , CodeGenModel , CodeGenPrimaryKeyType , CodeGenQuery , CodeGenSubscription , CodeGenMutation , CodeGenInputObject , CodeGenInputObjectMap } from "./appsync-visitor" ;
7
+ import { pascalCase } from "change-case" ;
7
8
8
9
const validateModelIntrospectionSchema = require ( '../validate-cjs' ) ;
9
10
@@ -80,11 +81,12 @@ export class AppSyncModelIntrospectionVisitor<
80
81
}
81
82
return { ...acc , [ mutationObj . name ] : this . generateGraphQLOperationMetadata < CodeGenMutation , SchemaMutation > ( mutationObj ) } ;
82
83
} , { } ) ;
83
- const conversationRoutes = Object . values ( this . mutationMap ) . reduce ( ( acc , mutationObj : CodeGenMutation ) => {
84
+ const conversations = Object . values ( this . mutationMap ) . reduce ( ( acc , mutationObj : CodeGenMutation ) => {
84
85
if ( ! mutationObj . directives . find ( ( directive ) => directive . name === 'conversation' ) ) {
85
86
return acc ;
86
87
}
87
- return { ...acc , [ mutationObj . name ] : this . generateConversationMetadata ( mutationObj ) }
88
+ const { route, inputs } = this . generateConversationMetadata ( mutationObj )
89
+ return { ...acc , [ mutationObj . name ] : route }
88
90
} , { } ) ;
89
91
const subscriptions = Object . values ( this . subscriptionMap ) . reduce ( ( acc , subscriptionObj : CodeGenSubscription ) => {
90
92
// Skip the field if the field type is union/interface
@@ -104,8 +106,8 @@ export class AppSyncModelIntrospectionVisitor<
104
106
if ( Object . keys ( mutations ) . length > 0 ) {
105
107
result = { ...result , mutations } ;
106
108
}
107
- if ( Object . keys ( conversationRoutes ) . length > 0 ) {
108
- result = { ...result , conversationRoutes }
109
+ if ( Object . keys ( conversations ) . length > 0 ) {
110
+ result = { ...result , conversations }
109
111
}
110
112
if ( Object . keys ( subscriptions ) . length > 0 ) {
111
113
result = { ...result , subscriptions } ;
@@ -245,21 +247,22 @@ export class AppSyncModelIntrospectionVisitor<
245
247
return operationMeta as V ;
246
248
}
247
249
248
- private generateConversationMetadata ( mutationObj : CodeGenMutation ) : SchemaConversationRoute {
249
- const conversationRoute : SchemaConversationRoute = {
250
+ private generateConversationMetadata ( mutationObj : CodeGenMutation ) : { route : SchemaConversationRoute , inputs : CodeGenInputObjectMap } {
251
+ const routeName = pascalCase ( mutationObj . name )
252
+ const route : SchemaConversationRoute = {
250
253
conversation : {
251
254
create : {
252
- name : `createConversation${ mutationObj . name } ` ,
255
+ name : `createConversation${ routeName } ` ,
253
256
isArray : false ,
254
257
type : {
255
- model : `Conversation${ mutationObj . name } `
258
+ model : `Conversation${ routeName } `
256
259
} ,
257
260
isRequired : false ,
258
261
} ,
259
262
get : {
260
- name : `getConversation${ mutationObj . name } ` ,
263
+ name : `getConversation${ routeName } ` ,
261
264
isArray : false ,
262
- type : { model : `Conversation${ mutationObj . name } ` } ,
265
+ type : { model : `Conversation${ routeName } ` } ,
263
266
isRequired : false ,
264
267
arguments : {
265
268
'id' : {
@@ -271,9 +274,9 @@ export class AppSyncModelIntrospectionVisitor<
271
274
}
272
275
} ,
273
276
delete : {
274
- name : `deleteConversation${ mutationObj . name } ` ,
277
+ name : `deleteConversation${ routeName } ` ,
275
278
isArray : false ,
276
- type : { model : `Conversation${ mutationObj . name } ` } ,
279
+ type : { model : `Conversation${ routeName } ` } ,
277
280
isRequired : false ,
278
281
arguments : {
279
282
'id' : {
@@ -285,27 +288,21 @@ export class AppSyncModelIntrospectionVisitor<
285
288
}
286
289
} ,
287
290
list : {
288
- name : `listConversation${ mutationObj . name } ` ,
291
+ name : `listConversation${ routeName } ` ,
289
292
isArray : true ,
290
293
type : {
291
- model : `Conversation${ mutationObj . name } `
294
+ model : `Conversation${ routeName } `
292
295
} ,
293
296
isRequired : false ,
294
297
}
295
298
} ,
296
299
message : {
297
300
send : this . generateGraphQLOperationMetadata < CodeGenMutation , SchemaMutation > ( mutationObj ) ,
298
- // send: {
299
- // name: mutationObj.name,
300
- // isArray: false,
301
- // type: 'String',
302
- // isRequired: false,
303
- // },
304
301
subscribe : {
305
302
isArray : false ,
306
303
isRequired : false ,
307
- name : `onAssistantMessageResponse${ mutationObj . name } ` ,
308
- type : { model : `ConversationMessage${ mutationObj . name } ` } ,
304
+ name : `onAssistantMessageResponse${ routeName } ` ,
305
+ type : { model : `ConversationMessage${ routeName } ` } ,
309
306
arguments : {
310
307
'sessionId' : {
311
308
name : 'sessionId' ,
@@ -314,10 +311,82 @@ export class AppSyncModelIntrospectionVisitor<
314
311
type : 'ID' ,
315
312
} ,
316
313
}
314
+ } ,
315
+ list : {
316
+ name : `listConversationMessage${ routeName } ` ,
317
+ isArray : true ,
318
+ type : {
319
+ nonModel : `ModelConversationMessage${ routeName } Connection`
320
+ } ,
321
+ isRequired : false ,
322
+ arguments : {
323
+ filter : {
324
+ name : 'filter' ,
325
+ isArray : false ,
326
+ isRequired : false ,
327
+ type : {
328
+ input : `ModelConversationMessage${ routeName } FilterInput`
329
+ } ,
330
+ } ,
331
+ limit : {
332
+ name : 'limit' ,
333
+ type : 'Int' ,
334
+ isArray : false ,
335
+ isRequired : false ,
336
+ } ,
337
+ nextToken : {
338
+ name : 'nextToken' ,
339
+ isRequired : false ,
340
+ type : 'String' ,
341
+ isArray : false
342
+ }
343
+ }
317
344
}
318
345
}
319
346
} ;
320
- return conversationRoute ;
347
+
348
+ const listMessagesReturnTypeName = `ModelConversationMessage${ routeName } Connection`
349
+ const nonModelTypes : Record < string , SchemaNonModel > = {
350
+ [ listMessagesReturnTypeName ] : {
351
+ name : listMessagesReturnTypeName ,
352
+ fields : {
353
+ items : {
354
+ isArray : true ,
355
+ isRequired : true ,
356
+ name : 'items' ,
357
+ type : {
358
+ model : `ConversationMessage${ routeName } `
359
+ } ,
360
+ } ,
361
+ nextToken : {
362
+ isArray : false ,
363
+ isRequired : false ,
364
+ name : 'nextToken' ,
365
+ type : 'String' ,
366
+ }
367
+ } ,
368
+ }
369
+ }
370
+
371
+
372
+ const listMessagesInputName = `ModelConversationMessage${ routeName } FilterInput` ;
373
+ const inputs : CodeGenInputObjectMap = {
374
+ [ listMessagesInputName ] : {
375
+ name : listMessagesInputName ,
376
+ inputValues : [
377
+ {
378
+ name : 'conversationId' ,
379
+ type : 'ModelIdInput' ,
380
+ isList : false ,
381
+ isNullable : true ,
382
+ directives : [ ] ,
383
+ }
384
+ ] ,
385
+ type : 'input'
386
+ }
387
+ } ;
388
+
389
+ return { route, inputs } ;
321
390
}
322
391
323
392
protected getType ( gqlType : string ) : FieldType | InputFieldType | UnionFieldType | InterfaceFieldType {
0 commit comments