Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mihajlonesic/spring-graphql-mysql
Getting Started with Spring Boot, GraphQL and MySQL. Please take a look at a newer version https://github.com/MihajloNesic/numista-graphql
https://github.com/mihajlonesic/spring-graphql-mysql
graphql mysql spring spring-boot
Last synced: 17 days ago
JSON representation
Getting Started with Spring Boot, GraphQL and MySQL. Please take a look at a newer version https://github.com/MihajloNesic/numista-graphql
- Host: GitHub
- URL: https://github.com/mihajlonesic/spring-graphql-mysql
- Owner: MihajloNesic
- Created: 2019-10-05T11:36:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T23:58:12.000Z (almost 5 years ago)
- Last Synced: 2024-11-18T13:28:24.015Z (3 months ago)
- Topics: graphql, mysql, spring, spring-boot
- Language: Java
- Homepage: https://github.com/MihajloNesic/numista-graphql
- Size: 19.5 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Boot - GraphQL - MySQL
[![Spring Boot](https://i.imgur.com/9zObPwT.png)](https://spring.io/projects/spring-boot)
[![GraphQL](https://i.imgur.com/TRGUDTv.png)](https://graphql.org/)
[![MySQL](https://i.imgur.com/0IydTPv.png)](https://www.mysql.com/)
Getting Started with Spring Boot, GraphQL and MySQL## Data
This demo application communicates with a MySQL database `graphql_db`. The sql file is located in 'resources' folder.
There are three tables: `language`, `user` and `project`.
Each project has a language and a user that created that project.
_Note that this database and data are just for demonstration purposes._
## Usage
GraphQL endpoint is located at `http://localhost:8080/graphql` and can be changed in `application.properties` file.
To use GraphiQL, locate `http://localhost:8080/graphiql` (notice 'i' in graphiql).
The `.graphqlconfig` file is located in `resources/graphql` folder. The file is used to execute GraphQL from the IntelliJ IDEA.
![IntelliJ IDEA GraphQL](https://i.imgur.com/ze6buJW.png)
#### Queries
`allLanguages` - Returns all languages in the database
`language(id: ID!)` - Returns one language with passed ID
`languageType(languageType: String!)` - Returns languages with passed type (programming, data or markup)
`allProjects: [Project]` - Returns all projects in the database
`project(id: ID!): Project` - Returns one project with passed ID
`userProjects(userId: ID!): [Project]` - Returns all projects created by the user with passed ID
`allUsers: [User]` - Returns all users in the database
`user(id: ID!): User` - Returns one user with passed ID#### Mutations
`createLanguage(name: String, code: String, color: String, languageType: String): Language!` - Creates a new language
`updateLanguage(id: ID!, name: String, code: String, color: String, languageType: String): Language!` - Updates an existing language
`deleteLanguage(id: ID!): Boolean` - Deletes a language by ID
`createProject(title: String, description: String, language: ID!, user: ID!): Project!` - Creates a new project
`updateProject(id: ID!, title: String, description: String, language: ID, user: ID): Project!` - Updates an existing project
`deleteProject(id: ID!): Boolean` - Deletes a project by ID
`createUser(username: String, email: String): User!` - Creates a new user
`updateUser(id: ID!, username: String, email: String): User!` - Updates an existing user
`deleteUser(id: ID!): Boolean` - Deletes a user by ID#### Demo Usage
Returns name, color and language type for a language with ID 1
```graphql
query {
language(id: 1) {
name
color
languageType
}
}
```Returns id and name of all languages with type 'programming'
```graphql
query {
languageType(languageType: "programming") {
id
name
}
}
```Creates a new language and returns id and name
```graphql
mutation {
createLanguage(name: "Kotlin", code: "kotlin", color: "F18E33", languageType: "PROGRAMMING") {
id
name
}
}
```Updates email for user with ID 5 and returns id, username and email
```graphql
mutation {
updateUser(id: 5, email: "[email protected]") {
id
username
}
}
```Deletes user with ID 4
```graphql
mutation {
deleteUser(id: 4)
}
```Returns all projects created by user with ID 2
```graphql
query {
userProjects(userId: 2) {
id
title
language {
name
}
}
}
```