Add group inputs

This commit is contained in:
Alexandre Bodin 2019-07-17 13:40:35 +02:00
parent fbfe41e1d1
commit 07cca4139c
2 changed files with 22 additions and 10 deletions

View File

@ -193,12 +193,16 @@ const schemaBuilder = {
return acc; return acc;
}, definition); }, definition);
return `type ${globalId} {${this.formatGQL(gqlAttributes, {}, group)}}`; let type = `type ${globalId} {${this.formatGQL(
gqlAttributes,
{},
group
)}}\n`;
type += Types.generateInputModel(group, globalId);
return type;
}) })
.join('\n'); .join('\n');
console.log(groupDefs);
// Extract custom definition, query or resolver. // Extract custom definition, query or resolver.
const { const {
definition, definition,

View File

@ -76,12 +76,20 @@ module.exports = {
if (definition.type === 'group') { if (definition.type === 'group') {
const globalId = strapi.groups[definition.group].globalId; const globalId = strapi.groups[definition.group].globalId;
const typeId = definition.required === true ? `${globalId}!` : globalId; const { required, repeatable } = definition;
if (definition.repeatable === true) { let typeName = required === true ? `${globalId}` : globalId;
return `[${typeId}]!`;
if (rootType === 'mutation') {
typeName =
action === 'update'
? `edit${_.capitalize(globalId)}Input`
: `${_.capitalize(globalId)}Input${required ? '!' : ''}`;
} }
return `${typeId}`; if (repeatable === true) {
return `[${typeName}]`;
}
return `${typeName}`;
} }
const ref = definition.model || definition.collection; const ref = definition.model || definition.collection;
@ -203,8 +211,7 @@ module.exports = {
const globalId = model.globalId; const globalId = model.globalId;
const inputName = `${_.capitalize(name)}Input`; const inputName = `${_.capitalize(name)}Input`;
/* eslint-disable */ const inputs = `
return `
input ${inputName} { input ${inputName} {
${Object.keys(model.attributes) ${Object.keys(model.attributes)
.map(attribute => { .map(attribute => {
@ -232,7 +239,8 @@ module.exports = {
.join('\n')} .join('\n')}
} }
`; `;
/* eslint-enable */ console.log(inputs);
return inputs;
}, },
generateInputPayloadArguments: function(model, name, type, resolver) { generateInputPayloadArguments: function(model, name, type, resolver) {