This commit is contained in:
Philippe Sevestre
2024-02-21 23:01:37 -03:00
121 changed files with 2205 additions and 349 deletions
@@ -1,7 +1,7 @@
<html>
<head>
<title>WebJars Demo</title>
<link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}" />
</head>
<body>
<h1>Welcome Home</h1>
@@ -12,8 +12,8 @@
</div>
</div>
<script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
<script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
<script th:src="@{/webjars/jquery/3.1.1/jquery.min.js}"></script>
<script th:src="@{/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js}"></script>
</body>
</html>
@@ -0,0 +1,30 @@
package com.baeldung.returnnull;
import graphql.schema.Coercing;
import graphql.schema.GraphQLScalarType;
public class GraphQLVoidScalar {
public static final GraphQLScalarType Void = GraphQLScalarType.newScalar()
.name("Void")
.description("A custom scalar that represents the null value")
.coercing(new Coercing() {
@Override
public Object serialize(Object dataFetcherResult) {
return null;
}
@Override
public Object parseValue(Object input) {
return null;
}
@Override
public Object parseLiteral(Object input) {
return null;
}
})
.build();
}
@@ -0,0 +1,14 @@
package com.baeldung.returnnull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
@Configuration
public class GraphQlConfig {
@Bean
public RuntimeWiringConfigurer runtimeWiringConfigurer() {
return wiringBuilder -> wiringBuilder.scalar(GraphQLVoidScalar.Void);
}
}
@@ -0,0 +1,51 @@
package com.baeldung.returnnull;
public class Post {
private String id;
private String title;
private String text;
private String category;
private String author;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
@@ -0,0 +1,28 @@
package com.baeldung.returnnull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.stereotype.Controller;
@Controller
public class PostController {
List<Post> posts = new ArrayList<>();
@MutationMapping
public Void createPostReturnCustomScalar(@Argument String title, @Argument String text, @Argument String category, @Argument String author) {
Post post = new Post();
post.setId(UUID.randomUUID()
.toString());
post.setTitle(title);
post.setText(text);
post.setCategory(category);
post.setAuthor(author);
posts.add(post);
return null;
}
}
@@ -0,0 +1,14 @@
package com.baeldung.returnnull;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ReturnNullApp {
public static void main(String[] args) {
System.setProperty("spring.profiles.default", "returnnull");
SpringApplication.run(com.baeldung.chooseapi.ChooseApiApp.class, args);
}
}
@@ -0,0 +1,9 @@
server:
port: 8082
spring:
graphql:
graphiql:
enabled: true
schema:
locations: classpath:returnnull/
@@ -0,0 +1,18 @@
scalar Void
type Mutation {
createPostReturnNullableType(title: String!, text: String!, category: String!, author: String!) : Int
createPostReturnCustomScalar(title: String!, text: String!, category: String!, author: String!) : Void
}
type Post {
id: ID
title: String
text: String
category: String
author: String
}
type Query {
recentPosts(count: Int, offset: Int): [Post]!
}
@@ -0,0 +1,48 @@
package com.baeldung.returnnull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest;
import org.springframework.context.annotation.Import;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.test.context.ActiveProfiles;
@GraphQlTest(PostController.class)
@ActiveProfiles("returnnull")
@Import(GraphQlConfig.class)
class PostControllerIntegrationTest {
@Autowired
private GraphQlTester graphQlTester;
@Test
void givenNewPostData_whenExecuteMutation_thenReturnCustomNullScalar() {
String documentName = "create_post_return_custom_scalar";
graphQlTester.documentName(documentName)
.variable("title", "New Post")
.variable("text", "New post text")
.variable("category", "category")
.variable("author", "Alex")
.execute()
.path("createPostReturnCustomScalar")
.valueIsNull();
}
@Test
void givenNewPostData_whenExecuteMutation_thenReturnNullType() {
String documentName = "create_post_return_nullable_type";
graphQlTester.documentName(documentName)
.variable("title", "New Post")
.variable("text", "New post text")
.variable("category", "category")
.variable("author", "Alex")
.execute()
.path("createPostReturnNullableType")
.valueIsNull();
}
}
@@ -0,0 +1,3 @@
mutation createPostReturnCustomScalar($title: String!, $text: String!, $category: String!, $author: String!) {
createPostReturnCustomScalar(title: $title, text: $text, category: $category, author: $author)
}
@@ -0,0 +1,3 @@
mutation createPostReturnNullableType($title: String!, $text: String!, $category: String!, $author: String!) {
createPostReturnNullableType(title: $title, text: $text, category: $category, author: $author)
}
@@ -104,6 +104,13 @@
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
</plugins>
</build>
@@ -142,12 +149,11 @@
</profiles>
<properties>
<spring-cloud.version>2022.0.4</spring-cloud.version>
<spring-cloud.version>2023.0.0</spring-cloud.version>
<commons-configuration.version>1.10</commons-configuration.version>
<resource.delimiter>@</resource.delimiter>
<!-- <start-class>com.baeldung.buildproperties.Application</start-class> -->
<start-class>com.baeldung.yaml.MyApplication</start-class>
<spring-boot.version>3.1.5</spring-boot.version>
</properties>
</project>
@@ -53,7 +53,6 @@
<properties>
<apache.client5.version>5.0.3</apache.client5.version>
<spring-boot.version>3.1.5</spring-boot.version>
</properties>
</project>
@@ -27,7 +27,7 @@ public class SecureRestTemplateConfig {
this.sslContext = sslBundle.createSslContext();
}
@Bean
@Bean(name="secureRestTemplate")
public RestTemplate secureRestTemplate() {
final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext).build();
final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).build();
@@ -1,6 +1,7 @@
package com.baeldung.springbootsslbundles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -11,7 +12,7 @@ public class SecureServiceRestApi {
private final RestTemplate restTemplate;
@Autowired
public SecureServiceRestApi(RestTemplate restTemplate) {
public SecureServiceRestApi(@Qualifier("secureRestTemplate") RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
+17 -4
View File
@@ -9,9 +9,10 @@
<packaging>war</packaging>
<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@@ -42,6 +43,7 @@
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -77,8 +79,19 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<ehcache.version>3.5.2</ehcache.version>
<caffeine.version>3.1.8</caffeine.version>
</properties>
@@ -4,8 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import java.io.Serializable;
import java.util.UUID;