mongoose - 未知指令“唯一” - Mongoose 和 GraphQL
问题描述
我是 graphql 的新手,并试图在 graphql 中添加一个独特的模式,但遇到了这样的错误。
这是架构:
const mongoose = require('mongoose');
const { Schema } = mongoose;
const incidentSchema = new Schema({
incidentNumber: {type: String, required: true, unique: true},
releaseDate: {type: String, required: true}
});
module.exports = mongoose.model('Incident', incidentSchema);
在 graphql 突变中:
addIncident: {
type: IncidentType,
args: {
incidentNumber: { type: GraphQLString },
releaseDate: { type: GraphQLString }
},
resolve(parent, args) {
let incident = new Incident({
incidentNumber: args.incidentNumber,
releaseDate: args.releaseDate
});
return incident.save();
}
}
不知道这个问题需要做什么
解决方案
当使用服务器不支持的指令进行查询时,通常会返回此错误消息。听起来您的查询包含该@unique
指令,但没有在服务器端定义这样的指令。您可以查看 API 的文档以查看支持哪些指令。也可以运行自省查询来获取该信息:
query GetDirectives {
__schema {
directives {
name
description
locations
args {
name
description
defaultValue
type {
name
}
}
}
}
}
推荐阅读
- httpclient - 调用 1 次时方法名称的预期失败是“创建”
- html - 在同一行对齐 figcaption 和 figure 标签
- jquery - 如何在 SignalR 的 accessTokenFactory 中异步传递更新的令牌?
- prometheus - 普罗米修斯的灭霸查询器重复数据删除问题
- cgal - 使用 CGAL 内置数字类型
- django - 博客:如何创建一个博客,在其中可以加载我想要的任何 JS/CSS 文件并将其格式化为我想要的任何布局?
- postgresql - 使用 pbbackrest 进行异常大的增量备份
- javascript - 如何从插件更改 Grid.js 状态?
- r - 在ggplot中绘制3D环形
- javascript - Microsoft Teams 自定义选项卡应用程序 - 地理位置问题