提问人:Peter Fox 提问时间:10/12/2023 更新时间:10/20/2023 访问量:33
@belongsToMany与@paginate
@belongsToMany with @paginate
问:
简单的模型,我们有一个用户,一个用户是主题的一部分。链接是通过数据透视表完成的。用户和主题都具有正确的关系。查询有效。但。现在我们需要向它添加分页。
type User {
id: ID!
uuid: String!
email: String!
api_token: String!
devices: [Device]
topics(
orderBy: _ @orderBy(
columns: ["created_at", "last_message_at"]
)
): [Topic] @belongsToMany @paginate(type: SIMPLE)
created_at: DateTime!
updated_at: DateTime!
}
type Topic {
uuid: String!
user_uuid: String!
title: String!
slug: String!
key: String!
last_message_at: DateTime!
}
extend type Query @guard {
me: User @auth
}
在架构上方,当我们从用户中删除@paginate时,它无需分页即可工作。现在我们需要对此进行分页。
这是我们的 GraphQL 查询:
{
me {
email
topics {
title
last_message_at
}
}
}
我们收到以下错误:
Node topics can only have one directive of type Nuwave\\Lighthouse\\Support\\Contracts\\FieldResolver but found [@belongsToMany, @paginate].",
答:
0赞
francisco
10/20/2023
#1
该指令有一个带有 的键,您可以在其中使用 用于分页。@belongsToMany()
type
enum BelongsToManyType
SIMPLE
下面是指令 blob 信息。
评论
@belongsToMany(type:SIMPLE)
@paginate