Closed
Description
Say I want to do the following:
mutation {
updateStudent(studentId: 5, input: $input) {
firstname,
lastname,
studentTags {
value
}
}
}
where $input =
{
firstname: 'joe',
lastname: 'cool',
studentTags: [{
value: 'summer 2016'
}]
}
My Student input definition is as follows:
new GraphQLInputObjectType({
name: 'StudentInput',
fields: {
firstname: {
type: GraphQLString
},
lastname: {
type: GraphQLString
},
email: {
type: GraphQLString
},
studentTags: {
type: new GraphQLList(StudentTagInput)
}
}
});
... and my mutation definition looks like this:
export default {
type: StudentObject,
args: {
studentId: {
type: new GraphQLNonNull(GraphQLInt)
},
input: {
type: StudentInput
}
},
resolve(_, {studentId, input}, context) {
return ACL.Common.enforceLoggedIn(context.user)
.then(() => Models.Student.update(context, studentId, input))
}
}
Is there any way to ease the concept of nested mutations in this case? Almost like having a resolve function attached to the StudentTagInputObject such that it runs whenever a student mutation happens, or having non-root mutations?
The only way I can see how to implement this is defining how the nested mutation will work within the resolve
function of the root mutation directly but could lead to duplicated code.
Thanks in advance! Hopefully my question makes sense
Metadata
Metadata
Assignees
Labels
No labels