Coder Social home page Coder Social logo

tanbinh123 / spring-graphql-mysql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mihajlonesic/spring-graphql-mysql

0.0 0.0 0.0 20 KB

Getting Started with Spring Boot, GraphQL and MySQL

Home Page: https://gitlab.com/MihajloNesic/spring-graphql-mysql

Java 100.00%

spring-graphql-mysql's Introduction

Spring Boot - GraphQL - MySQL

Spring Boot GraphQL MySQL
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

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

query {
    language(id: 1) {
        name
        color
        languageType
    }
}

Returns id and name of all languages with type 'programming'

query {
    languageType(languageType: "programming") {
        id
        name
    }
}

Creates a new language and returns id and name

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

mutation {
  updateUser(id: 5, email: "[email protected]") {
      id 
      username
      email
  }
}

Deletes user with ID 4

mutation {
  deleteUser(id: 4)
}

Returns all projects created by user with ID 2

query {
  userProjects(userId: 2) {
    id
    title
    language {
      name
    }
  }
}

spring-graphql-mysql's People

Contributors

mihajlonesic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.