title: How to fetch EntityGraph dynamically in Spring Boot
body: <p>I am developing an application using Spring Boot using JPA.
  In the application I am exposing a rest API. I do not want to use Spring data rest as I want to have full control of the data.</p>
  
  <p>I am not able to figure out how to use EntityGraph dynamically.</p>
  
  <p>Suppose I have following model taken from <a href="https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling" rel="noreferrer">here</a></p>
  
  <pre><code>   @Entity
  class Product {
  
    @ManyToMany
    Set&lt;Tag&gt; tags;
  
    // other properties omitted
  }
  
  interface ProductRepository extends Repository&lt;Customer, Long&gt; {
  
    @EntityGraph(attributePaths = {"tags"})
    Product findOneById(Long id);
  }
  </code></pre>
  
  <p>I have following rest link to access Product
  <a href="http://localhost:8090/product/1" rel="noreferrer">http://localhost:8090/product/1</a></p>
  
  <p>It returns to me a product with id 1</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>Will it by default fetch <strong>tags</strong> as we have mentioned @EntityGraph?
  If yes, then can this be configured on demand? Say, if in the query
  string I have <strong>include=tags</strong>, then only I want to fetch product with
  its tags.</li>
  </ol>
  
  <p>I found <a href="http://www.thoughts-on-java.org/jpa-21-entity-graph-part-2-define/" rel="noreferrer">this</a> article but not sure how this can be of help.</p>