在 Google App 脚本中使用 GraphQL 执行突变时出错
我设法使用下面类似的代码使用 Google App Script 来查询 GraphQL。 但是,当我更改为使用突变(下面的代码)时,它不起作用。
错误代码为 400,文本为:{"errors":[{"message":"GraphQL 操作必须包含非空 query
或 persistedQuery
扩展。"," Extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}
我刚刚开始学习 Google App Script & Javascript,在网上搜索了几个小时后不知道如何解决这个问题。一些帮助将不胜感激。提前致谢。
function get_auth_headers(){
email = "[email protected]"
password ="test"
var query = "mutation={ \
userLogin(input:{email:\"" + email + "\",password:\"" + password + "\"}){ \
token \
} \
}";
Logger.log(query)
var url1 = "https://server.matters.news/graphql?";
url = encodeURI(url1 + query)
Logger.log(url)
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true });
Logger.log("code: " + response.getResponseCode());
Logger.log("text: " + response.getContentText());
var response = UrlFetchApp.fetch(url,{method: 'GET', headers: {'Content-Type': 'application/json'}});
var lists = JSON.parse((response.getContentText()));
Logger.log(lists);
}
I managed to use similar code below for query GraphQL using Google App Script.
However, it's not working when I changed to use on mutation (code below).
Error code is 400 with text: {"errors":[{"message":"GraphQL operations must contain a non-empty query
or a persistedQuery
extension.","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}
I just started to learn Google App Script & Javascript, not sure how to resolve this issue after search few hours on the net. Some help would be appreciate. Thanks in advance.
function get_auth_headers(){
email = "[email protected]"
password ="test"
var query = "mutation={ \
userLogin(input:{email:\"" + email + "\",password:\"" + password + "\"}){ \
token \
} \
}";
Logger.log(query)
var url1 = "https://server.matters.news/graphql?";
url = encodeURI(url1 + query)
Logger.log(url)
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true });
Logger.log("code: " + response.getResponseCode());
Logger.log("text: " + response.getContentText());
var response = UrlFetchApp.fetch(url,{method: 'GET', headers: {'Content-Type': 'application/json'}});
var lists = JSON.parse((response.getContentText()));
Logger.log(lists);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设法从 https://speckle.guide/dev/js-app-script 得到答案.html
如果您遇到同样的问题,请参阅下面的代码供您参考。
Managed to get answer from https://speckle.guide/dev/js-app-script.html
Refers code below for your reference if you have same issue.