NodeJs GraphQL dynamic query variable

NodeJs GraphQL dynamic query variable

https://launchpad.graphql.com/9qvqz3v5r
Here is my graphQL example
If i passed userId:2 as static
{
user(userId:2){
firstName
lastName
}
}

I will get output as below
{
“data”: {
“user”: {
“firstName”: “Joe”,
“lastName”: “spin”
}
}
}

I need same output using dynamic query variable
query getUserNameData($userId: User){
user(userId:$userId){
firstName
lastName
}
}
query variables
{
“userId” : 2
}

But i am getter error as :
Variable \”$userId\” cannot be non-input type \”User
http://prntscr.com/h2ojor
Can anyone help me?

Solutions/Answers:

Solution 1:

http://prntscr.com/h2oop9

You have to specify datatype with ! this symbol to get the variables

query getUserNameData($userId: Int!) {
  user(userId: $userId) {
    firstName
    lastName
  }
}

References

Related:  GraphQL: One Big Query vs Lots of Little Queries