laravel-graphql滤波器查询
如何定义仅显示发布帖子的帖子查询?
我不想在情况下使用这样的情况
。
posts(@where(operator: "=", "publish", "1")): [Post!]! @paginate
我希望服务器帖子的查询仅在默认情况下仅发布发布的帖子
客户端:
$: posts = queryStore({
client: getContextClient(),
query: gql`
query ($first: Int!, $page: Int!) {
posts(first: $first, page: $page) {
data {
id
title
image
excerpt
slug
view
like
is_bookmarked
is_liked
author
postCategories {
id
title
}
}
paginatorInfo {
total
currentPage
lastPage
perPage
hasMorePages
}
}
}
`,
variables: { first, page },
requestPolicy: 'cache-and-network',
})
服务器架构:
type Query {
posts: [Post!]! @paginate
}
type PostComment{
id: ID!
post_id: ID!
user_id: ID
author: String
comment: String!
like: Int!
dislike: Int!
report_count: Int!
publish: Boolean!
is_liked: Boolean
is_bookmarked: Boolean
post: Post! @belongsTo
created_at: String
updated_at: String
}
type Post {
id: ID!
title: String!
slug: String!
view: Int!
like: Int!
body: String!
image: String
excerpt: String
author: String
publish: Boolean!
highlight: Boolean!
is_liked: Boolean
created_at: String
is_bookmarked: Boolean
postCategories: [PostCategory!]! @belongsToMany
postComments: [PostComment!]! @hasMany
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 laravel scopes 。在帖子模型中添加本地scepepepept:
然后通过@paginate :
you can use laravel scopes. Add a local scopePublished to the post model:
Then use it inside your schema by
@paginate
: