在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):joaquin-alfaro/graphql-gateway开源软件地址(OpenSource Url):https://github.com/joaquin-alfaro/graphql-gateway开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):graphql-gatewayGateway to expose rest services using GraphQL. OverviewModulesgraphql-serverExposes 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
} graphql-registryExposes 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' graphql-registry-clientIncludes the annotation @GraphQLRegistryService to register services during starting graphql-schemaIncludes the code to map swagger with graphql graphql-gateway-serverspringboot service that includes graphql-server and grapqhl-registry How it worksService registryGraphql queriesSetupConfiguration of springboot service to register in graphql-gateway Dependency with graphql-registry-client<dependency>
<groupId>org.formentor</groupId>
<artifactId>graphql-registry-client</artifactId>
<version>${graphql-gateway.version}</version>
</dependency> Annotation of spring boot class with @GraphQLRegistryService@SpringBootApplication
@GraphQLRegistryService
public class BooksApplication {
public static void main(String[] args) {
SpringApplication.run(BooksApplication.class, args);
}
} ConfigurationConfiguration of the url of the graphql-gateway in application.yaml graphql:
registry:
uri: http://localhost:8080 Usage and example
mvn clean package
java -jar graphql-gateway-server/target/graphql-gateway.jar ExampleThe project includes the samples rest-books-service and rest-countries-service to test the gateway Start rest-books-servicejava -jar rest-books-service/target/*.jar
query {
books {
name
id
author {
lastName
firstName
}
}
} query {
booksById(id: "one") {
id
name
author {
lastName
}
}
} Start rest_countries_servicejava -jar rest-countries-service/target/*.jar
query {
countries {
iso
name
cities {
name
id
}
}
} query {
countriesById(id: "DE") {
name
cities{
name
}
}
} GraphQL PlaygroundLaunch GraphQL queries using |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论