Code Monkey home page Code Monkey logo

quarkus-reactive-hibernate-graphql-crud's Introduction

quarkus-reactive-hibernate-graphql-crud

This project demonstrates a graphql crud application together using smallrye-graphql, panache and hibernate reactive(with ORM). It presents a set of movies together with actors and can be queried and mutated accordingly.

This project uses Quarkus, the Supersonic Subatomic Java Framework.

This project is presented in the following article.

Creating a CRUD app with Quarkus, Reactive Hibernate, Panache and GraphQL using a PostgreSQL database

Run Postgres docker container

 docker run -d --rm --name my_reative_db -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DB=my_db -p 5432:5432 postgres:10.5

Clean DB

docker rm $(docker ps -a -q) -f

docker volume prune

Run live coding

./mvnw compile quarkus:dev

Native image build

./mvnw package -Pnative -Dquarkus.native.container-build=true

Go to the GraphQL UI

http://localhost:8080/q/graphql-ui/

GraphQL for all movies

query allMovies {
  allMovies {
	title
  	releaseDate
        director
        id
  }
}

Response allMovies

{
  "data": {
    "allMovies": [
      {
        "title": "Reservoir Dogs",
        "releaseDate": "1993-02-26",
        "director": "Quentin Tarantino",
        "id": 1
      },
      {
        "title": "Pulp Fiction",
        "releaseDate": "1994-11-25",
        "director": "Quentin Tarantino",
        "id": 2
      },
      {
        "title": "The Mask",
        "releaseDate": "1994-12-25",
        "director": "Chuck Russel",
        "id": 3
      }
    ]
  }
}

Query by movieId

query getMovie {
  movie(movieId: 1) {
    title
    director
    releaseDate
  }
}

Response getMovie

{
  "data": {
    "movie": {
      "title": "Reservoir Dogs",
      "director": "Quentin Tarantino",
      "releaseDate": "1993-02-26"
    }
  }
}    

Query all movies with movie ids

  query allMovies {
    movie1: movie(movieId: 1) {
      title
      releaseDate
      director
    }
    movie2: movie(movieId: 2) {
      title
      releaseDate
      director
    }
  }

}

Response

{
  "data": {
    "movie1": {
      "title": "Reservoir Dogs",
      "releaseDate": "1993-02-26",
      "director": "Quentin Tarantino"
    },
    "movie2": {
      "title": "Pulp Fiction",
      "releaseDate": "1994-11-25",
      "director": "Quentin Tarantino"
    }
  }
}

Query movie with actors

query getMovie {
  movie(movieId: 1) {
    title
    director
    releaseDate
    actors {
      name
    }
  }
}

Response

{
  "data": {
    "movie": {
      "title": "Reservoir Dogs",
      "director": "Quentin Tarantino",
      "releaseDate": "1993-02-26",
      "actors": [
        {
          "name": "John Travolta"
        }
      ]
    }
  }
}

Query all movies with actors

   query allMovies {
     allMovies {
       title
       releaseDate
       director
       id
       actors {
         name
       }
     }
   }

Response

{
  "data": {
    "allMovies": [
      {
        "title": "Reservoir Dogs",
        "releaseDate": "1993-02-26",
        "director": "Quentin Tarantino",
        "id": 1,
        "actors": [
          {
            "name": "John Travolta"
          }
        ]
      },
      {
        "title": "Pulp Fiction",
        "releaseDate": "1994-11-25",
        "director": "Quentin Tarantino",
        "id": 2,
        "actors": [
          {
            "name": "Quentin Tarantino"
          },
          {
            "name": "John Travolta"
          },
          {
            "name": "Samuel L Jackson"
          }
        ]
      },
      {
        "title": "The Mask",
        "releaseDate": "1994-12-25",
        "director": "Chuck Russel",
        "id": 3,
        "actors": [
          {
            "name": "Jim Carrey"
          }
        ]
      }
    ]
  }
}

Create movie

mutation addMovie {
  createMovie(
    movie: {title: "The Mask", releaseDate: "1994-12-25", director: "Chuck Russell"}
  ) {
    title
    releaseDate
    director
  }
}

Response

{
  "data": {
    "createMovie": {
      "title": "The Mask",
      "releaseDate": "1994-12-25",
      "director": "Chuck Russell"
    }
  }
}

Update Movie

