GithubHelp home page GithubHelp logo

lazarevd / graphql-spring-boot-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vladimir-dejanovic/graphql-spring-boot-example

0.0 1.0 0.0 24 KB

graphql-spring-boot-example

License: GNU General Public License v3.0

Java 100.00%

graphql-spring-boot-example's Introduction

GraphQL example implemented with Spring Boot

This is simple example of GraphQL API implemented in Java with Spring Boot, and relaying on it's magic :)

There is example of implementation of Query and Subscription.

Dependencies

GraphQL

For GraphQL dependency added

        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-java</artifactId>
            <version>8.0</version>
        </dependency>
        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-java-tools</artifactId>
            <version>5.0.0</version>
        </dependency>

GraphQL Spring Boot integration

To connect GraphQL and Spring Boot added this dependency

        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-spring-boot-starter</artifactId>
            <version>5.0.2</version>
        </dependency>

GraphiQL "out of the box"

In order to get GraqhiQL, UI for testing local version of GraphQL API added this dependency

        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphiql-spring-boot-starter</artifactId>
            <version>5.0.2</version>
        </dependency>

For GraphiQL hit http://localhost:8080/graphiql, when you start application

Query implementation

Query implementation is almost exactly the same like all other my examples of Query. Only difference is annotation @Component at top. For full code just open Query.java

Query example in GraphiQL

query {
  allData {
    message
  }
}

Mutation implementation

Mutation implementation is almost exactly the same like all other my examples of Mutation. Only difference is annotation @Component at top. For full code just open Mutation.java

Mutation example in GraphiQL

mutation {
  add(message:"Hello") {
    message
  }
}

after mutation you can run query again and check if all worked as intended.

Subscription implementation

Subscription implementation is done using RXJava and by implementing GraphQLSubscriptionResolver

For full code example check Subscription.java

Subscription can be tested from GraphiQL.

Subscription example in GraphiQL

subscription {
  data {
    message
  }
}

graphql-spring-boot-example's People

Contributors

vladimir-dejanovic 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.