我正在使用 Strapi 构建 Graphql api。这是一个简单的应用程序,用户可以注册并保存他/她的一些信息。我有两个表,用户[由 Strapi 提供]和个人资料,我用它来存储用户附加信息。两个表有关系
用户 [User has and belongs to one Profile]
轮廓 Profile has and belongs to one User和接触部件结构。
我希望能够从配置文件表中获取当前登录的用户及其信息,但我保存为组件类型的联系人字段返回 null。
这是我到目前为止正在做的事情
扩展/用户权限/config/schema.graphql.js
module.exports = {
definition: `
extend type UsersPermissionsMe {
profile: ProfileMe
}
type ProfileMe {
id: ID!
website: String!
description: String!
contact: ContactMe
}
type ContactMe {
id: ID!
name: String!
phone: String!
email: String!
}
`
}
Run Code Online (Sandbox Code Playgroud)
扩展/用户权限/服务/User.js
'use strict';
module.exports = {
fetchAuthenticatedUser(id) {
return strapi.query('user', 'users-permissions').findOne({ id }, ['role', 'profile']);
},
};
Run Code Online (Sandbox Code Playgroud)
当运行 GraphQl 查询时
query {
me {
username
email
profile {
website
description
contact {
name
phone
email
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它回来了
{
"data": {
"me": {
"username": "company",
"email": "company@test.com",
"profile": {
"website": "http://localhost.com",
"description": "lorem text",
"contact": null
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还想在这里获取联系方式。我希望互联网上的人可以帮助我。请帮忙,谢谢。
| 归档时间: |
|
| 查看次数: |
499 次 |
| 最近记录: |