备忘:python和 java graphql client连Sky walking Server查询数据的联通性

1 篇文章 0 订阅
1 篇文章 0 订阅

本文仅做备忘
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

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhyuli

您的鼓励是对我付出努力一种赞赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值