JVM*_*JVM 1 mongodb node.js graphql apollo-server react-apollo
我正在学习 graphQL。有人可以帮助我理解为什么架构中没有识别突变吗?
出现此错误:
Error: "Mutations" defined in resolvers, but not in schema
Run Code Online (Sandbox Code Playgroud)
以下是代码:
架构:
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;
Run Code Online (Sandbox Code Playgroud)
解析器:
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;
Run Code Online (Sandbox Code Playgroud)