Netflix DGS Framework

repository·master·Indexed 25 days ago

https://github.com/netflix/dgs-framework

A specialized GraphQL server framework for Spring Boot applications developed by Netflix. It provides an annotation-based programming model, a test framework for unit testing queries, a Gradle Code Generation plugin for schema types, and support for GraphQL Federation, Spring Security, file uploads, and subscriptions via WebSockets and SSE.

Tokens
3.7K
Snippets
7
Records
29
Agent score
85%

What's inside DGS Framework

  1. Overview of the DGS Framework

    master

    The DGS Framework (Domain Graph Service) is a GraphQL server framework for Spring Boot developed by Netflix. It provides an annotation-based Spring Boot programming model and includes features such as:

    • A test framework for writing query tests as unit tests.
    • A Gradle Code Generation plugin to create types from your GraphQL schema.
    • Easy integration with GraphQL Federation.
    • Integration with Spring Security.
    • Support for GraphQL subscriptions via WebSockets and SSE.
    • File upload support.
    • Robust error handling.
    • Numerous extension points for customization.
  2. Manage DGS Framework dependencies using the Bill of Materials (BOM)

    master

    Use the graphql-dgs-platform Bill of Materials (BOM) to simplify dependency management in Maven or Gradle projects. This BOM provides version recommendations for DGS Framework Modules and their public API dependencies.

    Note: This BOM only includes dependencies exposed as part of the DGS Framework API. If you require a BOM that includes internal dependencies used by the framework, use the graphql-dgs-platform-dependencies BOM instead.

  3. Manage GraphQL DGS dependencies using the Bill of Materials (BOM)

    master
    To simplify dependency management and ensure version compatibility across various DGS Framework modules, use the GraphQL DGS Bill of Materials (BOM). This BOM includes references to DGS Framework Modules and recommended dependency versions used internally by Netflix. It can be imported into either Maven or Gradle projects to manage transitive dependencies effectively.
  4. Run the DGS Spring GraphQL WebFlux example app

    master

    To start the example application, run the ExampleApp class from your IDE. This application demonstrates DGS framework features and includes a React UI that connects to both /graphql and /subscriptions endpoints using Apollo Client.

    Once running, you can access the following interfaces:

    • GraphiQL IDE: http://localhost:8080/graphiql
    • Example React UI: http://localhost:8080/index.html
  5. Run the DGS Spring GraphQL Java example app

    master

    To start the example application, run the ExampleApp class from your IDE. This application demonstrates DGS framework features and includes a React UI that connects to both /graphql and /subscriptions endpoints via Apollo Client.

    Once running, you can access the following:

    • GraphiQL interface: http://localhost:8080/graphiql
    • React UI: http://localhost:8080/index.html
  6. Check DGS Framework version compatibility

    master

    Ensure your Spring Boot version is compatible with the DGS version you intend to use:

    DGS VersionSpring Boot VersionStatus
    11+4Actively maintained
    10.x3Most features will be backported until the second half of 2026
    5.x2No longer maintained
  7. Use DgsCustomMonoGraphQLClient instead of CustomMonoGraphQLClient

    master

    The CustomMonoGraphQLClient class is deprecated because it is tied to Jackson 2. For future compatibility and support for any DgsJsonMapper (including Jackson 3), you should migrate to DgsCustomMonoGraphQLClient.

    Migration Path: Replace com.netflix.graphql.dgs.client.CustomMonoGraphQLClient with com.netflix.graphql.dgs.client.DgsCustomMonoGraphQLClient.

  8. Use WebClientGraphQLClient for reactive GraphQL queries

    master

    The WebClientGraphQLClient provides a reactive way to execute GraphQL queries using Spring's WebClient. It returns a Mono<GraphQLResponse>, allowing you to extract data or handle errors reactively. You can provide a WebClient instance configured with your GraphQL endpoint URL.

    WebClientGraphQLClient webClientGraphQLClient =
        new WebClientGraphQLClient(WebClient.create("http://localhost:8080/graphql"));
    GraphQLResponse message = webClientGraphQLClient.reactiveExecuteQuery("{hello}")
                                                    .map(r -> r.extractValue<String>("hello"));
    message.subscribe();
  9. Execute reactive GraphQL queries with variables and operation names

    master

    The WebClientGraphQLClient supports several variations of reactiveExecuteQuery to handle different query requirements:

    • reactiveExecuteQuery(query: String): Executes a simple query string.
    • reactiveExecuteQuery(query: String, variables: Map<String, Any>): Executes a query with a map of input variables.
    • reactiveExecuteQuery(query: String, variables: Map<String, Any>, operationName: String?): Executes a query with variables and a specific operation name.
    • reactiveExecuteQuery(query: String, requestBodyUriCustomizer: RequestBodyUriCustomizer): Allows customizing the request URI and headers via a customizer.
    • reactiveExecuteQuery(query: String, variables: Map<String, Any>, operationName: String?, requestBodyUriCustomizer: RequestBodyUriCustomizer): The most flexible method, combining variables, operation names, and URI/header customization.