【发布时间】:2021-02-07 22:14:44
【问题描述】:
大约 24 小时以来,我一直在努力找出我做错了什么,所以我终于想我会崩溃并问你们所有优秀的人,如果你发现有什么不对劲的地方。
我的 Apollo 服务器运行良好,我的 getUser GraphQL 查询运行良好,但我无法让 getFosseReport 查询运行,出现上述错误(提供了屏幕截图)。
首先,我的 typedefs.graphql 文件显示了我的 FosseReport 类型,以及 getFosseReport 查询:
type Query {
getUser(email: String!): User
getCurrentUser: User
getFosseReport(facility_id: String!, report_date: String!): FosseReport
}
type Token {
token: String!
}
type FosseReport {
_id: ID
facility_id: String!
report_date: String!
reports: [FosseItems]
created_date: String
modified_date: String
}
type FosseItems {
account_desc: String
fytd_cgs: String
fytd_credit: String
fytd_debit: String
ptd_cgs: String
ptd_credit: String
ptd_debit: String
seq_cg_cd: String
today_cgs: String
today_credit: String
today_debit: String
}
type User {
_id: ID
email: String!
password: String!
facility_id: String!
}
我的带有 getFosseReport 查询的解析器文件:
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const createToken = (user, secret, expiresIn) => {
const { username, email } = user;
return jwt.sign({username, email}, secret, {expiresIn});
};
module.exports = {
Query: {
getUser: async (_, {email}, {User}) => {
const user = await User.findOne({email});
if(user) {
return user;
}
return "None Found";
},
getFosseReport: async(_, {facility_id, report_date}, {FosseReport}) => {
const fosseReport = await FosseReport.findOne();
if(!fosseReport) {
return null;
}
return fosseReport;
},
getCurrentUser: async (_, args, { User, currentUser }) => {
if(!currentUser) {
return null;
}
const user = await User.findOne({email: currentUser.email});
return user;
}
},
}
带有错误消息的游乐场查询:
最后是 getFosseReport 查询的 Docs,它显示了诸如 FosseReport 的返回类型之类的所有内容:
我确定我在这里遗漏了一些愚蠢的东西,但如果你们有任何建议,我将不胜感激。
编辑:忘记显示我的猫鼬模型,也用于 FosseReport:
const mongoose = require('mongoose');
const FosseReportSchema = new mongoose.Schema({
facility_id: {
type: String
},
report_date: {
type: Date
},
reports: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: "FosseReportPart"
},
created_date: {
type: Date,
default: Date.now
},
modified_date: {
type: Date,
default: Date.now
}
});
module.exports = mongoose.model('FosseReport', FosseReportSchema);
【问题讨论】:
-
您好,请不要在图片中发布代码或示例数据,图片无法搜索,因此对未来的读者没有用处,也无法复制粘贴到编辑器中进行编译为了重现问题。
-
对不起!我会尝试将所有内容更改为代码,但是对于某些代码,它运行得不是很好,并且不确定如何将 GraphQL 操场上的东西发布为代码......让我尝试编辑一些东西来制作它更适合这个论坛。
标签: javascript graphql apollo