An example project showcasing a simple service which serves data about famous books.
import com.expediagroup.graphql.spring.operations.Query
import org.springframework.stereotype.Component
@Component
class AuthorQuery(
private val authorService: AuthorService
) : Query {
fun authorById(id: Int): CompletableFuture<Author> {
return authorService.findAuthorById(id)
.toFuture()
}
}
data class Author(val id: Int, val name: String?)
schema {
query: Query
}
type Author {
id: Int!
name: String
}
type Query {
authorById(id: Int!): Author!
}
{
authorById(id: 1) {
name
}
}
- Build a Docker image using Spring Boot's Buildpack support
$ ./gradlew bootBuildImage --imageName=itsandreramon/spring
- Make sure the corresponding itsandreramon/spring image has been built
$ docker images -a
- Run Docker Compose
$ docker-compose up
- Make sure everything is running correctly
$ docker-compose ps
- Access PostgreSQL to make changes according to your needs (e.g. via CLI)
$ docker exec -it database psql -U postgres
Your newly created GraphQL server starts up with following preconfigured default routes:
- /graphql - GraphQL server endpoint used for processing queries and mutations
- /subscriptions - GraphQL server endpoint used for processing subscriptions
- /sdl - Convenience endpoint that returns current schema in Schema Definition Language format
- /playground - Prisma Labs GraphQL Playground IDE endpoint