Skip to content

Commit 7cb219f

Browse files
author
Dane Pilcher
authored
fix: lazy codegen for schemas without relationships (#500)
1 parent 14774ee commit 7cb219f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ describe('Javascript visitor with default owner auth', () => {
368368
validateTs(declarations);
369369
expect(declarations).toMatchInlineSnapshot(`
370370
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
371+
// @ts-ignore
372+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
371373
372374
export enum SimpleEnum {
373375
ENUM_VAL1 = \\"enumVal1\\",
@@ -460,6 +462,8 @@ describe('Javascript visitor with custom owner field auth', () => {
460462
validateTs(declarations);
461463
expect(declarations).toMatchInlineSnapshot(`
462464
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
465+
// @ts-ignore
466+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
463467
464468
export enum SimpleEnum {
465469
ENUM_VAL1 = \\"enumVal1\\",
@@ -554,6 +558,8 @@ describe('Javascript visitor with multiple owner field auth', () => {
554558
validateTs(declarations);
555559
expect(declarations).toMatchInlineSnapshot(`
556560
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
561+
// @ts-ignore
562+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
557563
558564
export enum SimpleEnum {
559565
ENUM_VAL1 = \\"enumVal1\\",
@@ -638,6 +644,8 @@ describe('Javascript visitor with auth directives in field level', () => {
638644
validateTs(declarations);
639645
expect(declarations).toMatchInlineSnapshot(`
640646
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
647+
// @ts-ignore
648+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
641649
642650
type EagerEmployee = {
643651
readonly id: string;
@@ -713,6 +721,8 @@ describe('Javascript visitor with custom primary key', () => {
713721
validateTs(declarations);
714722
expect(declarations).toMatchInlineSnapshot(`
715723
"import { ModelInit, MutableModel, __modelMeta__, ManagedIdentifier, CompositeIdentifier, CustomIdentifier, OptionallyManagedIdentifier } from \\"@aws-amplify/datastore\\";
724+
// @ts-ignore
725+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
716726
717727
718728
@@ -943,6 +953,8 @@ describe('New model meta field test', () => {
943953
validateTs(declarations);
944954
expect(declarations).toMatchInlineSnapshot(`
945955
"import { ModelInit, MutableModel, __modelMeta__, ManagedIdentifier, OptionallyManagedIdentifier, CompositeIdentifier, CustomIdentifier } from \\"@aws-amplify/datastore\\";
956+
// @ts-ignore
957+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
946958
947959
948960

packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-javascript-visitor.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ export {
443443
444444
exports[`AppSyncJavascriptVisitor - GQLv2 Regression Tests Works on record creation and updating timestamp 2`] = `
445445
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
446+
// @ts-ignore
447+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
446448
447449
type TodoMetaData = {
448450
readOnlyFields: 'createdOn' | 'updatedOn';
@@ -777,6 +779,8 @@ export {
777779
778780
exports[`AppSyncJavascriptVisitor - GQLv2 Regression Tests Works when configuring a secondary index 2`] = `
779781
"import { ModelInit, MutableModel } from \\"@aws-amplify/datastore\\";
782+
// @ts-ignore
783+
import { LazyLoading, LazyLoadingDisabled } from \\"@aws-amplify/datastore\\";
780784
781785
type CustomerMetaData = {
782786
readOnlyFields: 'createdAt' | 'updatedAt';

packages/appsync-modelgen-plugin/src/visitors/appsync-typescript-visitor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AppSyncModelTypeScriptVisitor<
3535
];
3636

3737
protected BASE_DATASTORE_IMPORT = new Set(['ModelInit', 'MutableModel']);
38-
protected TS_IGNORE_DATASTORE_IMPORT = new Set();
38+
protected TS_IGNORE_DATASTORE_IMPORT = new Set(['LazyLoading', 'LazyLoadingDisabled']);
3939

4040
protected MODEL_META_FIELD_NAME = '__modelMeta__';
4141

@@ -299,8 +299,6 @@ export class AppSyncModelTypeScriptVisitor<
299299
const typeNameStr = this.generateModelTypeDeclarationName(modelType);
300300

301301
if (options?.lazy) {
302-
this.TS_IGNORE_DATASTORE_IMPORT.add('LazyLoading');
303-
this.TS_IGNORE_DATASTORE_IMPORT.add('LazyLoadingDisabled');
304302
if (field.isList) {
305303
this.TS_IGNORE_DATASTORE_IMPORT.add('AsyncCollection');
306304
} else {

0 commit comments

Comments
 (0)