子查询上的GraphQL查询参数



我正在将Lighthouse与GraphQL一起使用,并试图找出如何将参数传递到关系中(我有一种感觉,我没有使用正确的术语(。

我得到的是:


type Entry {
id: ID!
site_id: ID
slug: String!
admin_note: String
type: String!
sub_type: String
content(status: String): EntryContent @hasOne
versions: [EntryContent!]! @hasMany
magazineIssues: [MagazineIssue]! @belongsToMany
contentPackages: [ContentPackage]! @belongsToMany
published_at: DateTime
created_at: DateTime
updated_at: DateTime
deleted_at: DateTime
}
# Query
entries(first: Int!, page: Int, type: String @eq, site_id: ID @eq, status: String): [Entry!]! @paginate
export const ALL_SITE_ENTRIES = gql`
query Entries($first: Int!, $page: Int, $type: String, $site_id: ID, $status: String) {
entries(first: $first, page: $page, type: $type, site_id: $site_id, status: $status) {
data {
...EntryDetails
content(status: $status) {
id
title
status
}
}
paginatorInfo {
currentPage
lastPage
total
}
}
}
${EntryDetailsFragment}
`

我正在使用分页来查询条目,但我需要传入一个特定内容状态的参数。我尝试了上面的一个,但我得到了错误:

message: "Fields "content" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional."

但我不明白为什么我需要这样的参数的别名。有没有办法将参数传递到关系/查询中?

谢谢!

因此,经过疯狂的尝试和错误,我想出了某种解决方案,却发现我们的Laravel关系并没有完全恢复原状。然而,对于任何想要了解如何查询嵌套关系的人来说,这里有一个适用于不同列的好例子:

extend type Query {
entries(first: Int!, 
page: Int, 
type: String @eq, 
site_id: ID @eq,
hasContent: _ @whereHasConditions(relation: "content", columns: ["title"])
): [Entry!]! @paginate
}

export const ALL_SITE_ENTRIES = gql`
query Entries($first: Int!, $page: Int, $type: String, $site_id: ID, $title: Mixed) {
entries(
first: $first, 
page: $page, 
type: $type, 
site_id: $site_id, 
hasContent: {column: TITLE, operator: LIKE, value: $title}
) {
data {
...EntryDetails
content{
id
title
status
}
}
paginatorInfo {
currentPage
lastPage
total
}
}
}
${EntryDetailsFragment}
`

注意:要获得完整的LIKE体验,请确保在搜索的文本周围添加%%。

希望这能帮助到别人。我真的需要更多的例子。:(

最新更新