【问题标题】:Not able to understand what this error means无法理解此错误的含义
【发布时间】:2019-07-13 05:56:45
【问题描述】:

enter image description here我正在尝试创建 graphql 模式指令并尝试将其添加到 makeExecutableSchema 中,并且出现以下错误。有没有人可以帮助我理解这个错误或解决它。

const templateDirective = require('../index');

// Define your schema and resolvers if needed

const typeDefs = `
  type Query {
    me(): Me @templateDirective
  }
`;

const resolvers = {
  Query: {
    me: () => false,
  },
};

module.exports = makeExecutableSchema({
  typeDefs,
  resolvers,
  schemaDirectives: {
    templateDirective,
  },
});

【问题讨论】:

  • 什么错误?请更新您的问题以包含完整的错误消息。
  • 对不起,我忘记添加错误的截图,我已经编辑了描述

标签: graphql graphql-js


【解决方案1】:

您的文档中有语法错误。如果一个字段没有参数,你必须省略括号,你不能只在字段名后面有一组空的括号。更正后的文件:

type Query {
  me: Me @templateDirective
}

【讨论】:

  • const typeDefs = ` type Query { me(id: Int): Me @directive } type Me { id: ID } `; 我添加了这个并且它有效。谢谢
猜你喜欢
  • 2019-08-22
  • 2015-04-25
  • 2022-06-15
  • 2011-05-13
  • 1970-01-01
  • 2022-06-19
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多