first of all i have to apologize. Probably this is a stupid beginner question, but slowly i get frustrated after paging thorugh dozens of tutorials and issues...
Whats the Problem? I have a simple schema, looking like the following:
schema {
query: Query
}
type Query {
allVehicles: [Vehicle]!
allPersons: [Person]!
}
type Vehicle{
name: String!
}
Person{
name: String!
}
Now im trying to let different classes resolve the queries for person and vehicle. So i build a query class for person and one for vehicle, both implement the GraphQLQueryResolver interface.
Than i have a class, which builds the schema, and it looks like the following:
@WebServlet(urlPatterns = "/graphql")
public class GraphQLEndpoint extends SimpleGraphQLServlet {
public GraphQLEndpoint() {
super(buildSchema());
}
private static GraphQLSchema buildSchema() {
final VehicleRepository vehicleRepository = new VehicleRepository();
final PersonRepository personRepository = new PersonRepository();
return SchemaParser.newParser()
.file("schema.graphqls")
.resolvers(new VehicleQuery(vehicleRepository),
new PersonQuery(personRepository)),
.build()
.makeExecutableSchema();
}
}
I can start the webapplication on my jetty server, but since i visit it from the browser, i get errors, which tell me, that the functions allVehicles and allPersons cannot be found.
(In other tutorials and issues, everybody has .js files beside their schema.graphqls but i neither don't understand, how they work nor why they are necessary. What's the point of the schema.graphqls, if it's not able to let me delegate which class has to deal the respective queries.)
So please, could anyone tell me, what i am doing wrong?
Edit: Maybe i should show you one of the query classes:
public class PersonQuery implements GraphQLRootResolver {
private final PersonRepository _personRepository;
public PersonQuery(
final PersonRepository pPersonRepository) {
this._personRepository = pPersonRepository;
}
public List<Person> allPersons() {
return _personRepository.getAllPersons();
}
}