This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch feature/ui-protocol
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/feature/ui-protocol by this 
push:
     new 84caf87  Add graphiql servlet
84caf87 is described below

commit 84caf87f36835a325b0b405b216e2fb908f9bc14
Author: gaohongtao <[email protected]>
AuthorDate: Tue Dec 26 22:46:04 2017 +0800

    Add graphiql servlet
---
 apm-protocol/apm-ui-protocol/README.md             |  6 ++
 apm-protocol/apm-ui-protocol/pom.xml               | 33 ++++++++++
 .../apm/ui/protocol/GraphQLInitializer.java        | 75 ++++++++++++++++++++++
 .../src/main/resources/application.yml             | 20 ++++++
 .../src/main/resources/ui-graphql/common.graphqls  |  3 +-
 .../resources/ui-graphql/overview-layer.graphqls   |  4 +-
 .../src/main/resources/ui-graphql/trace.graphqls   |  2 +-
 7 files changed, 139 insertions(+), 4 deletions(-)

diff --git a/apm-protocol/apm-ui-protocol/README.md 
b/apm-protocol/apm-ui-protocol/README.md
new file mode 100644
index 0000000..f58f1ea
--- /dev/null
+++ b/apm-protocol/apm-ui-protocol/README.md
@@ -0,0 +1,6 @@
+## 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)
diff --git a/apm-protocol/apm-ui-protocol/pom.xml 
b/apm-protocol/apm-ui-protocol/pom.xml
index 9ad10c0..ab829de 100644
--- a/apm-protocol/apm-ui-protocol/pom.xml
+++ b/apm-protocol/apm-ui-protocol/pom.xml
@@ -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>
diff --git 
a/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java
 
b/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java
new file mode 100644
index 0000000..934c067
--- /dev/null
+++ 
b/apm-protocol/apm-ui-protocol/src/main/java/org/apache/skywalking/apm/ui/protocol/GraphQLInitializer.java
@@ -0,0 +1,75 @@
+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();
+    }
+}
diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/application.yml 
b/apm-protocol/apm-ui-protocol/src/main/resources/application.yml
new file mode 100644
index 0000000..0dddee9
--- /dev/null
+++ b/apm-protocol/apm-ui-protocol/src/main/resources/application.yml
@@ -0,0 +1,20 @@
+#
+# 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
diff --git 
a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls 
b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls
index 91d6ba3..7473866 100644
--- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls
+++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls
@@ -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!
diff --git 
a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls
 
b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls
index 1dbc145..c101963 100644
--- 
a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls
+++ 
b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls
@@ -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 {
diff --git 
a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls 
b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls
index 75b8b20..822f7ce 100644
--- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls
+++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls
@@ -13,7 +13,7 @@ type BasicTrace {
 }
 
 # Represent the conditions used for query TraceBrief
-type TraceQueryCondition {
+input TraceQueryCondition {
   applicationCodes: [String!]
   traceId: String
   operationName: String

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to