GraphQL
GraphQL
基礎
參照Getting started with GraphQL Java and Spring Boot這篇文章學習即可
PS:可以使用 brew install --cask graphql-playground
安裝 graphql for mac
客戶端。
IDEA
怎么調試 GraphQL
應用
安裝 JS GraphQL
插件
點擊JS GraphQL安裝插件
GraphQL
定義
schema.graphqls
type Query {
bookById(id: ID): Book
}
type Book {
id: ID
name: String
pageCount: Int
author: Author
}
type Author {
id: ID
firstName: String
lastName: String
}
GraphQL
配置文件
.graphqlconfig
{
"name": "book-details",
"schemaPath": "schema.graphqls",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "http://localhost:8080/graphql", // 請求路徑
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}
創建一個查詢文件
query.graphql
# {"id": "book-1"}
query queryData($id: ID) {
bookById(id: $id) {
id name pageCount author {
id firstName lastName
}
}
}
GraphQL
腳本目錄結構
resources
├── .graphqlconfig # 配置文件
├── query.graphql # 查詢文件
└── schema.graphqls # 定義文件
執行結果
GraphQL
在 Skywalking
中的應用
graphql
協議文件路徑: oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol
GraphQL
配置文件
.graphqlconfig
{
"name": "skywalking",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "http://localhost:8080/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}
創建一個查詢文件
query.graphql
query queryData {
readMetricsValues(
duration: {start: "2021-07-03 1400",end: "2021-07-03 1401", step: MINUTE},
condition: {
name: "instance_jvm_thread_runnable_thread_count",
entity: {
scope: ServiceInstance,
serviceName: "business-zone::projectA",
serviceInstanceName: "e8cf34a1d54a4058a8c98505877770e2@192.168.50.113",
normal: true
}
}
) {
label values{ values{ id value }}
}
}
執行結果
{
"data": {
"readMetricsValues": {
"values": {
"values": [
{
"id": "202107031400_YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1_ZThjZjM0YTFkNTRhNDA1OGE4Yzk4NTA1ODc3NzcwZTJAMTkyLjE2OC41MC4xMTM=",
"value": 22
},
{
"id": "202107031401_YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1_ZThjZjM0YTFkNTRhNDA1OGE4Yzk4NTA1ODc3NzcwZTJAMTkyLjE2OC41MC4xMTM=",
"value": 22
}
]
}
}
}
}