【发布时间】:2019-12-21 12:52:02
【问题描述】:
我正在学习 graphQL。有人可以帮我理解为什么 Schema 中没有识别出突变吗?
得到这个错误:
Error: "Mutations" defined in resolvers, but not in schema
以下是代码:
架构:
const typeDefs = gql`
type Author {
age: String
name: String
books: [String]
}
type Query {
authors: [Author]
author(id: String): Author
}
type Mutation {
addAuthor(name: String, age: Int, books: [String]): Author
}
`;
const schema = makeExecutableSchema({ typeDefs, resolvers });
export default schema;
解析器:
const resolvers = {
Query: {
authors: () => {
// return authors;
},
author: (root, { id }) => {
// return authors.find(author => author.id === id);
}
},
Mutations: {
addAuthor: (root, {name, age, books}) => {
const author = new authorModel({name, age, books});
return author.save();
}
}
}
export default resolvers;
【问题讨论】:
标签: node.js mongodb graphql react-apollo apollo-server