我是graphql中的新手并且有以下问题:
我用他们的照片查询所有客户,但是graphql服务器响应在照片对象上给我null。
如果我从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"],
});
}
}
};
答案 0 :(得分:0)
我的客户架构不好
以下是解决方案:
而不是照片我必须使用CustomerPhoto
const Customer = `
type Customer {
customerID: ID!
firstname: String
lastname: String
phone: String
email: String
CustomerPhoto: CustomerPhoto
}
type Query {
customers: [Customer]
}
`;