简体   繁体   English

使用变量时 GraphQL 错误请求

[英]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.

相关问题 graphql 查询产生 400 错误请求 - graphql query with fetch producing 400 bad request 使用 Apollo 客户端时,GraphQL 突变未发送到请求? - GraphQL mutation not being sent to request when using Apollo client? 使用 neo4j-graphql-js 时如何访问自定义 graphQL 解析器中的请求标头? - How to access request headers in custom graphQL resolvers when using neo4j-graphql-js? 使用getfilebyserverrelativeurl或getfolderbyserverrelativeurl时的HTTP 400 Bad Request - HTTP 400 Bad Request when using getfilebyserverrelativeurl or getfolderbyserverrelativeurl 在 for 循环中使用异步等待时出现错误的请求错误 - Bad Request Error When Using Async Await in a for loop 尝试使用javascript打印页面时出现错误请求 - bad request when trying to print a page using javascript 仅在IE中使用jQuery发布数据时出现错误的请求错误 - Bad Request error when posting data using jQuery in IE only 使用 axios 访问谷歌图片搜索时出现错误请求 API - Bad request when using axios to access google image search API 在使用通行证ldap时继续收到错误请求 - Keep receiving Bad Request when using passport-ldap 在 React 中使用 Axios POST 时出现 400 BAD REQUEST - 400 BAD REQUEST when POST using Axios in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM