Skip to content

Commit

Permalink
chore(deps): bump dgs to 10.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Jan 3, 2025
1 parent db83da3 commit f2f3dd0
Show file tree
Hide file tree
Showing 63 changed files with 780 additions and 554 deletions.
23 changes: 15 additions & 8 deletions dgs-client/src/main/java/com/example/demo/DemoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import com.example.demo.gql.client.PostProjection;
import com.example.demo.gql.types.Post;
import com.jayway.jsonpath.TypeRef;
import com.netflix.graphql.dgs.client.*;
import com.netflix.graphql.dgs.client.CustomGraphQLClient;
import com.netflix.graphql.dgs.client.GraphQLClient;
import com.netflix.graphql.dgs.client.GraphQLResponse;
import com.netflix.graphql.dgs.client.HttpResponse;
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.intellij.lang.annotations.Language;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
Expand Down Expand Up @@ -44,20 +48,20 @@ private static HttpResponse execute(String url, Map<String, ? extends List<Strin
* To use RestTemplate, the requestHeaders need to be transformed into Spring's HttpHeaders.
*/
HttpHeaders requestHeaders = new HttpHeaders();
headers.forEach(requestHeaders::put);
requestHeaders.putAll(headers);

/**
* Use RestTemplate to call the GraphQL service.
* The response type should simply be String, because the parsing will be done by the GraphQLClient.
*/
var dgsRestTemplate = new RestTemplate();
ResponseEntity<String> exchange = dgsRestTemplate.exchange(url, HttpMethod.POST, new HttpEntity(body, requestHeaders), String.class);
ResponseEntity<String> exchange = dgsRestTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body, requestHeaders), String.class);

/**
* Return a HttpResponse, which contains the HTTP status code and response body (as a String).
* The way to get these depend on the HTTP client.
*/
return new HttpResponse(exchange.getStatusCodeValue(), exchange.getBody());
return new HttpResponse(exchange.getStatusCode().value(), exchange.getBody());
}


Expand Down Expand Up @@ -87,7 +91,7 @@ public void run(ApplicationArguments args) throws Exception {
GraphQLQueryRequest graphQLQueryRequest =
new GraphQLQueryRequest(
new AllPostsGraphQLQuery(),
new AllPostsProjectionRoot<AuthorProjection<?,?>,PostProjection<?,?>>()
new AllPostsProjectionRoot<AuthorProjection<?, ?>, PostProjection<?, ?>>()
.id()
.title()
.content()
Expand All @@ -98,11 +102,14 @@ public void run(ApplicationArguments args) throws Exception {
.createdAt()
);

String query = graphQLQueryRequest.serialize();
@Language("graphql") String query = graphQLQueryRequest.serialize();
log.info("query string: {}", query);

GraphQLClient client = new CustomGraphQLClient(url, DemoApplication::execute);
GraphQLResponse response = client.executeQuery(query, new HashMap<>() );
GraphQLResponse response = client.executeQuery(query, new HashMap<>());

var data = response.extractValueAsObject("allPosts", new TypeRef<List<Post>>() { });
var data = response.extractValueAsObject("allPosts", new TypeRef<List<Post>>() {
});
log.info("fetched all posts from client: {}", data);
}
}
5 changes: 3 additions & 2 deletions dgs-codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ repositories {

dependencyManagement {
imports {
mavenBom("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:9.2.2")
mavenBom("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:10.0.1")
}
}

dependencies {
// implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:8.2.0"))
implementation "com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter", {
implementation "com.netflix.graphql.dgs:dgs-starter", {
exclude group: 'org.yaml', module: 'snakeyaml'
}

Expand All @@ -55,6 +55,7 @@ dependencies {
testCompileOnly 'org.projectlombok:lombok:1.18.36'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.36'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation "com.netflix.graphql.dgs:dgs-starter-test"
}

generateJava {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.example.demo.gql;

import com.example.demo.gql.directives.UppercaseDirectiveWiring;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsRuntimeWiring;
import graphql.schema.idl.RuntimeWiring;
import graphql.validation.rules.OnValidationErrorStrategy;
import graphql.validation.rules.ValidationRules;
import graphql.validation.schemawiring.ValidationSchemaWiring;
import lombok.RequiredArgsConstructor;

//@DgsComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,61 @@


import com.netflix.graphql.dgs.DgsScalar;
import graphql.GraphQLContext;
import graphql.execution.CoercedVariables;
import graphql.language.NullValue;
import graphql.language.StringValue;
import graphql.language.Value;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@DgsScalar(name = "LocalDateTime")
public class LocalDateTimeScalar implements Coercing<LocalDateTime, String> {

@Nullable
@Override
public String serialize(Object dataFetcherResult) throws CoercingSerializeException {
if (dataFetcherResult instanceof LocalDateTime) {
return ((LocalDateTime) dataFetcherResult).format(DateTimeFormatter.ISO_DATE_TIME);
} else {
throw new CoercingSerializeException("Not a valid DateTime");
public String serialize(@NotNull Object dataFetcherResult, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingSerializeException {
if (dataFetcherResult instanceof LocalDateTime dateTime) {
return dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
}

throw new CoercingSerializeException("Not a valid DateTime");
}

@Nullable
@Override
public LocalDateTime parseValue(Object input) throws CoercingParseValueException {
return LocalDateTime.parse(input.toString(), DateTimeFormatter.ISO_DATE_TIME);
public LocalDateTime parseValue(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseValueException {
if (input instanceof LocalDateTime dateTime) {
return LocalDateTime.parse(dateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
}

throw new CoercingParseValueException("Value is not a valid ISO date time");
}

@Nullable
@Override
public LocalDateTime parseLiteral(Object input) throws CoercingParseLiteralException {
if (input instanceof StringValue) {
return LocalDateTime.parse(((StringValue) input).getValue(), DateTimeFormatter.ISO_DATE_TIME);
public LocalDateTime parseLiteral(@NotNull Value<?> input, @NotNull CoercedVariables variables, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseLiteralException {
if (input instanceof StringValue value) {
return LocalDateTime.parse(value.getValue(), DateTimeFormatter.ISO_DATE_TIME);
}

throw new CoercingParseLiteralException("Value is not a valid ISO date time");
}

@Override
public @NotNull Value<?> valueToLiteral(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) {
if (input instanceof LocalDateTime dateTime) {
return StringValue.of(dateTime.format(DateTimeFormatter.ISO_DATE_TIME));
}
return NullValue.of();
}

}
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
package com.example.demo.gql.scalars;

import com.netflix.graphql.dgs.DgsScalar;
import graphql.GraphQLContext;
import graphql.execution.CoercedVariables;
import graphql.language.StringValue;
import graphql.language.Value;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.UUID;

@DgsScalar(name = "UUID")
public class UUIDScalar implements Coercing<UUID, String> {

@Override
public @NotNull Value<?> valueToLiteral(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) {
return StringValue.of(input.toString());
}

@Nullable
@Override
public String serialize(Object o) throws CoercingSerializeException {
if (o instanceof UUID) {
return ((UUID) o).toString();
} else {
throw new CoercingSerializeException("Not a valid UUID");
public UUID parseLiteral(@NotNull Value<?> input, @NotNull CoercedVariables variables, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseLiteralException {
if (input instanceof StringValue value) {
return UUID.fromString(value.getValue());
}

throw new CoercingParseLiteralException("Value is not a valid UUID string");
}

@Nullable
@Override
public UUID parseValue(Object o) throws CoercingParseValueException {
return UUID.fromString(o.toString());
public UUID parseValue(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseValueException {
return UUID.fromString(input.toString());
}

@Nullable
@Override
public UUID parseLiteral(Object input) throws CoercingParseLiteralException {
if (input instanceof StringValue) {
return UUID.fromString(((StringValue) input).getValue());
public String serialize(@NotNull Object dataFetcherResult, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingSerializeException {
if (dataFetcherResult instanceof UUID uuid) {
return uuid.toString();
}

throw new CoercingParseLiteralException("Value is not a valid UUID string");
throw new CoercingSerializeException("Not a valid UUID");
}
}
12 changes: 5 additions & 7 deletions dgs-codegen/src/test/java/com/example/demo/MutationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
import com.example.demo.service.AuthorService;
import com.example.demo.service.PostService;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedValidationAutoConfiguration;
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
import com.netflix.graphql.dgs.test.EnableDgsTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.util.UUID;

Expand All @@ -30,6 +29,7 @@
import static org.mockito.Mockito.*;

@SpringBootTest(classes = MutationTests.MutationTestsConfig.class)
@EnableDgsTest
@Slf4j
class MutationTests {

Expand All @@ -42,9 +42,7 @@ class MutationTests {
CustomDataFetchingExceptionHandler.class
})
@ImportAutoConfiguration(classes = {
DgsAutoConfiguration.class,
DgsExtendedValidationAutoConfiguration.class,
JacksonAutoConfiguration.class
})
static class MutationTestsConfig {

Expand All @@ -53,10 +51,10 @@ static class MutationTestsConfig {
@Autowired
DgsQueryExecutor dgsQueryExecutor;

@MockBean
@MockitoBean
PostService postService;

@MockBean
@MockitoBean
AuthorService authorService;

@Test
Expand Down
15 changes: 5 additions & 10 deletions dgs-codegen/src/test/java/com/example/demo/QueryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
import com.example.demo.service.PostNotFoundException;
import com.example.demo.service.PostService;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
import com.netflix.graphql.dgs.test.EnableDgsTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.util.List;
import java.util.Map;
Expand All @@ -31,16 +29,17 @@
import static org.mockito.Mockito.*;

@SpringBootTest(classes = {QueryTests.QueryTestsConfig.class})
@EnableDgsTest
@Slf4j
class QueryTests {

@Autowired
DgsQueryExecutor dgsQueryExecutor;

@MockBean
@MockitoBean
PostService postService;

@MockBean
@MockitoBean
AuthorService authorService;

@Configuration
Expand All @@ -50,10 +49,6 @@ class QueryTests {
LocalDateTimeScalar.class,
UppercaseDirectiveWiring.class
})
@ImportAutoConfiguration(value = {
DgsAutoConfiguration.class,
JacksonAutoConfiguration.class
})
static class QueryTestsConfig {

}
Expand Down
14 changes: 5 additions & 9 deletions dgs-fileupload/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,26 @@ repositories {

dependencyManagement {
imports {
mavenBom("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:9.2.2")
mavenBom("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:10.0.1")
}
}

dependencies {
//implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:8.2.0"))
implementation "com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter", {
exclude group: 'org.yaml', module: 'snakeyaml'
}
implementation 'com.netflix.graphql.dgs:graphql-dgs-extended-scalars', {
exclude group: 'org.yaml', module: 'snakeyaml'
}// auto-configure graphql extended scalars
implementation 'org.yaml:snakeyaml:2.3'
implementation "com.netflix.graphql.dgs:dgs-starter"
implementation 'com.netflix.graphql.dgs:graphql-dgs-extended-scalars'
implementation 'org.apache.commons:commons-lang3:3.17.0'

// spring web
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'name.nkonev.multipart-spring-graphql:multipart-spring-graphql:1.5.3'

//configure Lombok for compile java/ compile tests
compileOnly 'org.projectlombok:lombok:1.18.36'
annotationProcessor 'org.projectlombok:lombok:1.18.36'
testCompileOnly 'org.projectlombok:lombok:1.18.36'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.36'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.netflix.graphql.dgs:dgs-starter-test'
}

test {
Expand Down
Loading

0 comments on commit f2f3dd0

Please sign in to comment.