Skip to content

Commit

Permalink
Merge pull request #1766 from Netflix/spring-graphql-refactored
Browse files Browse the repository at this point in the history
Integrate DGS Framework with Spring-GraphQL . The DGS framework will now use SpringGraphQL's execution engine , and transport handlers for graphql requests. This feature introduces a new starter for users com.netflix.graphql.dgs:graphql-dgs-spring-graphql-starter for opting in to the Spring-GraphQL integration. We have also added a new module for the autoconfiguration and integration points specific to Spring GraphQL and a corresponding example app that demonstrates functionality for existing DGS features and some Spring GraphQL features as well.

---------

Co-authored-by: Paul Bakker<paul.bakker.nl@gmail.com>
Co-authored-by: Kavitha Srinivasan <ksrinivasan@netflix.com>
  • Loading branch information
srinivasankavitha and srinivasankavitha committed Mar 29, 2024
2 parents c9f3dd2 + 73922d1 commit 7d0ac42
Show file tree
Hide file tree
Showing 109 changed files with 32,049 additions and 306 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Expand Up @@ -15,6 +15,7 @@
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI

buildscript {
repositories {
Expand Down Expand Up @@ -58,6 +59,12 @@ allprojects {
extra["kotlin.version"] = Versions.KOTLIN_VERSION
val springBootVersion = extra["sb.version"] as String

configurations.all {
resolutionStrategy {
force("org.springframework.graphql:spring-graphql:1.2.6")
}
}

dependencyRecommendations {
mavenBom(mapOf("module" to "org.jetbrains.kotlin:kotlin-bom:${Versions.KOTLIN_VERSION}"))

Expand Down
6 changes: 0 additions & 6 deletions graphql-dgs-example-java-webflux/dependencies.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -44,7 +44,7 @@ void withHeaders() {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
servletRequest.addHeader("demo-header", "demo-header-value");

String message = queryExecutor.executeAndExtractJsonPath("{headers}", "data.headers", new ServletWebRequest(servletRequest));
String message = queryExecutor.executeAndExtractJsonPath("{demoHeader}", "data.demoHeader", new ServletWebRequest(servletRequest));
assertThat(message).isEqualTo("demo-header-value");
}

Expand All @@ -53,7 +53,7 @@ void withHeadersAndNoRequest() {
HttpHeaders headers = new HttpHeaders();
headers.add("demo-header", "demo-header-value");

String message = queryExecutor.executeAndExtractJsonPath("{headers}", "data.headers", headers);
String message = queryExecutor.executeAndExtractJsonPath("{demoHeader}", "data.demoHeader", headers);
assertThat(message).isEqualTo("demo-header-value");
}
}
Expand Up @@ -25,8 +25,6 @@
import graphql.relay.SimpleListConnection;
import graphql.schema.DataFetchingEnvironment;
import org.dataloader.DataLoader;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Expand Up @@ -28,7 +28,14 @@

@DgsComponent
public class RequestHeadersDataFetcher {

@DgsData(parentType = "Query", field = "headers")
public String headers(DgsDataFetchingEnvironment dfe) {
HttpHeaders headers = dfe.getDgsContext().getRequestData().getHeaders();
return headers.toString();
}

@DgsData(parentType = "Query", field = "demoHeader")
public String headers(DgsDataFetchingEnvironment dfe, @RequestHeader("demo-header") String demoHeader) {
return demoHeader;
}
Expand Down
Expand Up @@ -21,10 +21,9 @@ type Query {
concurrent1: Int
concurrent2: Int

nested: [NestedA!]!

headers: String
referer: String
demoHeader: String

### To show how to handle HttpHeaders
helloWithHeaders(name: String): String
Expand All @@ -33,14 +32,6 @@ type Query {
withCookie: String
}

type NestedA {
nested2: Nested2!
}

type Nested2 {
message: String
}

type Message @connection {
info: String
}
Expand Down Expand Up @@ -95,3 +86,5 @@ type Stock {
scalar Upload
scalar LocalTime

directive @connection on OBJECT

@@ -0,0 +1,35 @@
/*
* Copyright 2024 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.graphql.dgs.pagination

import org.springframework.boot.SpringApplication
import org.springframework.boot.env.EnvironmentPostProcessor
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.MapPropertySource

class DgsPaginationEnvironmentPostProcessor : EnvironmentPostProcessor {
override fun postProcessEnvironment(environment: ConfigurableEnvironment, application: SpringApplication) {
val properties = mutableMapOf<String, Any>()
properties["dgs.springgraphql.pagination.enabled"] = false
environment.propertySources.addLast(
MapPropertySource(
"dgs-pagination-defaults",
properties
)
)
}
}
@@ -0,0 +1 @@
org.springframework.boot.env.EnvironmentPostProcessor=com.netflix.graphql.dgs.pagination.DgsPaginationEnvironmentPostProcessor
5 changes: 3 additions & 2 deletions graphql-dgs-reactive/build.gradle.kts
Expand Up @@ -16,8 +16,9 @@

dependencies {
api(project(":graphql-dgs"))
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework:spring-webflux")
compileOnly("org.springframework.boot:spring-boot-starter")
compileOnly("org.springframework:spring-webflux")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
Expand Down

0 comments on commit 7d0ac42

Please sign in to comment.