https://github.com/vladimir-dejanovic/graphql-spring-boot-example
graphql-spring-boot-example
https://github.com/vladimir-dejanovic/graphql-spring-boot-example
graphql graphql-server java spring-boot
Last synced: over 1 year ago
JSON representation
graphql-spring-boot-example
- Host: GitHub
- URL: https://github.com/vladimir-dejanovic/graphql-spring-boot-example
- Owner: vladimir-dejanovic
- License: gpl-3.0
- Created: 2018-10-31T22:51:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-08T22:21:08.000Z (over 7 years ago)
- Last Synced: 2025-02-28T03:41:55.268Z (over 1 year ago)
- Topics: graphql, graphql-server, java, spring-boot
- Language: Java
- Size: 23.4 KB
- Stars: 5
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL example implemented with Spring Boot
This is simple example of GraphQL API implemented in Java with Spring Boot, and relaying on it's magic :)
There is example of implementation of **Query** and **Subscription**.
## Dependencies
### GraphQL
For GraphQL dependency added
```
com.graphql-java
graphql-java
8.0
com.graphql-java
graphql-java-tools
5.0.0
```
### GraphQL Spring Boot integration
To connect GraphQL and Spring Boot added this dependency
```
com.graphql-java
graphql-spring-boot-starter
5.0.2
```
### GraphiQL "out of the box"
In order to get GraqhiQL, UI for testing local version of GraphQL API added this dependency
```
com.graphql-java
graphiql-spring-boot-starter
5.0.2
```
For GraphiQL hit http://localhost:8080/graphiql, when you start application
## Query implementation
Query implementation is almost exactly the same like all other my examples of Query. Only difference is annotation **@Component** at top.
For full code just open [Query.java](https://github.com/vladimir-dejanovic/graphql-spring-boot-example/blob/master/src/main/java/xyz/itshark/play/graphqlspringboot/example/resolves/Query.java)
Query example in GraphiQL
```
query {
allData {
message
}
}
```
## Mutation implementation
Mutation implementation is almost exactly the same like all other my examples of Mutation. Only difference is annotation **@Component** at top.
For full code just open [Mutation.java](https://github.com/vladimir-dejanovic/graphql-spring-boot-example/blob/master/src/main/java/xyz/itshark/play/graphqlspringboot/example/resolves/Mutation.java)
Mutation example in GraphiQL
```
mutation {
add(message:"Hello") {
message
}
}
```
after mutation you can run query again and check if all worked as intended.
## Subscription implementation
Subscription implementation is done using RXJava and by implementing **GraphQLSubscriptionResolver**
For full code example check [Subscription.java](https://github.com/vladimir-dejanovic/graphql-spring-boot-example/blob/master/src/main/java/xyz/itshark/play/graphqlspringboot/example/resolves/Subscription.java)
Subscription **can be** tested from GraphiQL.
Subscription example in GraphiQL
```
subscription {
data {
message
}
}
```