Skip to content

Commit a83595e

Browse files
committed
test: add unit test for 320
1 parent a05376a commit a83595e

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ const createAndGeneratePipelinedTransformerVisitor = (schema: string) => {
2424
return createAndGenerateVisitor(schema, true);
2525
};
2626

27-
const createGraphQLV2TransformerVisitor = (schema: string) => {
28-
const ast = parse(schema);
29-
const builtSchema = buildSchemaWithDirectives(schema);
30-
const visitor = new AppSyncModelVisitor(
31-
builtSchema,
32-
{ directives, target: 'general', isTimestampFieldsAdded: true, usePipelinedTransformer: true },
33-
{ generate: CodeGenGenerateEnum.code },
34-
);
35-
visit(ast, { leave: visitor });
36-
return visitor;
37-
}
38-
3927
describe('AppSyncModelVisitor', () => {
4028
it('should support schema with id', () => {
4129
const schema = /* GraphQL */ `
@@ -912,6 +900,13 @@ describe('AppSyncModelVisitor', () => {
912900

913901
describe.only('Graphql V2 fix tests for multiple has many relations of only one model type', () => {
914902
const schema = /* GraphQL*/ `
903+
type Registration @model {
904+
id: ID! @primaryKey
905+
meetingId: ID @index(name: "byMeeting", sortKeyFields: ["attendeeId"])
906+
meeting: Meeting! @belongsTo(fields: ["meetingId"])
907+
attendeeId: ID @index(name: "byAttendee", sortKeyFields: ["meetingId"])
908+
attendee: Attendee! @belongsTo(fields: ["attendeeId"])
909+
}
915910
type Meeting @model {
916911
id: ID! @primaryKey
917912
title: String!
@@ -922,21 +917,9 @@ describe('AppSyncModelVisitor', () => {
922917
id: ID! @primaryKey
923918
meetings: [Registration] @hasMany(indexName: "byAttendee", fields: ["id"])
924919
}
925-
926-
type Registration @model {
927-
id: ID! @primaryKey
928-
meetingId: ID @index(name: "byMeeting", sortKeyFields: ["attendeeId"])
929-
meeting: Meeting! @belongsTo(fields: ["meetingId"])
930-
attendeeId: ID @index(name: "byAttendee", sortKeyFields: ["meetingId"])
931-
attendee: Attendee! @belongsTo(fields: ["attendeeId"])
932-
}
933920
`;
934-
const outputModels: string[] = ['Meeting', 'Attendee', 'Registration'];
935-
outputModels.forEach(model => {
936-
it(`should not throw error when processing ${model}`, () => {
937-
const visitor = createGraphQLV2TransformerVisitor(schema);
938-
expect(() => visitor.generate()).not.toThrow();
939-
});
940-
})
921+
it(`should not throw error when processing models`, () => {
922+
expect(() => createAndGeneratePipelinedTransformerVisitor(schema)).not.toThrow();
923+
});
941924
})
942925
});

0 commit comments

Comments
 (0)