Skip to content

Commit 1844625

Browse files
committed
split call attempt
1 parent db61a36 commit 1844625

File tree

4 files changed

+101
-27
lines changed

4 files changed

+101
-27
lines changed

packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"inputs": {
2828
"$ref": "#/definitions/SchemaInputs"
2929
},
30-
"conversationRoutes": {
30+
"conversations": {
3131
"$ref": "#/definitions/SchemaConversationRoutes"
3232
}
3333
},
@@ -588,6 +588,9 @@
588588
"SchemaConversationMessage": {
589589
"type": "object",
590590
"properties": {
591+
"list": {
592+
"$ref": "#/definitions/SchemaQuery"
593+
},
591594
"subscribe": {
592595
"$ref": "#/definitions/SchemaSubscription"
593596
},
@@ -596,6 +599,7 @@
596599
}
597600
},
598601
"required": [
602+
"list",
599603
"subscribe",
600604
"send"
601605
],

packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
mutations?: SchemaMutations;
2020
subscriptions?: SchemaSubscriptions;
2121
inputs?: SchemaInputs;
22-
conversationRoutes?: SchemaConversationRoutes;
22+
conversations?: SchemaConversationRoutes;
2323
};
2424
/**
2525
* Top-level Entities on a Schema
@@ -46,6 +46,7 @@ export type SchemaConversation = {
4646
}
4747

4848
export type SchemaConversationMessage = {
49+
list: SchemaQuery;
4950
subscribe: SchemaSubscription;
5051
send: SchemaMutation;
5152
}

packages/appsync-modelgen-plugin/src/validate-cjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { GraphQLSchema } from "graphql";
33
import { Argument, AssociationType, Field, Fields, FieldType, ModelAttribute, ModelIntrospectionSchema, PrimaryKeyInfo, SchemaEnum, SchemaModel, SchemaMutation, SchemaNonModel, SchemaQuery, SchemaSubscription, Input, InputFieldType, SchemaConversationRoute } from "../interfaces/introspection";
44
import { METADATA_SCALAR_MAP } from "../scalars";
55
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";
78

89
const validateModelIntrospectionSchema = require('../validate-cjs');
910

@@ -80,11 +81,12 @@ export class AppSyncModelIntrospectionVisitor<
8081
}
8182
return { ...acc, [mutationObj.name]: this.generateGraphQLOperationMetadata<CodeGenMutation, SchemaMutation>(mutationObj) };
8283
}, {});
83-
const conversationRoutes = Object.values(this.mutationMap).reduce((acc, mutationObj: CodeGenMutation) => {
84+
const conversations = Object.values(this.mutationMap).reduce((acc, mutationObj: CodeGenMutation) => {
8485
if (!mutationObj.directives.find((directive) => directive.name === 'conversation')) {
8586
return acc;
8687
}
87-
return { ...acc, [mutationObj.name]: this.generateConversationMetadata(mutationObj) }
88+
const { route, inputs } = this.generateConversationMetadata(mutationObj)
89+
return { ...acc, [mutationObj.name]: route }
8890
}, {});
8991
const subscriptions = Object.values(this.subscriptionMap).reduce((acc, subscriptionObj: CodeGenSubscription) => {
9092
// Skip the field if the field type is union/interface
@@ -104,8 +106,8 @@ export class AppSyncModelIntrospectionVisitor<
104106
if (Object.keys(mutations).length > 0) {
105107
result = { ...result, mutations };
106108
}
107-
if (Object.keys(conversationRoutes).length > 0) {
108-
result = { ...result, conversationRoutes }
109+
if (Object.keys(conversations).length > 0) {
110+
result = { ...result, conversations }
109111
}
110112
if (Object.keys(subscriptions).length > 0) {
111113
result = { ...result, subscriptions };
@@ -245,21 +247,22 @@ export class AppSyncModelIntrospectionVisitor<
245247
return operationMeta as V;
246248
}
247249

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 = {
250253
conversation: {
251254
create: {
252-
name: `createConversation${mutationObj.name}`,
255+
name: `createConversation${routeName}`,
253256
isArray: false,
254257
type: {
255-
model: `Conversation${mutationObj.name}`
258+
model: `Conversation${routeName}`
256259
},
257260
isRequired: false,
258261
},
259262
get: {
260-
name: `getConversation${mutationObj.name}`,
263+
name: `getConversation${routeName}`,
261264
isArray: false,
262-
type: { model: `Conversation${mutationObj.name}` },
265+
type: { model: `Conversation${routeName}` },
263266
isRequired: false,
264267
arguments: {
265268
'id': {
@@ -271,9 +274,9 @@ export class AppSyncModelIntrospectionVisitor<
271274
}
272275
},
273276
delete: {
274-
name: `deleteConversation${mutationObj.name}`,
277+
name: `deleteConversation${routeName}`,
275278
isArray: false,
276-
type: { model: `Conversation${mutationObj.name}` },
279+
type: { model: `Conversation${routeName}` },
277280
isRequired: false,
278281
arguments: {
279282
'id': {
@@ -285,27 +288,21 @@ export class AppSyncModelIntrospectionVisitor<
285288
}
286289
},
287290
list: {
288-
name: `listConversation${mutationObj.name}`,
291+
name: `listConversation${routeName}`,
289292
isArray: true,
290293
type: {
291-
model: `Conversation${mutationObj.name}`
294+
model: `Conversation${routeName}`
292295
},
293296
isRequired: false,
294297
}
295298
},
296299
message: {
297300
send: this.generateGraphQLOperationMetadata<CodeGenMutation, SchemaMutation>(mutationObj),
298-
// send: {
299-
// name: mutationObj.name,
300-
// isArray: false,
301-
// type: 'String',
302-
// isRequired: false,
303-
// },
304301
subscribe: {
305302
isArray: false,
306303
isRequired: false,
307-
name: `onAssistantMessageResponse${mutationObj.name}`,
308-
type: { model: `ConversationMessage${mutationObj.name}` },
304+
name: `onAssistantMessageResponse${routeName}`,
305+
type: { model: `ConversationMessage${routeName}` },
309306
arguments: {
310307
'sessionId': {
311308
name: 'sessionId',
@@ -314,10 +311,82 @@ export class AppSyncModelIntrospectionVisitor<
314311
type: 'ID',
315312
},
316313
}
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+
}
317344
}
318345
}
319346
};
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 };
321390
}
322391

323392
protected getType(gqlType: string): FieldType | InputFieldType | UnionFieldType | InterfaceFieldType {

0 commit comments

Comments
 (0)