如何解决Angular graphql在请求中添加回车符
似乎graphql正在将回车符添加到我的json请求中。它还添加了_typename,但是我在graphql.module.ts中使用addTypename:false删除了它。如何摆脱回车符?
在graphql.module.ts
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri}),cache: new InMemoryCache({
addTypename: false
}),};
}
在home.component.ts
import { Component,OnInit } from "@angular/core";
import { Apollo } from "apollo-angular";
import gql from "graphql-tag";
@Component({
selector: "app-home",templateUrl: "./home.component.html",styleUrls: ["./home.component.css"]
})
export class HomeComponent implements OnInit {
statemind: any[];
loading = true;
error: any;
constructor(private apollo: Apollo) {}
ngOnInit() {
this.apollo
.query<any>({
query: gql `{statemind{issue{person{firstname lastname}}}}`
})
.subscribe(
({ data,loading }) => {
this.statemind = data && data.statemind;
this.loading = loading;
},error => {
this.loading = false;
this.error = error;
}
);
}
}
我明白了
error: "Bad Request"
message: "JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token↵ at [Source: (PushbackInputStream); line: 1,column: 35]"
path: "/v1/graphql"
status: 400
如果我在Chrome的开发人员工具中的“网络”下查看,似乎在查询中添加了回车符:
operationName: null,variables: {},…}
operationName: null
query: "{↵ statemind {↵ issue {↵ person {↵ firstname↵ lastname↵ }↵ }↵ }↵}↵"
variables: {}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。