GithubHelp home page GithubHelp logo

spring-boot-graphql's Introduction

Spring Boot and GraphQL

This demo project demonstrates integration between Spring Boot and GraphQL. Integrating GraphQL with Spring Boot is straightforward. Spring Boot provides a range of tools and libraries for building GraphQL APIs.

How to integrate Spring Boot with GraphQL

To integrate GraphQL with Spring Boot, you can follow these general steps:

  1. Define your GraphQL schema. Example is located in directory src/main/resources/graphql
  2. Use the graphql-spring-boot-starter library to expose your GraphQL API over HTTP
  3. Use the GraphQL UI (http://localhost:8080/graphiql) for exploring and testing GraphQL API

Examples from this demo

GraphQL schema is defined into file schema.graphqls located on src/main/resources/graphql. Developed endpoints are:

  • Get all users
  • Get user by unique identifier (id)
  • Get page of users
  • Create user
  • Get all roles
  • Get all departments

Example 1 (Get all users):

query {
    allUsers {
        id
        email
        age
        department {
            id
            name
        }
    }
}

Example 2 (Get page of users):

query {
  usersPage(page: 0, size: 10) {
    nodes {
      id
      email
      roles {
        name
      }
    }
    pageInfo {
      totalElements
      totalPages
    }
  }
}

Example 3 (Get all departments):

query {
    allDepartments {
        id
        name
    }
}

Example 4 (Create user):

mutation {
    createUser(user: {
        firstName: "Jack"
        lastName: "Sparow"
        email: "[email protected]"
        age: 40
        department {
            id: 1
        }
        roles: [{
            id: 1
        }]
    }) {
        id
        email
        age
    }
}

Contribution/Suggestions

If someone is interested in contribution or have some suggestions please contact me on email [email protected].

Author

Heril Muratović
Software Engineer

Mobile/Viber/WhatsUp: +382 69 657 962
Email: [email protected]
Skype: hedza06
Twitter: herilmuratovic
LinkedIn: https://www.linkedin.com/in/heril-muratovi%C4%87-021097132/
StackOverflow: https://stackoverflow.com/users/4078505/heril-muratovic

spring-boot-graphql's People

Contributors

hedza06 avatar

Watchers

 avatar

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.