Skip to content

tiagomartins91/graphql-spring-boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo Application - GraphQL with Spring Boot

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

My personal notes

Demo application with H2 database to test some GraphQL features.

Notes

  • GraphQL Query - GET data
  • GraphQL Mutation - Create, Update, Delete data
  • GraphQL Schema - Define which attributes are there in your class data type.
  • GraphQL Vs REST API:
    • REST is having fixed response while GraphQL provides flexibility;
    • REST has different http methods and separate endpoints to each API, while in GraphQL whe have Query and Mutation and there is only one endpoint;
    • GraphQL needs Schema file while REST does not need that.
  • Node and Edge in GraphQL:
    • Node(Table - PK) ---->(Edge) Node(Table - PK; FK)

Examples

  • Plugin for Google Chrome to run querys: Altair GraphQL Client

  • Query's:

    query {
          fullName(sampleRequest: {
              firstName: "Tiago",
              lastName: "Jesus"
          })
    }
    

    Get Student By Id (dynamic fields, can add or remove fields):

    query {
        student(id: 1){
            id
            firstName
            lastName
            email
            street
            city
        }
    }
    

    Query with list:

      query{
            student(id: 2){
                id
                firstName
                lastName
                learningSubjects {
                    subjectName
                    marksObtained
                }
            }
      }
    
        query{
            student(id: 2){
                id
                firstName
                lastName
                learningSubjects {
                    subjectName
                    marksObtained
                }
                fullName
            }
        }
    

    Query with filtered data:

    • subjectNameFilter (Enum): All, Java, MySQL, MongoDB
      query{
          student(id: 2){
              id
              firstName
              lastName
              learningSubjects(subjectNameFilter: Java) {
                  subjectName
                  marksObtained
              }
            fullName
          }
      }
    

    Query to create (Mutation - POST):

          mutation{
            createStudent(createStudentDTO:{
                  firstName: "TM"
                  lastName: "91"
                  email: "tm91@test.com"
                  street: "test"
                  city: "test"
                  subjectsLearning: [
                    { subjectName: "Java" marksObtained: 100.00 }
                    { subjectName: "Ruby" marksObtained: 60.00 }
                  ]
                }) {
                  id
                  firstName
                  lastName
                  email
                  street
                  city
                  learningSubjects(subjectNameFilter: All) {
                    id
                    subjectName
                    marksObtained
                  }
                  fullName
                }
            }
          }
    

About

GraphQL with Spring Boot Demo App

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages