Code Monkey home page Code Monkey logo

dgs-examples-kotlin's Introduction

Kotlin DGS Framework example

This repository is an example application for the DGS Framework. The example is a standalone GraphQL server in Java.

It shows the following features:

Other examples

There are other examples of using the DGS framework as well:

Shows and Reviews

This example is built around two main types: Show and Review. A Show represents a series or movie you would find on Netflix. For ease of running the demo, the list of shows is hardcoded in ShowsServiceImpl. A show can have Reviews. Again, for ease of running the demo, a list of reviews is generated during startup for each show in DefaultReviewsService.

Reviews can also be added by users of the API using a mutation, and a GraphQL Subscription is available to watch for added reviews.

There's also a mutation available to add Artwork for a show, demonstrating file uploads. Uploaded files are stored in a folder uploaded-images in the work directory where ethe application is started.

Starting the example

The example requires Java 11. Run the application in an IDE using its main class or using Gradle:

./gradlew bootRun

Interact with the application using GraphiQL on http://localhost:8080/graphiql.

dgs-examples-kotlin's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dgs-examples-kotlin's Issues

how to integrate graphql-java-extended-validation into DGS?

Can dgs be integrated with implementation("com.graphql-java:graphql-java-extended-validation:2022-04-27T05-15-47-b3d9bc3") ?

and how to do it?

    implementation("com.graphql-java:graphql-java-extended-validation:2022-04-27T05-15-47-b3d9bc3")
    implementation("org.hibernate.validator:hibernate-validator:7.0.4.Final")
type Query {
    shows(titleFilter: String @NotBlank): [Show]
}

@DgsComponent
class ValidationConfig {

    @DgsRuntimeWiring
    fun addValidationDirective(builder: RuntimeWiring.Builder): RuntimeWiring.Builder {
        val validationRules = ValidationRules.newValidationRules()
            .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
            .build()
        val wiring = ValidationSchemaWiring(validationRules)  // SchemaDirectiveWiring
        return builder.directiveWiring(wiring)
    }
    
}
2022-05-22 17:57:10.242  WARN 60792 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception; nested exception is SchemaProblem{errors=['titleFilter' [@2:11] tried to use an undeclared directive 'NotBlank']}
2022-05-22 17:57:10.244  INFO 60792 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-05-22 17:57:10.254  INFO 60792 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-22 17:57:10.271 ERROR 60792 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

There are problems with the GraphQL Schema:
	 * 'titleFilter' [@2:11] tried to use an undeclared directive 'NotBlank'

Extend Example to show Pagination with a DataLoader

Request:
Update the example to include pagination in combination with a dataloader.

Issue:
Bootstrapping pagination into the data loader is proving to be a bit difficult to grok based on the documentation. There is an example provided by @paulbakker here with the connection serialisation carried out manually, but is less clear when using the SimpleListConnection type that is leveraged by the codegeneration tools in the documentation.

A canonical end-to-end example would be very useful!

Edit:

I ended up working this out. You can simply wrap the response from the data loader in something like:

      return dataLoader.load(id).thenApply{
          SimpleListConnection(it ?: emptyList()).get(environment)
      }

If I get time after the christmas break, I'll create a fork/pr to add relay connections into the example to make it more complete

Data Fetchers with Kotlin

I don't understand why data fetchers are not generated when used with language = "KOTLIN" while java working fine. Any support for this in future?

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.