我是graphql的新手,有以下问题:
I'm querying all customers with their photo but graphql server response give me null on photo object.
如果我尝试从Sequelize日志记录中执行RAW SQL语句并在我的sql客户端执行它给我正确的结果 .
我认为问题是在客户端的graphql中的某个地方,但我不知道在哪里 .
我没有在CustomerPhoto模式中添加字段 filetype 的自定义标量类型,但我不认为这是一个问题 .
//客户架构
import CustomerPhoto from "./customerPhoto";
const Customer = `
type Customer {
customerID: ID!
firstname: String
lastname: String
phone: String
email: String
photo: CustomerPhoto
}
type Query {
customers: [Customer]
}
`;
export default [Customer, CustomerPhoto];
// CustomerPhoto schema
const CustomerPhoto = `
type CustomerPhoto {
customerPhotoID: ID!
filename: String
filetype: BLOB
}
`;
export default CustomerPhoto;
这是我在grahpiQL中的查询:
{
customers {
firstname
phone
photo {
customerPhotoID
}
}
}
以下是查询的结果:
{
"data": {
"customers": [
{
"firstname": "Jade",
"phone": "993.588.1173 x0426",
"photo": null
},
{
"firstname": "Oleta",
"phone": "288-162-3631",
"photo": null
},
{
"firstname": "Geoffrey",
"phone": "742.195.2920 x40571",
"photo": null
},
{
"firstname": "Daphne",
"phone": "010.713.4911 x39353",
"photo": null
}
......
]
}
}
这是我的解析器:
const CustomerResolvers = {
Query: {
customers: (_, args) => {
return models.Customer.findAll({
include: {
model: models.CustomerPhoto,
attributes: ["customerPhotoID","filename"],
},
attributes: ["customerID","firstname", "lastname", "phone", "email"],
});
}
}
};
1 回答
我的客户架构不好
Here is the solution:
而不是照片,我不得不使用CustomerPhoto