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