Giter Club home page Giter Club logo

spring-graphql-sample's Introduction

spring-graphql-sample

Spring GraphQL examples using the following frameworks and libraries:

Other GraphQL Java integration examples with Java frameworks.

Guide

TBD

Example Codes

Example name Description
dgs Simple Netflix DGS example
dgs-webflux Simple Netflix DGS example with Spring WebFlux
dgs-subscription-ws Simple Netflix DGS Subscription example using WebSocket protocol
dgs-subscription-ui Angular Client app for dgs-subscription-ws
dgs-subscription-sse Simple Netflix DGS Subscription example using Http/SSE protocol
dgs-codegen Netflix DGS example with Spring Jdbc and Gradle codegen plugin
dgs-fileupload Netflix DGS file upload example
dgs-client Netflix DGS Typesafe Client example
dgs-kotlin-co A complete Netflix DGS example with WebFlux, Kotlin Coroutines, Spring Data R2dbc and Spring Security
dgs-kotlin A complete Netflix DGS example with WebMvc/Kotlin, Spring Data Jdbc, Spring Security and Spring Session/Spring Data Redis
graphql-kotlin ExpediaGroup Graphql Kotlin Spring Boot example
spring-graphql Spring GraphQL example
spring-graphql-webmvc Spring GraphQL with WebMvc Controller annotation example
spring-graphql-querydsl Spring GraphQL/JPA/QueryDSl Data Fetchers example
spring-graphql-webflux Spring GraphQL/WebFlux example with WebSocket transport protocol
spring-graphql-rsocket-kotlin-co Spring GraphQL/WebFlux/Kotlin Coroutines example with RSocket transport protocol

Legacy Codes

Some example codes are moved to legacy folder, because the upstream project is discontinued or under an inactive development status.

Example name Description
graphql-java GraphQL Java vanilla Spring Boot example, upstream project is discontinuned, replaced by Spring GraphQL
graphql-spqr GraphQL SPQR Spring example, inactive
graphql-java-kickstart GraphQL Java Kickstart Spring Boot example
graphql-java-kickstart-webclient GraphQL Java Kickstart Spring WebClient example
graphql-java-kickstart-annotations GraphQL Java Kickstart Spring Boot example(Code first)

Prerequisites

Make sure you have installed the following software.

  • Java 21
  • Apache Maven 3.8.x / Gradle 7.x
  • Docker

Some sample codes are written in Kotlin. If you are new to Kotlin, start to learn it from the the Kotlin homepage.

Build

Clone the source codes from Github.

git clone https://github.com/hantsy/spring-graphql-sample/

Open a terminal, and switch to the root folder of the project, and run the following command to build the whole project.

docker-compose up postgres // start up a postgres it is required
cd examplename // change to the example folder
mvn clean install // build the project
//or
./gradlew build

Run the application.

mvn spring-boot:run 
//or 
./gradlew bootRun
// or from command line after building
java -jar target/xxx.jar

Contribution

Any suggestions are welcome, filing an issue or submitting a PR is also highly recommended.

References

spring-graphql-sample's People

Contributors

dependabot[bot] avatar hantsy avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-graphql-sample's Issues

spring-graphql是否能自定义异常处理逻辑?

代码片段如下:

@MutationMapping
Author deleteAuthor(@Argument("id") Long id) {
    throw new BusinessException("delete operation not supported yet.");
}

如上面的代码,我抛出了一个自定义的业务异常。应答为:

{
  "errors": [
    {
      "message": "delete operation not supported yet.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "deleteAuthor"
      ],
      "extensions": {
        "classification": "INTERNAL_ERROR"
      }
    }
  ],
  "data": {
    "deleteAuthor": null
  }
}

如果把异常的分类定义为 INTERNAL_ERROR 我觉得并不是特别合理。

您如果知道的话,请赐教。 注意到您是spring-graphql项目中唯一一位**贡献者,特意过来问问您。请勿见怪。

以上例子出自这里

How do your data fetchers work with Flow?

How do your data fetchers work when the return Flows?

When I return a flow from my datafetchers I'm getting this error:

{
  "errors": [
    {
      "message": "Can't resolve value (/accounts) : type mismatch error, expected type LIST",
      "path": [
        "accounts"
      ],
      "extensions": {
        "classification": "DataFetchingException"
      }
    }
  ],
  "data": {
    "accounts": null
  }
}

Dgs-webflux build problem

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method dgsReactiveQueryExecutor in com.netflix.graphql.dgs.webflux.autoconfiguration.DgsWebFluxAutoConfiguration required a bean of type 'graphql.schema.GraphQLSchema' that could not be found.


Action:

Consider defining a bean of type 'graphql.schema.GraphQLSchema' in your configuration.

Yml

spring:
  main:
    web-application-type: reactive
  autoconfigure:
    exclude: com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration

dgs:
  graphql:
    schema-locations: classpath*:graphql/**/*.graphql*
    path: /graphql

The version is same like you but use kt

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.