From 941a947da072acf39e2b027eeddbcf10d3148c13 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 26 Jul 2024 12:17:57 -0400 Subject: [PATCH] feat: update _parseListType (#229) * feat: update _parseListType * refactor: move directive check to parse method --- .vscode/settings.json | 5 +++++ packages/devtools/src/schema/parser.ts | 2 ++ packages/devtools/test/schema.test.ts | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7ca18de0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "undeployed" + ] +} \ No newline at end of file diff --git a/packages/devtools/src/schema/parser.ts b/packages/devtools/src/schema/parser.ts index c4ad8afd..4f9412ff 100644 --- a/packages/devtools/src/schema/parser.ts +++ b/packages/devtools/src/schema/parser.ts @@ -521,6 +521,7 @@ export class SchemaParser { hasCreateModel: boolean, ): DefinitionWithReferences { const list = directives.find((d) => d.name === 'list') + const immutable = directives.some((item) => item.name === 'immutable') if (list == null) { throw new Error(`Missing @list directive on list field ${fieldName} of object ${objectName}`) } @@ -534,6 +535,7 @@ export class SchemaParser { const definition: ListFieldDefinition = { type: 'list', required, + immutable, item: item.definition, maxLength: list.args.maxLength as number, } diff --git a/packages/devtools/test/schema.test.ts b/packages/devtools/test/schema.test.ts index 20e17e3c..15312da9 100644 --- a/packages/devtools/test/schema.test.ts +++ b/packages/devtools/test/schema.test.ts @@ -795,6 +795,7 @@ describe('schema parsing and compilation', () => { ) { uniqueValue: Int @immutable tag: String! @string(minLength: 1, maxLength: 100) + uniqueListValue: [Int] @list(maxLength: 5) @immutable } `), ).toMatchObject({ @@ -803,7 +804,7 @@ describe('schema parsing and compilation', () => { action: 'create', model: { name: 'ModelWithImmutableProp', - immutableFields: ['uniqueValue'], + immutableFields: ['uniqueValue', 'uniqueListValue'], accountRelation: { type: 'single' }, description: 'Test model with an immutable int property', schema: {