提供便捷调用Graphql Server Api 的能力
通过 interface
+annotation
的方式注册 Spring Bean,在 resource
目录下通过 graphql 文件维护查询语句
最新版本为 1.6.0-SNAPSHOT
<dependency>
<groupId>io.github.wangyuheng</groupId>
<artifactId>arc-graphql-client</artifactId>
<version>1.6.0-SNAPSHOT</version>
</dependency>
Example
新建文件 resources/ql/echo.graphql
query hello($echoText: String!) {
echo(text:$echoText)
}
- 通过
@EnableGraphqlClients
启用并指定扫描包 GraphqlClient
指定api url 并注册SpringBeanGraphqlMapping
关联resource目录下的查询语句
Example
@EnableGraphqlClients(basePackages = "io.github.wangyuheng.arcgraphqlclientexample")
@RestController
@SpringBootApplication
public class ArcGraphqlClientExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ArcGraphqlClientExampleApplication.class, args);
}
@Autowired
private GitlabGraphqlClient gitlabGraphqlClient;
@RequestMapping("rest")
public Object rest(@RequestParam(required = false, defaultValue = "Arc") String name) {
return gitlabGraphqlClient.echo("Hello " + name).getData();
}
@GraphqlClient(value = "gitlabGraphqlClient", url = "https://gitlab.com/api/graphql")
interface GitlabGraphqlClient {
@GraphqlMapping(path = "ql/echo.graphql")
GraphqlResponse<Object> echo(@GraphqlParam("echoText") String text);
}
}