【发布时间】:2018-04-28 10:37:25
【问题描述】:
我想调用 API,获取 json 数据并将其设置为 Graphql 中的解析器查询。到目前为止,我设法使用 Graphql 服务器并调用 API。这是我到目前为止的代码
//resolvers.js
//var fetch = require('node-fetch');
var request = require("request");
var options = { method: 'GET',
url: 'http://mydomain.con/index.php/rest/V1/products/24-MB01',
headers:
{ 'postman-token': 'mytoken',
'cache-control': 'no-cache',
'content-type': 'application/json',
authorization: 'Bearer mytoken' } };
const links = request(options, function (error, response, body) {
if (error) throw new Error(error);
//body = json data
//console.log(body);
});
module.exports = {
Query: {
//set data to Query
allLinks: () => links,
},
};
我不知道如何将包含 json 数据的 body 参数设置为 Query。我在“http://localhost/src/apicall.php”上也有相同的数据,但这不适用于 node-fetch(或者我犯了错误)。 api来自magento2。
【问题讨论】:
标签: javascript php magento2 graphql