Skip to content

NEDONION/springboot-graphql-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot GraphQL App - A CRUD Java Spring Boot with GraphQL

Requisites

  • Java
  • Spring Boot
  • JPA
  • GraphQL

Get Started

Query (Read)

1. Get All Persons

{
  getAllPersons {
    person_id
    name
    addressId
    address {
      address_id
      city
      zipcode
    }
  }
}
//Output:
{
  "data": {
    "getAllPersons": [
      {
        "person_id": "1",
        "name": "Richard",
        "addressId": 1,
        "address": {
          "address_id": "1",
          "city": "New York City",
          "zipcode": "10001"
        }
      },
      {
        "person_id": "2",
        "name": "Nate",
        "addressId": 2,
        "address": {
          "address_id": "2",
          "city": "Dallas",
          "zipcode": "20002"
        }
      },
      {
        "person_id": "3",
        "name": "Lucy",
        "addressId": 3,
        "address": {
          "address_id": "3",
          "city": "LA",
          "zipcode": "30003"
        }
      }
    ]
  }
}

2. Get All Address

{
  getAllAddress {
    address_id
    city
    zipcode
  }
}
//Output:
{
  "data": {
    "getAllAddress": [
      {
        "address_id": "1",
        "city": "New York City",
        "zipcode": "10001"
      },
      {
        "address_id": "2",
        "city": "Dallas",
        "zipcode": "20002"
      },
      {
        "address_id": "3",
        "city": "LA",
        "zipcode": "30003"
      }
    ]
  }
}

3. Get Person And Address By Id

{
  getPersonById(person_id: 1) {
    person_id
    name
    email
    addressId
    address {
      address_id
      city
      zipcode
    }
  }
}
//Output:
{
  "data": {
    "getPersonById": {
      "person_id": "1",
      "name": "Richard",
      "email": "Richard@test.com",
      "addressId": 1,
      "address": {
        "address_id": "1",
        "city": "New York City",
        "zipcode": "10001"
      }
    }
  }
}

Mutation (Write)

1. Create Address

mutation {
  createAddress(city: "Austin", zipcode: "78717") {
    address_id
    city
    zipcode
  }
}
//Output:
{
  "data": {
    "createAddress": {
      "address_id": "4",
      "city": "Austin",
      "zipcode": "78717"
    }
  }
}

2. Create Person

mutation {
  createPerson(name: "Jiacheng", addressId: 4, email: "743160803@qq.com") {
    person_id
    name
    addressId
    email
  }
}
//Output:
{
  "data": {
    "createPerson": {
      "person_id": "4",
      "name": "Jiacheng",
      "addressId": 4,
      "email": "743160803@qq.com"
    }
  }
}

3. Delete Address

mutation {
  deleteAddress(address_id: 3)
}
//Output:
{
  "data": {
    "deleteAddress": true
  }
}

What happens if we fetch data for person_id = 3 now?

//Output:
{
  "data": {
    "getPersonById": {
      "person_id": "3",
      "name": "Lucy",
      "email": "ar_alok@accionlabs.com",
      "addressId": 3,
      "address": null
    }
  },
  "errors": [
    {
      "message": "Internal Server Error(s) while executing query",
      "extensions": null,
      "path": null
    }
  ]
}

4. Delete Person

mutation {
  deletePerson(person_id: 3)
}
//Output:
{
  "data": {
    "deletePerson": true
  }
}

About

A CRUD Java Spring Boot with GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages