【发布时间】:2021-12-25 08:40:53
【问题描述】:
我在 graphql 操场上遇到这个错误(下图)。 我也在解析器中检查了 objectId 的有效性。
// 型号
const ProposalSchema = new Schema({
cover
Letter: {
type: String,
},
budget: {
type: String,
},
proposals: {
type: mongoose.Schema.Types.ObjectId,
},
_id: {
type: mongoose.Schema.Types.ObjectId,
},
});
//解析器
还检查了如果使用 mongoose.isValidObjectId(proposser) 的参数有效,则返回 true
Query: {
proposals(_, args) {
const { proposser } = args;
return Proposal.findById({
proposser,
});
},
},
// 架构
const typeDefs = gql`
type Proposal {
_id: ID!
coverLetter: String
budget: String
proposser: ID!
}
`;
const Proposal = mongoose.model("Proposal", ProposalSchema);
【问题讨论】: