本文仅做备忘
Skywalking OAP 关于graphql的url http://localhost:8090/graphql
python3.10
需要安装 GraphQLClient库
testGraphQL.py程序
from graphqlclient import GraphQLClient
import json
if __name__ == '__main__':
client=GraphQLClient('http://localhost:8090/graphql')
#以下是查询测试语句,查找指定服务对应的serviceId
queryServiceId= "query {ServiceId: searchService(serviceCode: \"" + "demo3" + "\"){id}}"
result = client.execute(queryServiceId)
print(result)
执行结果
{“data”:{“ServiceId”:{“id”:“Y3F1YW50LXRyYWRlLXNlcnZpY2U=.1”}}}
JAVA1.8
需要在pom.xml依赖中增加‘graphql-client
<dependency>
<groupId>org.mountcloud</groupId>
<artifactId>graphql-client</artifactId>
<version>1.2</version>
</dependency>
代码GraphQLTest.java如下
import org.mountcloud.graphql.GraphqlClient;
import org.mountcloud.graphql.request.query.DefaultGraphqlQuery;
import org.mountcloud.graphql.request.query.GraphqlQuery;
import org.mountcloud.graphql.response.GraphqlResponse;
import java.util.Map;
public class GraphQLTest {
public static void main(String[] args) throws Exception {
String serverUrl = "http://localhost:8090/graphql";
GraphqlClient graphqlClient = GraphqlClient.buildGraphqlClient(serverUrl);
String queryMethodName = "searchService";
GraphqlQuery query = new DefaultGraphqlQuery(queryMethodName);
query.addParameter("serviceCode","demo3");
query.addResultAttributes("id","name");
GraphqlResponse response = graphqlClient.doQuery(query);
Map result = response.getData();
System.out.println("result::"+result.toString());
}
}
执行结果
result::{data={searchService={id=Y3F1YW50LXRyYWRlLXNlcnZpY2U=.1, name=demo3}}
Process finished with exit code 0