Gateway to expose rest services using GraphQL.
Exposes the endpoint POST /graphql for query requests
query {
countriesById(id: "DE") {
name
cities{
name
}
}
}
type CityDto {
id: ID
name: String
}
type CountryDto {
cities: [CityDto]
iso: String
name: String
}
Exposes the following endpoints to manage registration of services:
POST /registry to register services in the gateway
curl --location --request POST 'http://localhost:8080/registry' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "rest-countries-service",
"url": "http://localhost:8082/v2/api-docs"
}'
DELETE /registry to unregister services from the gateway
curl --location --request DELETE 'http://localhost:8080/registry?service=rest-countries-service' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "booksApi",
"url": "http://localhost:8081/v2/api-docs"
}'
GET /registry to list registered services in the gateway
curl --location --request GET 'http://localhost:8080/registry'
Includes the annotation @GraphQLRegistryService to register services during starting
Includes the code to map swagger with graphql
springboot service that includes graphql-server and grapqhl-registry
Configuration of springboot service to register in graphql-gateway
<dependency>
<groupId>org.formentor</groupId>
<artifactId>graphql-registry-client</artifactId>
<version>${graphql-gateway.version}</version>
</dependency>
@SpringBootApplication
@GraphQLRegistryService
public class BooksApplication {
public static void main(String[] args) {
SpringApplication.run(BooksApplication.class, args);
}
}
Configuration of the url of the graphql-gateway in application.yaml
graphql:
registry:
uri: http://localhost:8080
- Install
mvn clean package
- Start graphql-gateway
java -jar graphql-gateway-server/target/graphql-gateway.jar
The project includes the samples rest-books-service and rest-countries-service to test the gateway
java -jar rest-books-service/target/*.jar
The service rest-books-service will register the fields books and booksById in query type
query {
books {
name
id
author {
lastName
firstName
}
}
}
query {
booksById(id: "one") {
id
name
author {
lastName
}
}
}
java -jar rest-countries-service/target/*.jar
The service rest-countries-service will register the fields countries and countriesById in query type
query {
countries {
iso
name
cities {
name
id
}
}
}
query {
countriesById(id: "DE") {
name
cities{
name
}
}
}