title: Mapping multiple graphQL schema files to separate resolvers - Spring Boot
body: <p>I'm finding it really difficult to separate queries from one schema file. I want to have something like this:</p>
  
  <p><strong>car.graphqls</strong></p>
  
  <pre><code>type Query {
      car(id: ID!): Car
  }
  
  type Car {
      id: ID!,
      name: String!
  }
  </code></pre>
  
  <p><strong>house.graphqls</strong></p>
  
  <pre><code>type Query {
      house(id: ID!): House
  }
  
  type House {
      id: ID!,
      owner: String,
      street: String
  }
  </code></pre>
  
  <p>I searched a lot but I can't find a way to write two java classes and implement <code>getHouse()</code> in one of them and <code>getCar()</code> in other.</p>
  
  <pre><code>@Component
  public class CarQuery implements GraphQLQueryResolver {
  
      @Autowired
      private CarService carService;
  
      public List&lt;Car&gt; getCar(final int id) {
          return this.carService.getCar(id);
      }
  }
  
  public class HouseQuery implements GraphQLQueryResolver {
  
      @Autowired
      private HouseService houseService;
  
      public List&lt;House&gt; getHouse(final int id) {
          return this.houseService.getHouse(id);
      }
  }
  </code></pre>
  
  <p>I found out that the <code>graphql-java-tools</code> package which I'm using will search through the project and finds all schema files (that end with <code>.graphqls</code>), but the code which I showed above gives me this error:</p>
  
  <pre><code>Caused by: com.coxautodev.graphql.tools.FieldResolverError: No method found with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:
  
    com.example.polls.resolvers.CarQuery.house(~count)
    com.example.polls.resolvers.CarQuery.getHouse(~count)
  </code></pre>
  
  <p>I also found some advises that I need to have only one Root Query in schema files, and to extend all other Query types in schema files. I tried to write to <code>house.graphqls</code> something like this, but failed:</p>
  
  <pre><code>extend Type Query {
      house(id: ID!): House
  }
  </code></pre>
  
  <p>Is there a way to tell graphql and java what schema file I want to be mapped to which java resolver file?</p>