本文主要是介绍备忘:python和 java graphql client连Sky walking Server查询数据的联通性,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文仅做备忘
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') #以下是查询测试语句,查找指定服务对应的serviceIdqueryServiceId= "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
这篇关于备忘:python和 java graphql client连Sky walking Server查询数据的联通性的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!