gpt4 book ai didi

graphql - 网络错误 : Response not successful: Received status code 400

转载 作者:行者123 更新时间:2023-12-04 10:19:44 26 4
gpt4 key购买 nike

我脑子坏了。为什么服务器发送此错误。我查看了所有具有相同错误的文章,但没有找到解决方案。问题是什么?我该如何解决这个错误?请帮忙。我的代码。

App.jsx这是 Apollo Client 的客户端

const client = new ApolloClient({
uri: "http://localhost:4000/api/",
request: (operation) => {
const token = localStorage.getItem("token");

operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : ""
}
});
}
});

signUp.js这是 sighUp 的突变

import { gql } from "apollo-boost";

export default gql`
mutation signup($firstName: String!, $secondName: String!, $email: String!, $password: String! ) {
signup(firstName: $firstName, secondName: $secondName, email: $email, password: $password )
}
`;

RegForm.jsx是我的组件注册

import React, {Component} from 'react'
import {Field, reduxForm, SubmissionError} from 'redux-form'
import regForm from './RegForm.module.css'
import { matchInput, passLength, email, required} from '../../../utils/validators'

import RegMutation from '../../../queries/signup'
import Button from '../../../UI/Button/Button'
import myInput from '../../../UI/Input/Input'
import { withMutation } from "react-apollo";

const passwordValidator = passLength(8);


class RegForm extends Component {
constructor(props){
super(props)

this.handleSubmit = this.handleSubmit.bind(this);
}

handleSubmit(fields) {
console.log('Fields from handleSubmit',fields);

const { mutate } = this.props;

return new Promise((resolve, reject) => {
mutate({
variables: {
firstName: fields.loginField,
email: fields.email,
password: fields.passwordField
}
})
.then(res => {
console.log(res.data);
resolve(res);
})
.catch(e => {
reject(new SubmissionError({ _error: e?.message }));
});
});
}

render(){
return (
<div>
<form
className={regForm.formContent}
onSubmit={this.props.handleSubmit(this.handleSubmit)}
>

<Field
name='loginField'
type='text'
component={myInput}
validate={[required]}

/>
<Field
name='email'
type='text'
component={myInput}
validate={[email]}

/>
<Field
name='passwordField'
type='password'
component={myInput}
validate={[passwordValidator]}
placeholderText='Введите пароль'
/>
<Field
name='repPas'
type='password'
component={myInput}
validate={[matchInput]}

/>
<Button
onClick={this.Click}
className={regForm.button}>Sign Up
</Button>

</form>

{this.props.error ? <span>{this.props.error}</span> : null}
</div>
)
}
}
const connectedToReduxForm = reduxForm({
form: "loginForm",
});



export default withMutation(RegMutation)(connectedToReduxForm(RegForm))

最佳答案

secondName 字段不存在。我通过运行完整的项目知道这个) screenshot

关于graphql - 网络错误 : Response not successful: Received status code 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60914282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com