BAEL-5308 An Introduction to Domain Graph Service (DGS) Framework (#11718)

Co-authored-by: Adrianna Zychewicz <adrianna.zychewicz@decerto.pl>
This commit is contained in:
makapszenna 2022-01-31 04:40:53 +01:00 committed by GitHub
parent 45703a660c
commit 6f6b8e23e0
7 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.graphql-dgs</groupId>
<artifactId>graphql-dgs</artifactId>
<version>1.0</version>
<name>graphql-dgs</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-platform-dependencies</artifactId>
<version>4.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs.codegen</groupId>
<artifactId>graphql-dgs-codegen-client-core</artifactId>
<version>5.1.14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-spring-boot-starter</artifactId>
<version>4.9.15</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.2</version>
</plugin>
<plugin>
<groupId>io.github.deweyjose</groupId>
<artifactId>graphqlcodegen-maven-plugin</artifactId>
<version>1.14</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaPaths>
<param>src/main/resources/schema/schema.graphqls</param>
</schemaPaths>
<packageName>com.bealdung.graphqldgs.generated</packageName>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,25 @@
package com.bealdung.graphqlDGS;
public class Album {
private final String title;
private final String artist;
private final Integer recordNo;
public Album(String title, String artist, Integer recordNo) {
this.title = title;
this.recordNo = recordNo;
this.artist = artist;
}
public String getTitle() {
return title;
}
public String getArtist() {
return artist;
}
public Integer getRecordNo() {
return recordNo;
}
}

View File

@ -0,0 +1,28 @@
package com.bealdung.graphqlDGS;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@DgsComponent
public class AlbumsDataFetcher {
private final List<Album> albums = Arrays.asList(
new Album("Rumours", "Fleetwood Mac", 20),
new Album("What's Going On", "Marvin Gaye", 10),
new Album("Pet Sounds", "The Beach Boys", 12)
);
@DgsQuery
public List<Album> albums(@InputArgument String titleFilter) {
if(titleFilter == null) {
return albums;
}
return albums.stream()
.filter(s -> s.getTitle().contains(titleFilter))
.collect(Collectors.toList());
}
}

View File

@ -0,0 +1,13 @@
package com.bealdung.graphqlDGS;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1 @@
server.servlet.context-path=

View File

@ -0,0 +1,9 @@
type Query {
albums(titleFilter: String): [Album]
}
type Album {
title: String
artist: String
recordNo: Int
}

View File

@ -422,6 +422,7 @@
<!-- <module>gradle-6</module> --> <!-- Not a maven project --> <!-- <module>gradle-6</module> --> <!-- Not a maven project -->
<!-- <module>grails</module> --> <!-- Not a maven project --> <!-- <module>grails</module> --> <!-- Not a maven project -->
<module>graphql/graphql-java</module> <module>graphql/graphql-java</module>
<module>graphql/graphql-dgs</module>
<module>grpc</module> <module>grpc</module>
<module>gson</module> <module>gson</module>
<module>guava-modules</module> <module>guava-modules</module>