使用http.get的Graphql查询失败

时间:2017-11-18 00:03:42

标签: angularjs http graphql

我正在尝试将简单的graphql查询传递给我的http.get。这里有两个问题:id不接受empID,请求失败。请指教

以下是代码:

EmployeeService.prototype.getEmployee = function(empID) {
 let deferred = ij.q.defer();

  // Get the endpoint.
  const myQuery = `{
    employee(id: {empID}) {
      id
      items {
        nodes {
          id
          name
        }
      }
    }
  }`;
  const gql = 'graphql';
  const queryURL = `${gql}?query=${encodeURI(myQuery)}`;

  $http.get(queryURL).then((response) => {
    let result = response && response.data;
    if (result) {
      deferred.resolve(result);
    } 
  }, (reason) => {
  });
  return deferred.promise;
};

0 个答案:

没有答案