From c52a7f32d0418baeb489ee58333c8f3667b991d2 Mon Sep 17 00:00:00 2001 From: Ian Saultz <52051793+atierian@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:10:41 -0400 Subject: [PATCH] udpate content shape, session to conversation, sender to role --- ...c-model-introspection-visitor.test.ts.snap | 44 ++++++++++--------- ...ppsync-model-introspection-visitor.test.ts | 10 +++-- .../appsync-model-introspection-visitor.ts | 32 +++++++------- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap index 7bd5a6b72..250cdb90c 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap @@ -5,8 +5,8 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"version\\": 1, \\"models\\": {}, \\"enums\\": { - \\"ConversationMessageSender\\": { - \\"name\\": \\"ConversationMessageSender\\", + \\"ConversationParticipantRole\\": { + \\"name\\": \\"ConversationParticipantRole\\", \\"values\\": [ \\"user\\", \\"assistant\\" @@ -54,7 +54,7 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"association\\": { \\"connectionType\\": \\"HAS_MANY\\", \\"associatedWith\\": [ - \\"sessionId\\" + \\"conversationId\\" ] } }, @@ -125,15 +125,15 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"isRequired\\": true, \\"attributes\\": [] }, - \\"sessionId\\": { - \\"name\\": \\"sessionId\\", + \\"conversationId\\": { + \\"name\\": \\"conversationId\\", \\"isArray\\": false, \\"type\\": \\"ID\\", \\"isRequired\\": true, \\"attributes\\": [] }, - \\"session\\": { - \\"name\\": \\"session\\", + \\"conversation\\": { + \\"name\\": \\"conversation\\", \\"isArray\\": false, \\"type\\": { \\"model\\": \\"ConversationPirateChat\\" @@ -143,23 +143,25 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"association\\": { \\"connectionType\\": \\"BELONGS_TO\\", \\"targetNames\\": [ - \\"sessionId\\" + \\"conversationId\\" ] } }, - \\"sender\\": { - \\"name\\": \\"sender\\", + \\"role\\": { + \\"name\\": \\"role\\", \\"isArray\\": false, \\"type\\": { - \\"enum\\": \\"ConversationMessageSender\\" + \\"enum\\": \\"ConversationParticipantRole\\" }, \\"isRequired\\": false, \\"attributes\\": [] }, \\"content\\": { \\"name\\": \\"content\\", - \\"isArray\\": false, - \\"type\\": \\"String\\", + \\"isArray\\": true, + \\"type\\": { + \\"nonModel\\": \\"ContentBlock\\" + }, \\"isRequired\\": false, \\"attributes\\": [] }, @@ -181,7 +183,9 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"assistantContent\\": { \\"name\\": \\"assistantContent\\", \\"isArray\\": false, - \\"type\\": \\"String\\", + \\"type\\": { + \\"nonModel\\": \\"ContentBlock\\" + }, \\"isRequired\\": false, \\"attributes\\": [] }, @@ -243,8 +247,8 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener }, \\"nonModels\\": {}, \\"enums\\": { - \\"ConversationMessageSender\\": { - \\"name\\": \\"ConversationMessageSender\\", + \\"ConversationParticipantRole\\": { + \\"name\\": \\"ConversationParticipantRole\\", \\"values\\": [ \\"user\\", \\"assistant\\" @@ -264,8 +268,8 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener }, \\"isRequired\\": false, \\"arguments\\": { - \\"sessionId\\": { - \\"name\\": \\"sessionId\\", + \\"conversationId\\": { + \\"name\\": \\"conversationId\\", \\"isArray\\": false, \\"type\\": \\"ID\\", \\"isRequired\\": false @@ -286,8 +290,8 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"model\\": \\"ConversationMessagePirateChat\\" }, \\"arguments\\": { - \\"sessionId\\": { - \\"name\\": \\"sessionId\\", + \\"conversationId\\": { + \\"name\\": \\"conversationId\\", \\"isArray\\": false, \\"isRequired\\": true, \\"type\\": \\"ID\\" diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts index a8f70d367..4adaa6fdf 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts @@ -30,22 +30,24 @@ const getVisitor = (schema: string, settings: any = {}, directives: readonly Dir describe('Conversation Route Introspection Visitor', () => { const schema = /* GraphQL */ ` - enum ConversationMessageSender { + enum ConversationParticipantRole { user assistant } interface ConversationMessage { id: ID! - sessionId: ID! - sender: ConversationMessageSender + conversationId: ID! + role: ConversationParticipantRole + # TODO: Update to ContentBlock -- need the types content: String context: AWSJSON uiComponents: [AWSJSON] } type Mutation { - pirateChat(sessionId: ID, content: String): ConversationMessage + # TODO: Update to ContentBlock -- need the types + pirateChat(conversationId: ID, content: String): ConversationMessage @conversation(aiModel: "Claude3Haiku", functionName: "conversation-handler") } `; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts index c5e1b7b95..75f0cc2bf 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts @@ -293,7 +293,7 @@ export class AppSyncModelIntrospectionVisitor< association: { connectionType: CodeGenConnectionType.HAS_MANY, associatedWith: [ - 'sessionId' + 'conversationId' ] } }, @@ -365,15 +365,15 @@ export class AppSyncModelIntrospectionVisitor< isRequired: true, attributes: [] }, - sessionId: { - name: 'sessionId', + conversationId: { + name: 'conversationId', isArray: false, type: 'ID', isRequired: true, attributes: [] }, - session: { - name: 'session', + conversation: { + name: 'conversation', isArray: false, type: { model: conversationModelName @@ -383,23 +383,23 @@ export class AppSyncModelIntrospectionVisitor< association: { connectionType: CodeGenConnectionType.BELONGS_TO, targetNames: [ - 'sessionId' + 'conversationId' ] } }, - sender: { - name: 'sender', + role: { + name: 'role', isArray: false, type: { - enum: 'ConversationMessageSender' + enum: 'ConversationParticipantRole' }, isRequired: false, attributes: [] }, content: { name: 'content', - isArray: false, - type: 'String', + isArray: true, + type: { nonModel: 'ContentBlock' }, isRequired: false, attributes: [] }, @@ -421,7 +421,7 @@ export class AppSyncModelIntrospectionVisitor< assistantContent: { name: 'assistantContent', isArray: false, - type: 'String', + type: { nonModel: 'ContentBlock' }, isRequired: false, attributes: [] }, @@ -489,8 +489,8 @@ export class AppSyncModelIntrospectionVisitor< }, nonModels: {}, enums: { - ConversationMessageSender: { - name: 'ConversationMessageSender', + ConversationParticipantRole: { + name: 'ConversationParticipantRole', values: ['user', 'assistant'], } }, @@ -506,8 +506,8 @@ export class AppSyncModelIntrospectionVisitor< name: `onCreateAssistantResponse${routeName}`, type: { model: `ConversationMessage${routeName}` }, arguments: { - 'sessionId': { - name: 'sessionId', + 'conversationId': { + name: 'conversationId', isArray: false, isRequired: true, type: 'ID',