简体   繁体   中英

GraphQl Variable Question - hardcode works

I am wondering why my 2nd postman request does not work when utilizing variables for graphql api POST request.

The 1st request below works on Postman. Variables with graphql issue.

query {getById(id: "2"){
  id 
  name
  icon
  elements {
    id name link
    elements {
      id name link
      elements {
        id name link
        elements {
          id name link
            }
        }
    }
  }
} }
query {getById($id: String ){
  id ($id: id)
  name
  icon
  elements {
    id name link
    elements {
      id name link
      elements {
        id name link
        elements {
          id name link
           }
                }
            }
        }
    }
  }

} }

variable

{
    "id": "2"
}

Your second postman request is not working because you're not having the node called "2" in the graphQL definition.

A simple breakdown of your request:

query {getById(id: "2"){

Above identifies the item with id 2 from the service. All below that method are just nodes that you want to retrieve.

Also I think you can just use below:

query {getById($id: String ){
  id 
  name
  icon
  elements {
    id name link
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM