Skip to content

Commit

Permalink
必須判定を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed Sep 6, 2023
1 parent 2f610d1 commit a9d5208
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions tools/base/EccubeValidationBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});

Expand All @@ -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
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions tools/base/EccubeValidationBuilder/src/JoiTranslationFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a9d5208

Please sign in to comment.