My sample query is as below:
%{
"query" => """
query getPerson(
$name: String!
){
getPerson(name: $name) {
id
col1
col2
col3
col3
}
}
""",
"variables" => %{
"name" => "person_name",
}
}
I want to select the fields dynamically. For example, for one query I just need id, col1, col2
but for another query id, col1, col3
and so on. How do I use variable for fields?
Below is what I try which is not correct.
%{
"query" => """
query getPerson(
$name: String!
){
getPerson(name: $name) {
$fields
}
}
""",
"variables" => %{
"name" => "person_name",
"fields" => "id col1 col3",
}
}
I am new to graphql. Can anyone help me write it correctly?