[英]GraphQL bad request when using variables
I am new to GraphQL and am in a situation where I need to make a mutation request using apollo.我是 GraphQL 的新手,并且处于需要使用 apollo 发出突变请求的情况。 I am largely unfamiliar with syntax and I am unable to find a solution to my problem elsewhere.我在很大程度上不熟悉语法,并且无法在其他地方找到解决我的问题的方法。
When I use the following query, I get a status code 200 back:当我使用以下查询时,我得到状态码 200:
const CREATE_USER = gql`mutation Mutation {
createUser(firstName: "corn", uid: "unique", contactNumber: "123467891") {
user {
uid
contactNumber
email
firstName
lastName
gender
},
ok
}
}`
Hover, when I try to implement variables with the following query, I get a 400 bad request code back:悬停,当我尝试使用以下查询实现变量时,我得到一个 400 错误的请求代码:
const CREATE_USER = gql`mutation createUser($firstName: String, $lastName: String, $uid: String $contactNumber: String) {
user {
contactNumber
email
firstName
lastName
gender
dob
}
ok
}
I've looked at examples and adjusted by query with variables to fit, but I am still unable to figure out what exactly I'm doing wrong.我查看了示例并通过查询调整了变量以适应,但我仍然无法弄清楚我到底做错了什么。 I know it's probably a simple syntax problem but I'm too unfamiliar with graphql to figure it out.我知道这可能是一个简单的语法问题,但我对 graphql 太陌生而无法弄清楚。 Any help would be really appreciated.任何帮助将非常感激。
I believe I figured out the correct syntax.我相信我找到了正确的语法。 I had tried variations like this, but I guess I made mistakes which caused errors.我曾尝试过这样的变体,但我想我犯了导致错误的错误。 This time I got it right.这次我做对了。
const CREATE_USER = gql`mutation createUser($contactNumber: String, $uid: String!, $email: String, $firstName: String, $lastName: String) {
createUser(contactNumber: $contactNumber, uid: $uid, email: $email, firstName: $firstName, lastName: $lastName) {
user {
contactNumber
uid
email
firstName
lastName
gender
dob
}
ok
}
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.