• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

joaquin-alfaro/graphql-gateway: GraphQL gateway

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

joaquin-alfaro/graphql-gateway

开源软件地址(OpenSource Url):

https://github.com/joaquin-alfaro/graphql-gateway

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource Introduction):

graphql-gateway

Gateway to expose rest services using GraphQL.

Overview

architecture

Modules

graphql-server

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
}

graphql-registry

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'

graphql-registry-client

Includes the annotation @GraphQLRegistryService to register services during starting

graphql-schema

Includes the code to map swagger with graphql

graphql-gateway-server

springboot service that includes graphql-server and grapqhl-registry

How it works

Service registry

service registry

Graphql queries

graphql queries

Setup

Configuration 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);
	}
}

Configuration

Configuration of the url of the graphql-gateway in application.yaml

graphql:
  registry:
    uri: http://localhost:8080

Usage and example

  1. Install
mvn clean package
  1. Start graphql-gateway
java -jar graphql-gateway-server/target/graphql-gateway.jar

Example

The project includes the samples rest-books-service and rest-countries-service to test the gateway

Start rest-books-service

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
    }
  }
}

Start rest_countries_service

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
        }
    }
}

Launch GraphQL queries using GraphQL Playground

graphql playground




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap