Angular 图ql角突变显示;错误:网络错误:无法读取属性';长度';“无效”的定义;控制台中
我不熟悉graphql和angular,我的代码有一些问题 我想在我的数据库(注册页面)中存储一些数据,但我在控制台中不断收到此错误Angular 图ql角突变显示;错误:网络错误:无法读取属性';长度';“无效”的定义;控制台中,angular,graphql,apollo,apollo-client,graphql-js,Angular,Graphql,Apollo,Apollo Client,Graphql Js,我不熟悉graphql和angular,我的代码有一些问题 我想在我的数据库(注册页面)中存储一些数据,但我在控制台中不断收到此错误 ERROR Error: Network error: Cannot read property 'length' of null at new ApolloError (bundle.esm.js:63) at Object.error (bundle.esm.js:1030) at notifySubscription (Observable.js:134)
ERROR Error: Network error: Cannot read property 'length' of null
at new ApolloError (bundle.esm.js:63)
at Object.error (bundle.esm.js:1030)
at notifySubscription (Observable.js:134)
at onNotify (Observable.js:165)
at SubscriptionObserver.error (Observable.js:224)
at bundle.esm.js:869
at Set.forEach (<anonymous>)
at Object.error (bundle.esm.js:869)
at notifySubscription (Observable.js:134)
at flushSubscription (Observable.js:116)
这是test.component.ts代码
import { Component, OnInit } from '@angular/core';
import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent {
loading = true;
data: any;
constructor(private apollo: Apollo) {}
isEmpty(str) {
return (!str || 0 === str.trim().length);
}
newPost() {
this.apollo.mutate({
mutation: gql`mutation($email: String!, $role: String!, $password: String!, $fullname: String!, $username: String!, $Rpassword: String!) {
signUp(email: $email, role: $role, password: $password, fullname: $fullname, username: $username, Rpassword: $Rpassword) {
token
}
}
`,
variables: {
username:"sfefs",
email: "car@gmail.com",
password: "XYZ01-uy92",
Rpassword: "XYZ01-uy92",
fullname: "XYZ",
role: "GUEST"
}
})
.subscribe(data => {
console.log('New post created!', data);
});
}
}
我不知道我做错了什么,如何解决这个问题,以及如何显示后端的错误您不应该将标题设置为
null
,而是将其设置为空字符串:
localStorage.getItem('token') || ''
这听起来像是与
@auth0/angular jwt
有关,而不是与apollo client
有关。它与@auth0/angular jwt而不是apollo client的关系如果我知道的话,我会提供完整的答案而不是评论。但是在任何Apollo库中都没有tokenGetter
属性,在@auth0/angular jwt
中也有一个属性。我不使用该库,因此无法提供任何进一步的帮助。好的,我删除了@auth0/angular jwt,现在出现错误“网络错误:无法读取null的属性'length'”
localStorage.getItem('token') || ''