Basic spring graphql application using an in memory H2 database and spring jdbc
Under src/main/resources, create nba.graphqls file and add the schema for types and queries
Enable the graphiql web interface in application.properties
Create a basic @Controller class and use @QueryMapping to map the graph ql query
Define schema.sql to create tables and data.sql to insert some values
Create a data source @Configuration class and define @Bean data source
Create entities, row mappers to map from db to java class and DAOs (@Repository) to fetch data from DB using @JdbcTemplate
Define h2 db properties in application.properties and disable jpa hibernate as we will use pure spring jdbc only for this project
Inject the DAO into the controller to get the data from DB when the graphql query is issued from the graphql web console
H2 Console http://localhost:8080/h2-console
Use jdbc:h2:mem:testdb as JDBC URL
GraphQL browser : http://localhost:8080/graphiql?path=/graphql
query {
teams {
id
name
city
}
team(teamId:"7"){
id, name
}
}
query {
team(teamId:"1"){
name
coach
city
arena
owner
founded
players{
id
name
age
height
position
}
}
}
mutation {
createTeam(name: "Seattle Seahawks", coach: "Gary", city: "Seattle")
}
A Player can belong to only one Team
A Player can have only one Position
A Team can have only 5 players
Team stats - Played, Won, Lost, PPG, Rebounds, Assists, Blocks, FG %, FT %
Player stats - Min, PTS, FG %, FT%, 3P %, ASS, STL, BLK
List all teams
List all players in a team
Create or Remove Team
Create or Remove Player
Add or remove Player from Team
List all stats for a Team , for a Player
List all players in Team with their stats