GraphQL Ajax 获取请求

GraphQL Ajax Get request

我正在尝试弄清楚如何编写 graphQL Ajax GET 请求。 当我在浏览器中输入 complete url 时,我会取回数据。

但是,当我想尝试通过 Ajax GET 方法获取数据时:

$.get({
  url: 'https://ltbliqkb1c.execute-api.eu-west-1.amazonaws.com/thomas/query?query=%7B%20book(id:%229789024576807%22)%20%7B%20bol%20%7B%20id%20%7D%20itunes%20%7B%20beschikbaar%20%7D%20%7D%7D',
    contentType: 'application/json',
    crossDomain:true,
     headers: {
        'Access-Control-Allow-Origin': 'https://ltbliqkb1c.execute-api.eu-west-1.amazonaws.com/',
        'Access-Control-Allow-Credentials': true
    }

}).done(function(response) {
  console.log('Data:', response.data);
});

我得到一个:

Failed to load https://ltbliqkb1c.execute-api.eu-west-1.amazonaws.com/thomas/query?query=%7B%20book(id:%229789024576807%22)%20%7B%20bol%20%7B%20id%20%7D%20itunes%20%7B%20beschikbaar%20%7D%20%7D%7D: Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

我的 Graphql 查询:

{
  book(id: "9789024576791") {
    bol {
      id
    }
    itunes {
      beschikbaar
    }
  }
}

我也试过以下js:

var test =  JSON.stringify('{book(id:"9789047202363"){bol{id}}}')
$.ajax({
     method: "GET",
          url: "https://ltbliqkb1c.execute-api.eu-west-1.amazonaws.com/thomas/query?"+test,
          contentType: "application/json",
          crossDomain:true,
          success: function(data) {     
               console.log('data',data);
          },
          error: function(err) {
               console.log(err);
          }
});

并使用以下变量进行字符串化:

var test= ` book($id: String!){
              bol{
                id,
                ean,
                mobileUrl,
                desktopUrl
              }
              itunes{
                beschikbaar
                auteur
                titel
              }
            }
          }`

设置headers回答为access-control-allow-origin:*