mutation updateMovie {
  updateMovie(
    movieId: 1
    movie: {title: "The One"}
  ) {
    title
  }
}

Response

{
  "data": {
    "updateMovie": {
      "title": "The One"
    }
  }
}

Delete Movie

mutation deleteMovie {
  deleteMovie(movieId: 1)
}

Response

{
  "data": {
    "deleteMovie": true
  }
}

Get All Actors

query allActors {
  allActors {
    name
    id
  }
}

Response

{
  "data": {
    "allActors": [
      {
        "name": "Quentin Tarantino",
        "id": 1
      },
      {
        "name": "Quentin Tarantino",
        "id": 2
      },
      {
        "name": "John Travolta",
        "id": 3
      },
      {
        "name": "Samuel L Jackson",
        "id": 4
      }
    ]
  }
}

Query all actors with movies

query allActors {
  allActors {
    name
    movies {
      title
      director
    }
  }
}

Response

{
  "data": {
    "allActors": [
      {
        "name": "Quentin Tarantino",
        "movies": [
          {
            "title": "Pulp Fiction",
            "director": "Quentin Tarantino"
          }
        ]
      },
      {
        "name": "John Travolta",
        "movies": [
          {
            "title": "Reservoir Dogs",
            "director": "Quentin Tarantino"
          },
          {
            "title": "Pulp Fiction",
            "director": "Quentin Tarantino"
          }
        ]
      },
      {
        "name": "Samuel L Jackson",
        "movies": [
          {
            "title": "Pulp Fiction",
            "director": "Quentin Tarantino"
          }
        ]
      },
      {
        "name": "Jim Carrey",
        "movies": [
          {
            "title": "The Mask",
            "director": "Chuck Russel"
          }
        ]
      }
    ]
  }
}

Add actor to movie

mutation addActorToMovie {
  addActorToMovie(movieId: 1, actorId: 4) {
    title
    releaseDate
    director
    actors {
      name
    }
  }
}

Response

{
  "data": {
    "addActorToMovie": {
      "title": "The One",
      "releaseDate": "1993-02-26",
      "director": "Quentin Tarantino",
      "actors": [
        {
          "name": "John Travolta"
        },
        {
          "name": "Jim Carrey"
        }
      ]
    }
  }
}

Add movie to actor

mutation addMovieToActor {
  addMovieToActor(movieId: 2, actorId: 4) {
    name
    id
    movies {
      title
      actors {
        name
      }
    }
  }
}

Response

{
  "data": {
    "addMovieToActor": {
      "name": "Jim Carrey",
      "id": 4,
      "movies": [
        {
          "title": "Pulp Fiction",
          "actors": [
            {
              "name": "Quentin Tarantino"
            },
            {
              "name": "John Travolta"
            },
            {
              "name": "Samuel L Jackson"
            },
            {
              "name": "Jim Carrey"
            }
          ]
        },
        {
          "title": "The Mask",
          "actors": [
            {
              "name": "Jim Carrey"
            }
          ]
        }
      ]
    }
  }
}

quarkus-reactive-hibernate-graphql-crud's People

Contributors

dvddhln avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

quarkus-reactive-hibernate-graphql-crud's Issues

Update quarkus 2.4.2.Final โ†’ graphql error

After update quarkus to 2.4.2.Final I get the following error โ€“ any idea how to fix this? Using quarkus 2.0.2.Final everything is OK.

query allMovies {
  allMovies {
    title
    actors {
      name
    }
  }
}

error


2021-11-16 ERROR [io.sma.graphql] (executor-thread-1) SRGQL012000: Data Fetching Error: java.lang.IllegalStateException: HR000069: Detected use of the reactive Session from a different Thread than the one which was used to open the reactive Session - this suggests an invalid integration; original thread: 'vert.x-eventloop-thread-12' current Thread: 'executor-thread-1'
	at org.hibernate.reactive.common.InternalStateAssertions.assertCurrentThreadMatches(InternalStateAssertions.java:46)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.threadCheck(ReactiveSessionImpl.java:154)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.checkOpen(ReactiveSessionImpl.java:1556)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.buildReactiveQueryFromName(ReactiveSessionImpl.java:474)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.createReactiveNamedQuery(ReactiveSessionImpl.java:465)
	at org.hibernate.reactive.mutiny.impl.MutinySessionImpl.createNamedQuery(MutinySessionImpl.java:252)

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.