提交 84caf87f 编写于 作者: G gaohongtao

Add graphiql servlet

上级 0af4f173
## Using graphiql
Graphiql */ˈɡrafək(ə)l/* is interactive in-browser GraphQL IDE which can be used by following steps.
1. Run `org.apache.skywalking.apm.ui.protocol.GraphQLInitializer#main`
1. Access [http://localhost:8080/graphiql](http://localhost:8080/graphiql)
......@@ -29,5 +29,38 @@
<artifactId>apm-ui-protocol</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<!-- to embed GraphiQL tool -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>3.9.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>3.9.2</version>
</dependency>
</dependencies>
</project>
package org.apache.skywalking.apm.ui.protocol;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.TypeResolver;
import graphql.schema.idl.FieldWiringEnvironment;
import graphql.schema.idl.InterfaceWiringEnvironment;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.schema.idl.WiringFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import java.io.File;
/**
* GraphQL server initializer.
*
* @author gaohongtao
*/
@SpringBootApplication
public class GraphQLInitializer extends SpringBootServletInitializer {
private Logger logger = LoggerFactory.getLogger(GraphQLInitializer.class);
public static void main(String[] args) throws Exception {
ApplicationContext applicationContext = SpringApplication.run(GraphQLInitializer.class, args);
}
@Bean
GraphQLSchema schema() {
SchemaParser schemaParser = new SchemaParser();
SchemaGenerator schemaGenerator = new SchemaGenerator();
TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
typeRegistry.merge(schemaParser.parse(loadSchema("common.graphqls")));
typeRegistry.merge(schemaParser.parse(loadSchema("trace.graphqls")));
typeRegistry.merge(schemaParser.parse(loadSchema("overview-layer.graphqls")));
RuntimeWiring wiring = buildRuntimeWiring();
return schemaGenerator.makeExecutableSchema(typeRegistry, wiring);
}
private File loadSchema(final String s) {
return new File(GraphQLInitializer.class.getClassLoader().getResource("ui-graphql/" + s).getFile());
}
private RuntimeWiring buildRuntimeWiring() {
WiringFactory dynamicWiringFactory = new WiringFactory() {
@Override
public boolean providesTypeResolver(final InterfaceWiringEnvironment environment) {
return true;
}
@Override
public TypeResolver getTypeResolver(final InterfaceWiringEnvironment environment) {
return env -> GraphQLObjectType.newObject().build();
}
@Override
public boolean providesDataFetcher(final FieldWiringEnvironment environment) {
logger.info("data fetcher: {},{}", environment.getFieldDefinition(), environment.getParentType());
return false;
}
};
return RuntimeWiring.newRuntimeWiring()
.wiringFactory(dynamicWiringFactory).build();
}
}
#
# Copyright 2017, OpenSkywalking Organization All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Project repository: https://github.com/OpenSkywalking/skywalking-ui
#
server:
port: 8080
......@@ -2,6 +2,7 @@ schema {
query: Query
}
#Root node
type Query {
version: String
}
......@@ -24,7 +25,7 @@ type Query {
# metrics from the following time points expected
# 2017-11-08 9:00 -> 2017-11-08 19:00
# there are 11 time points (hours) in the time span.
type Duration{
input Duration{
start: String!
end: String!
step: Step!
......
......@@ -88,7 +88,7 @@ type ConjecturalApp {
# The display name of the application
# e.g. MySQL, RocketMQ, Kafka, Nginx
name: String!
num: int!
num: Int!
}
type ApplicationBrief {
......@@ -97,7 +97,7 @@ type ApplicationBrief {
type ApplicationInfo {
name: String!
tps: int!
tps: Int!
}
extend type Query {
......
......@@ -13,7 +13,7 @@ type BasicTrace {
}
# Represent the conditions used for query TraceBrief
type TraceQueryCondition {
input TraceQueryCondition {
applicationCodes: [String!]
traceId: String
operationName: String
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册