1. 程式人生 > >[GraphQL] Filter Data Based on Query Arguments with GraphQL

[GraphQL] Filter Data Based on Query Arguments with GraphQL

With GraphQL, every field and nested object can have a set of arguments which can be used to request very specific data from a GraphQL API. In this lesson, we will pass arguments to the GitHub API inline and as query variables.

 

We can named query:

query UserInfo {

}

 

We can pass in arguements into query:

query UserInfo ($login: String="xxx"){}

 

The same as function in Javascript, we can give default params and use it in query:

query UserInfo ($login: String="xxx"){ 
  user(login:$login) {
    name,
    company,
    followers {
      totalCount
    }
  }
}