【发布时间】:2020-08-20 04:35:33
【问题描述】:
我正在尝试使用 Apollo 获取一些数据。这是简单的查询:
export const CurrentUserForProfile = gql`
query getGroupDetails($groupId: Long, $groupType: String, $tags: [Tag]) {
nodes: NodesRelay (
first: 50
where: {
tags: { CONTAINS: $tags },
OR: {
AND: {
nsParentId: { EQ: $groupId }
nsParentType: { EQ: $groupType }
}
superGroupNodeLinks: {
groupId: { EQ: $groupId }
groupType: { EQ: $groupType }
}
}
}
) {
elements {
data {
...nodeFields
ext {
...nodeExtFields
}
}
}
pageInfo {
...pageInfoFields
}
}
}
fragment nodeFields on Node {
id {
id
type
}
subtype
internalId
businessId
scadaId
isGroup
isTemporary
nsParentId
nsParentType
ouId
description
shortDescription
status
isNsPowered
tags
owners
notes
version
}
fragment nodeExtFields on NodeExt {
id {
id
type
}
asParentId
asParentType
isAsPowered
isAsInconsistent
isAsPoweredInParallel
isAsPoweredByExtSource
isAsPoweredByDiffSource
maneuverId
entityStatusMap
createdAt
createdBy
updatedAt
updatedBy
version
}
fragment pageInfoFields on PageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
`;
我使用它的方式就像教程所说的那样:
this.data = this.apollo
.watchQuery({
query: CurrentUserForProfile,
variables: {
"groupId": 15,
"groupType": "sec_subst",
"tags": ["GIS"]
},
fetchResults: true,
returnPartialData: false,
}).valueChanges
.pipe(
map((res: any) => res.data.nodes.elements)
)
HTML:
<ng-container *ngFor="let a of data | async">
{{a.data.id.type}} <br>
</ng-container>
我得到的只是 10 行 "lv_line"。
如果我更改逻辑,订阅组件并执行console.log(data),我会看到同样的事情。这可能是正确的,但不是。我得到的数据是完全错误的,如果我在网络选项卡中检查,无论我的应用程序中的逻辑是什么,数据都是正确的,而不仅仅是具有属性 type 的 10 个元素的数组总是“lv_line”。
这是网络结果:
而 HTML 结果看起来像这样:
我做错了什么?我已经尝试了所有我能想到的方法,但都没有成功,一次又一次地得到同样的错误结果。
【问题讨论】: