Apollo Angular返回空数据,而Postman请求使用相同的查询返回正确的数据

时间:2019-10-29 10:51:23

标签: angular graphql apollo

我目前在Apollo Angular Client上遇到问题,因为当我引入一些查询以从我的graphql端点获取结果时,它将返回200响应,但返回空数据。

这是我用来获取数据的代码。

  const query = gql`
  { 
    KPI (label: "RejectionRatio") {
        definedIn sourceField computedBy series {
            fromDate toDate value

        }

    } 

}
  `;

  return this.apollo.query({query}).pipe(
    tap(v => console.log('v',v)),
    map(result => result.data),
  );
}

这是请求有效负载。我不知道类型名称是否会自动添加,但这是我能找到的唯一区别。

{
    "operationName":null,
    "variables":{},
    "query":"{
        KPI(label: \"RejectionRatio\") {
            definedIn
            sourceField
            computedBy
            series {
                fromDate
                toDate
                value
                __typename
            }
            __typename
        }
    }
}

还有回应。

response

{"data":[]}

有趣的是,当我尝试在邮递员中使用相同的端点并选择GraphQL作为正文类型时,我正在获取正确的数据。我附加了整个页面的图像,以便您查看。

{"data":[{"definedIn":"Number of claims rejected within 24h","sourceField":["Claim Rejected Date","Claim Identifier","Claim Status"],"computedBy":"n(claim rejected date OR claim status is rejected)/n(claims with identifier)","series":[{"fromDate":"2019-10-01","toDate":"2019-10-02","value":"3"},{"fromDate":"2019-10-07","toDate":"2019-10-08","value":"3"},{"fromDate":"2019-10-06","toDate":"2019-10-07","value":"4"},{"fromDate":"2019-10-03","toDate":"2019-10-04","value":"5"},{"fromDate":"2019-10-15","toDate":"2019-10-16","value":"4"},{"fromDate":"2019-10-09","toDate":"2019-10-10","value":"1"},{"fromDate":"2019-10-08","toDate":"2019-10-09","value":"4"},{"fromDate":"2019-10-12","toDate":"2019-10-13","value":"2"},{"fromDate":"2019-10-10","toDate":"2019-10-11","value":"2"},{"fromDate":"2019-10-04","toDate":"2019-10-05","value":"5"},{"fromDate":"2019-10-13","toDate":"2019-10-14","value":"3"},{"fromDate":"2019-10-14","toDate":"2019-10-15","value":"3"},{"fromDate":"2019-10-05","toDate":"2019-10-06","value":"3"},{"fromDate":"2019-10-02","toDate":"2019-10-03","value":"4"},{"fromDate":"2019-10-11","toDate":"2019-10-12","value":"5"}]}]}

Payload

非常感谢您所做的一切。 亲切的问候。 哈维尔

0 个答案:

没有答案