我在graphql游乐场中遇到了这个错误(下图)。我也检查了解析器中objectId的有效性。
// model
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,
});
},
},// schema
const typeDefs = gql`
type Proposal {
_id: ID!
coverLetter: String
budget: String
proposser: ID!
}
`;
const Proposal = mongoose.model("Proposal", ProposalSchema);

发布于 2021-11-13 11:22:12
我在解析器中使用了错误的方法。findById用于字段非Id字段。
async proposals(_, args) {
const { proposser } = args;
const userProposals = await Proposal.find({
proposser,
});
try {
const result = userProposals;
return result ? result : [];
} catch (err) {
console.log(err);
}
},https://stackoverflow.com/questions/69952401
复制相似问题