【发布时间】:2019-02-19 22:08:31
【问题描述】:
我正在使用 graphql 通过 Apollo 获取 API 值。我已成功下载 schema.json 并从 grpahql 获取值。但我无法获取 json 值的 values 数组。
这是我的示例回复:
{
"data": {
"team_Dashboard": {
"activeMission": "Food Mission",
"currentMissionChallenges": [
{
"id": "123",
"title": "Challenge",
"estTime": "5",
"location": "Anywhere",
"maxPts": "30",
"status": "Not yet started"
},
{
"id": "1234",
"title": " II Challenge",
"estTime": "5",
"location": "Anywhere",
"maxPts": "70",
"status": "Not yet started"
}
]
}
}
}
Graphql 查询:
query teamDashboard($teamId: ID!) {
team_Dashboard(teamId: $teamId) {
activeMission
currentMissionChallenges
}
}
Graphql 架构响应:
missionDeadLine: String
currentMissionChallenges: [JSON]
当我在我的 Graphql 查询中添加 currentMissionChallenges([JSON]) 时,会从服务器获取错误响应。但是当我从 Graphql 查询中删除 currentMissionChallenges 时,会从服务器获取成功响应和值。
问题是 currentMissionChallenges 是 [JSON] 格式。当我更改我的 graphql 查询 This is graphql Response
query teamDashboard($teamId: ID!) {
team_Dashboard(teamId: $teamId) {
activeMission
currentMissionChallenges {
id
title
estTime
location
maxPts
status
}
}
}
dashBord.grpahql 中显示以下错误
Field "currentMissionChallenges" must not have a selection since type "[JSON]" has no subfields.
如何从 graphql 获取 json 数组值。获取 Json 值有什么问题?请帮帮我!
【问题讨论】: