• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

spring-petclinic/spring-petclinic-graphql: PetClinic Example based on GraphQL

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

spring-petclinic/spring-petclinic-graphql

开源软件地址(OpenSource Url):

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

开源编程语言(OpenSource Language):

CSS 56.2%

开源软件介绍(OpenSource Introduction):

Spring PetClinic Sample Application using spring-graphql

This PetClinic version uses the new spring-graphql project, that has been introduced in july 2021 and has been finally release as 1.0.0 GA version.

This version uses Spring Boot 2.7 with GraphQL for Spring 1.0.

It implements a GraphQL API for the PetClinic and provides an example Frontend for the API.

Java CI with Maven

Open in Gitpod

Features

Some features that are built in:

  • Annotated Controllers (see graphql/*Controller-classes, e.g. SpecialtyController and VetController)
  • Subscriptions via Websockets (see VisitController#onNewVisit)
  • Own scalar types (See PetClinicRuntimeWiringConfiguration and DateCoercing)
  • GraphQL Interfaces (GraphQL Type Person) and Unions (GraphQL Type AddVetPayload), see class PetClinicRuntimeWiringConfiguration
  • Security: the /graphql http and WebSocket endpoints are secured and can only be accessed using a JWT token. More fine grained security is implemented using @PreAuthorize (see VetService)
    • Example: addVet mutation is only allowed for users with ROLE_MANAGER
  • Pagination and Sorting of results: implemented with spring-data, see OwnerController
  • Tests: See test folder for typical GraphQL endpoint tests, including tests for security

Running the sample application

You can run the sample application with two ways:

  1. The easiest way: run it pre-configured in cloud IDE GitPod
  2. Run it locally

Run it in GitPod

To run the application (backend, GraphiQL and React frontend) in GitPod, simply click on the "Open in GitPod" button at the top of this README.

  • Note that you need a (free) GitPod account.
  • And please make sure that you allow your browser opening new tabs/windows from gitpod.io!

After clicking on the GitPod button, GitPod creates a new workspace including an Editor for you, builds the application and starts backend and frontend. That might take some time!

When backend and frontend are running, GitPod opens two new browser tabs, one with GraphiQL and one with the PetClinic backend. For login options, see below "Accessing the GraphQL API"

Note that the workspace is your personal workspace, you can make changes, save files, re-open the workspace at any time and you can even create git commits and pull requests from it. For more information see GitPod documentation.

In the GitPod editor you can make changes to the app, and after saving the app will be recompiled and redeployed automatically.

SpringBoot PetClinic in GitPod Workspace

Using IntelliJ with GitPod

Recently GitPod has added support for JetBrain IDEs like IntelliJ. While this support is currenty beta only, you can try it and open the PetClinic in IntelliJ. Note that in this scenario you're still working on a complete, ready-to-use workspace in the cloud. Only the IntelliJ UI runs locally at your maching.

Please read the setup instructions here.

SpringBoot PetClinic in GitPod IntelliJ Workspace

Running locally

The server is implemented in the backend folder and can be started either from your IDE (org.springframework.samples.petclinic.PetClinicApplication) or using maven from the root folder of the repository:

./mvnw spring-boot:run -pl backend

Note: the server runs on port 9977, so make sure, this port is available.

(The server uses an in-memory database, so no external DB is needed)

Running the frontend

While you can access the whole GraphQL API from GraphiQL this demo application also contains a modified version of the classic PetClinic UI. Compared to the original client this client is built as a Single-Page-Application using React and Apollo GraphQL and has slightly different features to make it a more realistic use-case for GraphQL.

You can install and start the frontend by using npm:

cd ./frontend

npm install

npm run build:css

npm run generate

npm start

The running frontend can be accessed on http://localhost:3000.

For valid users to login, see list above.

SpringBoot PetClinic, React Frontend

Accessing the GraphQL API

You can access the GraphQL API via the included customized version of GraphiQL.

The included GraphiQL adds support for login to the original GraphiQL.

You can use the following users for login:

  • joe/joe: Regular user
  • susi/susi: has Manager Role and is allowed to execute the createVet Mutation

After starting the server, GraphiQL runs on http://localhost:9977

Sample Queries

Here you can find some sample queries that you can copy+paste and run in GraphiQL. Feel free to explore and try more


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap