Change mutaion definition for single types

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-01-30 15:50:31 +01:00
parent 0285c7bd96
commit 900cec28f4
2 changed files with 23 additions and 1 deletions

View File

@ -498,10 +498,17 @@ const buildMutation = ({ model, action }, { _schema }) => {
};
}
const { kind } = model;
let mutationDef = `${mutationName}(input: ${mutationName}Input)`;
if (kind === 'singleType' && action === 'delete') {
mutationDef = mutationName;
}
return {
definition,
mutation: {
[`${mutationName}(input: ${mutationName}Input)`]: `${mutationName}Payload`,
[mutationDef]: `${mutationName}Payload`,
},
resolvers: {
Mutation: {

View File

@ -291,6 +291,8 @@ module.exports = {
const singularName = toSingular(name);
const inputName = toInputName(name);
const { kind } = model;
switch (action) {
case 'create':
return `
@ -298,11 +300,24 @@ module.exports = {
type ${mutationName}Payload { ${singularName}: ${model.globalId} }
`;
case 'update':
if (kind === 'singleType') {
return `
input ${mutationName}Input { data: edit${inputName} }
type ${mutationName}Payload { ${singularName}: ${model.globalId} }
`;
}
return `
input ${mutationName}Input { where: InputID, data: edit${inputName} }
type ${mutationName}Payload { ${singularName}: ${model.globalId} }
`;
case 'delete':
if (kind === 'singleType') {
return `
type ${mutationName}Payload { ${singularName}: ${model.globalId} }
`;
}
return `
input ${mutationName}Input { where: InputID }
type ${mutationName}Payload { ${singularName}: ${model.globalId} }