var schema = buildSchema(`
type Query {
course(id: Int!): Course
courses(topic: String):[Course]
},
type Mutation {
updateCourseTopic(id: Int!, topic: String!): Course
}
type Course {
id: Int
title: String
author: String
description: String
topic: String
url: String
}
`);
// 省略
var updateCourseTopic = function({id, topic}){
coursesData.map(course => {
if(course.id === id){
course.topic = topic;
return course;
}
});
return coursesData.filter(course => course.id === id)[0];
}
var root = {
course: getCourse,
courses: getCourses,
updateCourseTopic: updateCourseTopic
};
$ node server2.js
mutation updateCourseTopic($id: Int!, $topic: String!) {
updateCourseTopic(id: $id, topic: $topic) {
... courseFields
}
}
fragment courseFields on Course {
title
author
description
topic
url
}
{
"id": 1,
"topic": "JavaScript"
}
何となく使い方はわかりました。
