Skip to content

Latest commit

 

History

History
141 lines (126 loc) · 4.07 KB

README.md

File metadata and controls

141 lines (126 loc) · 4.07 KB

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
                }
            }
          }