Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.81 KB

README.md

File metadata and controls

56 lines (43 loc) · 1.81 KB

Spring-Graphql JPA Sample Application

Kotlin build status PR's Welcome

This project aims to be an example project using the latest spring-graphql libraries with a modest JPA data model.

Running the project

running the project is simple and does not require any database or external dependencies other than Java 11 as the DB is entirely using H2

To run, simply run

./gradlew bootRun

GraphiQL client is available at

http://localhost:8811/graphiql?path=/graphql

The application server will run on post 8811 By default, query logging and Hibernate statistics are turned on in order to visualize some of the performance benefits that can be found using Data Loaders/Data Fetchers. This also demonstrates how N+1 problems can be avoided.

The application is a simple message board, with user, post, and comment entities. The graphql schema can be found in src/resources/graphql/schema.graphqls The most complicated query, is getPostComments, where the post, comments, and authors can all be returned in one query.

query {
    getPostComments(postId: 40) {
        id
        text
        authorUser {
            id
            name
        }
        post {
            id
            text
            authorUser {
                id
                name
            }
        }
    }
}

Example Request using curl

curl http://localhost:8811/graphql -H 'Content-Type: application/json' -d '{"query": "query { getUsers { id name } }"}'