Generate different input for edit mutation

This commit is contained in:
Aurélien Georget 2018-11-26 17:36:49 +01:00
parent 4e23e872ed
commit 6fd3319f18

View File

@ -29,6 +29,7 @@ module.exports = {
modelName = '',
attributeName = '',
rootType = 'query',
action = ''
}) {
// Type
if (definition.type) {
@ -62,7 +63,7 @@ module.exports = {
break;
}
if (definition.required) {
if (definition.required && action !== 'update') {
type += '!';
}
@ -202,6 +203,21 @@ module.exports = {
})
.join('\n')}
}
input edit${inputName} {
${Object.keys(model.attributes)
.filter(attribute => model.attributes[attribute].private !== true)
.map(attribute => {
return `${attribute}: ${this.convertType({
definition: model.attributes[attribute],
modelName: globalId,
attributeName: attribute,
rootType: 'mutation',
action: 'update'
})}`;
})
.join('\n')}
}
`;
/* eslint-enable */
},
@ -224,7 +240,7 @@ module.exports = {
`;
case 'update':
return `
input ${type}${inputName} { where: InputID, data: ${inputName} }
input ${type}${inputName} { where: InputID, data: edit${inputName} }
type ${type}${payloadName} { ${pluralize.singular(name)}: ${
model.globalId
} }