【问题标题】:Getting Error: "Mutations" defined in resolvers, but not in schema出现错误:解析器中定义了“突变”,但架构中没有
【发布时间】: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


    【解决方案1】:

    如错误所示,您的架构中没有名为 Mutations 的类型。它被命名为Mutation。解析器映射中的任何类型和/或字段都必须与您的架构完全匹配。

    【讨论】:

      猜你喜欢
      • 2020-02-24
      • 2019-09-26
      • 2022-11-26
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      相关资源
      最近更新 更多