1

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?

mpriyaah
  • 65
  • 1
  • 7

1 Answers1

0

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
  }
}
  • Could you please show an example of how to have dynamic fields such as `firstName` or `lastName`? – Jack Jan 30 '19 at 18:07