Gatsby Source API服务器运行良好 . 有了这个在我的gatsby-config:
{
resolve: 'gatsby-source-apiserver',
options: {
typePrefix: 'community_education__',
url: `https://spreadsheets.google.com/feeds/list/1DLAVN3q758sPohCFeZlVSVRZKXzEser1SIsQnH2mvrw/ogwtdyp/public/basic?hl=en_US&alt=json`,
method: 'get',
name: `classes`,
entityLevel: `feed.entry`,
schemaType: classType,
localSave: true,
path: `${__dirname}/api/`,
verboseOutput: true,
}
}
它正确地下拉了我想要的数据 . 问题是我使用的API(谷歌)带来了以下属性:
{
"title": {
"type": "text",
"$t": "Computer Coding for Kids"
},
"content": {
"type": "text",
"$t": "district: Hopkins, days: Mon - Thurs, startdate: 6/11/2018, enddate: 6/14/2018, time: 9am - Noon, grades: 3rd, 4th, 5th, 6th Grades, description: Learn how to code through playing games and having fun! We'll learn the fundamentals of loops, if statements, and variables as we learn the blockly and python computer languages! Please come with internet navigation skills (basic typing and mouse control) and a passion to work hard and have fun!, link: https://hopkins.ce.eleyo.com/course/6064/youth-summer-2018/computer-coding-for-kids"
}
}
当我进行GraphQL查询时,可用的属性是 type
和 alternative__t
这实际上是可以的,除了 alternative__t
总是返回 null
.
这个查询:
{
allCommunityEducationClasses {
totalCount
edges {
node {
title {
type
alternative__t
}
content {
type
alternative__t
}
}
}
}
}
返回此结果:
{
"node": {
"title": {
"type": "text",
"alternative__t": null
},
"content": {
"type": "text",
"alternative__t": null
}
}
},
{
"node": {
"title": {
"type": "text",
"alternative__t": null
},
"content": {
"type": "text",
"alternative__t": null
}
}
},
我知道问题是 $t
,如果它是我自己的API,我可以更改响应名称属性,我会,但这是谷歌API . 我可以以某种方式重命名该属性吗?有没有办法使用转义字符来查询 $t
?
1 回答
好像图书馆正在检查特殊字符,但不是
$
. 通过在normalize.js
中将.replace
更改为.replace(/-|__|:|\$|\.|\s/g, '_');
,我能够在我的代码中修复它,这解决了我的问题 .我也提出了拉请求 . https://github.com/thinhle-agilityio/gatsby-source-apiserver/pull/1