Graphql 模式类型
我们可以将关注者和关注者的类型定义为用户吗?或者如果我只在关注者和追随者上创建不同的模式会更好吗?
type User {
id: ID!
name: String!
email: String!
posts: [Post!]
following: [User]
followers: [User]
}
Can we define the type of followers and following as User? or is it better if I will just create a differenct schema on both following and followers?
type User {
id: ID!
name: String!
email: String!
posts: [Post!]
following: [User]
followers: [User]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方式很好,没有任何问题。但是,如果您需要这些字段中的更多信息,您可以执行以下操作:
这允许您重用 User 类型,同时还可以合并与追随者。就像我说的,如果你不需要额外的信息,那么你的方法就可以了。祝你好运!
Your way is fine and there's nothing wrong with it. However, if you need more info in those fields you could do something like:
That allows you to reuse the User type while also incorporating additional information related to a follower. Like I said though, if you don't need that extra info then your way works fine. Good luck!