在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):npalm/graphql-java-demo开源软件地址(OpenSource Url):https://github.com/npalm/graphql-java-demo开源编程语言(OpenSource Language):Java 88.1%开源软件介绍(OpenSource Introduction):GraphQL demo service#TL;TR Execute the
IntroductionThis repo contains a simple Spring Boot (2.x) service that implements GraphQL API. The implementation is based on graphql-java-tools a GraphQL java library inspired by Apollo.
ApplicationThe application implements GraphQL on top of JPA repositories. The application provides basic functionality to store Conferences, for a conferences a set of Talks, for each Talk a set of speakers. And for each Talk comments can be made. The graphQL API contains queries, mutations and subscriptions. For a Conference a basic query is available. For Person and Talk a basic filtering is implemented in the query, and for Comments an experiment with pagination is available. For more details have a look at the schema Run with dockerPull and run the image.
The following endpoints are now available:
Example usagesExamples below show the usages of GraphiQL IDE. GraphQL IDE's playground and altair are enabled as well. Once the application is running point a browser to http://localhost:8080/graphiql. Which will open the GraphQL IDE. Here you can simple enter GraphQL queries. Since GraphQL is based on a schema you have completion features and documentation directly available in the browser. The system contains out-of-the box some basic test date. So why not start exploring by entering some queries. So let's get for all the conferences a list of talks with the speakers name. query {
conferences {
name
city
talks {
id
title
speakers {
name
}
}
}
} Data can be added via mutations, so next we add "John" via a GraphQL mutation.. mutation {
addPerson(person: {name: "John Doe"}) {
id
}
} We can subscribe for new comments made on a talk via the GrapQL subscribtion API. Subscribing for an event works in the same way as query you define the data structure in which you are interested. Next we subscribe for upates on notes. Via subscriptions you can get updates via a web socket about new Notes is. So first we subscribe to the notes, enter the following query. subscription {
comments {
comment
author
talk {
title
}
createdOn
}
} The response should like as follow.
Finally make a comment via a mutation in a new browser window. Find a talkId in the result of the first query. mutation {
addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
createdOn
id
}
} Have now a look on the subscription window, here the update should be visible. Build and RunBe aware that the React app is not part of this repo but linked as a GIT submodule. Either clone the repo with GradleTo build the Java application just run:
To run the application run, this does not contain the React app:
To run the React app:
DockerThe Docker file build both the Java and React app to a single Jar and package the in a docker image. Build image
Run the container
Now the container should be running and you can play around with GraphQL. Test dataDuring application start some test data is loaded. Test data is defined in the following files.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论