PetClinic Example based on GraphQL
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 15 commits behind spring-petclinic:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
backend
frontend
talk
.gitattributes
.gitignore
graphql-idea.png
graphql.config.json
readme.md
screenshot.png

readme.md

GraphQL version of Spring PetClinic Sample Application

This is a GraphQL API version of the Spring PetClinic Application. It consists of two parts:

  • The Spring Boot-based backend, that uses the graphql-java implementation for the server-side GraphQL Api implementation
  • The React-based frontend, that uses React Apollo for running GraphQL queries.

Note This project is in very early stage and has much room for improvement! If you like to help, I'd be more than happy! You can for example open an issue for discussing things or a Pull Request to contribute.

The Backend

The backend code in this repository is based on the Rest example https://github.com/spring-petclinic/spring-petclinic-rest. Instead of the org.springframework.samples.petclinic.rest package it contains a org.springframework.samples.petclinic.graphql package that contains the resolvers for the GraphQL API.

GraphQL Java implementation

GraphQL frameworks used in this example:

The frontend

The frontend is implemented in TypeScript and uses React for the UI.

GraphQL frameworks used in the frontend:

Running petclinic locally

First clone the application:

git clone https://github.com/spring-petclinic/spring-petclinic-graphql.git

Then build and start the SpringBoot backend using Maven:

cd spring-petclinic-graphql/backend
./mvnw spring-boot:run

Finally build and start the frontend:

cd spring-petclinic-graphql/frontend
# install dependencies
yarn install
	
# start application
yarn start

After running you can access:

SpringBoot PetClinic, GraphQL Edition

Contributing

If you like to help and contribute you're more than welcome! Please open an issue or a Pull Request

Contact

You can find me on Twitter.

From the original PetClinic README

Understanding the Spring Petclinic application with a few diagrams

See the presentation here

Database configuration

(Note: this is unrelated to GraphQL)

In its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data. A similar setups is provided for MySql and PostgreSQL in case a persistent database configuration is needed. To run petclinic locally using persistent database, it is needed to change profile defined in application.properties file.

For MySQL database, it is needed to change param "hsqldb" to "mysql" in string

spring.profiles.active=hsqldb,spring-data-jpa

defined in application.properties file.

Before do this, would be good to check properties defined in application-mysql.properties file.

spring.datasource.url = jdbc:mysql://localhost:3306/petclinic?useUnicode=true
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.username=root 
spring.datasource.password=petclinic 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.jpa.database=MYSQL 
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=none

You may also start a MySql database with docker:

docker run --name mysql-petclinic -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8

For PostgeSQL database, it is needed to change param "hsqldb" to "postgresql" in string

spring.profiles.active=hsqldb,spring-data-jpa

defined in applcation.properties file.

Before do this, would be good to check properties defined in application-postgresql.properties file.

spring.datasource.url=jdbc:postgresql://localhost:5432/petclinic
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=petclinic
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database=POSTGRESQL
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none

You may also start a Postgres database with docker:

docker run --name postgres-petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 -d postgres:9.6.0