From a9d5208171b3581e803d71e76aabd3970a054786 Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:41:13 +0900 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E9=A0=88=E5=88=A4=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/base/EccubeValidationBuilder/index.js | 8 ++++++-- .../src/GenerateAutoValidationFileToDucks.js | 4 +++- .../src/JoiTranslationFile.json | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/base/EccubeValidationBuilder/index.js b/tools/base/EccubeValidationBuilder/index.js index 7e571ae..4b93340 100644 --- a/tools/base/EccubeValidationBuilder/index.js +++ b/tools/base/EccubeValidationBuilder/index.js @@ -66,7 +66,9 @@ class EccubeValidationBuilder { const mutationArguments = mutationQLData.map(field => { return { name: field.name, - type: field?.type?.ofType?.name ?? field.type.name + type: field?.type?.ofType?.name ?? field.type.name, + required: field.type.kind === 'NON_NULL', + // required_kind: field.type.kind // for debug } }); @@ -83,7 +85,9 @@ class EccubeValidationBuilder { return type.inputFields.map(field => { return { name: field.name, - type: field?.type?.ofType?.name ?? field.type.name + type: field?.type?.ofType?.name ?? field.type.name, + required: field.type.kind === 'NON_NULL', + // required_kind: field.type.kind // for debug } }); }); diff --git a/tools/base/EccubeValidationBuilder/src/GenerateAutoValidationFileToDucks.js b/tools/base/EccubeValidationBuilder/src/GenerateAutoValidationFileToDucks.js index 98d9ab5..be476e0 100644 --- a/tools/base/EccubeValidationBuilder/src/GenerateAutoValidationFileToDucks.js +++ b/tools/base/EccubeValidationBuilder/src/GenerateAutoValidationFileToDucks.js @@ -80,7 +80,9 @@ class GenerateAutoValidationFileToDucks { for (const MutationField of MutationFields) { console.log(jsonConversionFile); console.log(MutationField.type); - JoiValidationFileConstructor += jsonConversionFile.fields[MutationField.type].replace('{FIELD_NAME}', MutationField.name); + JoiValidationFileConstructor += jsonConversionFile.fields[MutationField.type] + .replace('{FIELD_NAME}', MutationField.name) + .replace('{REQUIRED}', MutationField.required ? '.required()' : ''); } JoiValidationFileConstructor += jsonConversionFile.end_tag; diff --git a/tools/base/EccubeValidationBuilder/src/JoiTranslationFile.json b/tools/base/EccubeValidationBuilder/src/JoiTranslationFile.json index 098c5cd..f339816 100644 --- a/tools/base/EccubeValidationBuilder/src/JoiTranslationFile.json +++ b/tools/base/EccubeValidationBuilder/src/JoiTranslationFile.json @@ -2,12 +2,12 @@ "comment_text": "// ################# \r\n // ### 注意:自動生成されたファイルのため、このファイルを編集しないでください ### \r\n // ################# \r\n", "import_text" : "\r\n import Joi from \"joi\"; \r\n", "fields" : { - "Int": "{FIELD_NAME} : Joi.number().required(),\r\n", - "String": "{FIELD_NAME} : Joi.string().required(),\r\n", - "Boolean": "{FIELD_NAME} : Joi.boolean().required(),\r\n", - "Date": "{FIELD_NAME} : Joi.date().required(),\r\n", - "DateTime": "{FIELD_NAME} : Joi.date().required(),\r\n", - "ID": "{FIELD_NAME} : Joi.number().required(),\r\n" + "Int": "{FIELD_NAME} : Joi.number(){REQUIRED},\r\n", + "String": "{FIELD_NAME} : Joi.string(){REQUIRED},\r\n", + "Boolean": "{FIELD_NAME} : Joi.boolean(){REQUIRED},\r\n", + "Date": "{FIELD_NAME} : Joi.date(){REQUIRED},\r\n", + "DateTime": "{FIELD_NAME} : Joi.date(){REQUIRED},\r\n", + "ID": "{FIELD_NAME} : Joi.number(){REQUIRED},\r\n" }, "start_tag": "const {MODEL_NAME}Schema = Joi.object().keys({\r\n", "end_tag": "});\r\n"