You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2019/05/12 21:50:02 UTC

[unomi] branch UNOMI-180-CXS-GRAPHQLAPI updated (241a579 -> ed513da)

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

shuber pushed a change to branch UNOMI-180-CXS-GRAPHQLAPI
in repository https://gitbox.apache.org/repos/asf/unomi.git.


    from 241a579  UNOMI-180 - Updated GraphQL projects to latest version - Added CDP SDL schema generated from latest CDP specification
     new d72020a  UNOMI-180 - Start building a new servlet that loads the SDL schema and will combine it with dynamic type registration. - Deactivated old graphql-java-servlet for the moment.
     new ed513da  UNOMI-180 CDP Specification implementation - Get CDP feature to install properly (but it doesn't start yet since it is missing custom scalar and event registrations) - Fixed GraphQL schema JSON encoding to UTF-8 - Removed references to incubating that are no longer needed.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 graphql/cxs-impl/pom.xml                           |   4 +-
 .../unomi/graphql/internal/CDPSDLServletImpl.java  | 106 +++
 .../src/main/resources/cdp-schema.graphqls         | 978 +++++++++++++++++++++
 graphql/cxs-impl/src/main/resources/cdp-schema.sdl | Bin 45752 -> 0 bytes
 graphql/karaf-feature/pom.xml                      |   9 +-
 graphql/pom.xml                                    |   2 +-
 6 files changed, 1091 insertions(+), 8 deletions(-)
 create mode 100644 graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
 create mode 100644 graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
 delete mode 100644 graphql/cxs-impl/src/main/resources/cdp-schema.sdl


[unomi] 01/02: UNOMI-180 - Start building a new servlet that loads the SDL schema and will combine it with dynamic type registration. - Deactivated old graphql-java-servlet for the moment.

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch UNOMI-180-CXS-GRAPHQLAPI
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit d72020a4c06adbb64d9cc9607f6e694c62a679c9
Author: sergehuber <sh...@jahia.com>
AuthorDate: Sun May 12 22:12:14 2019 +0200

    UNOMI-180
    - Start building a new servlet that loads the SDL schema and will combine it with dynamic type registration.
    - Deactivated old graphql-java-servlet for the moment.
---
 .../unomi/graphql/internal/CDPSDLServletImpl.java  | 105 +++++++++++++++++++++
 .../{cdp-schema.sdl => cdp-schema.graphqls}        | Bin
 graphql/karaf-feature/pom.xml                      |   6 +-
 3 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
new file mode 100644
index 0000000..dfd1ca6
--- /dev/null
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.unomi.graphql.internal;
+
+import graphql.schema.GraphQLSchema;
+import graphql.schema.StaticDataFetcher;
+import graphql.schema.idl.RuntimeWiring;
+import graphql.schema.idl.SchemaGenerator;
+import graphql.schema.idl.SchemaParser;
+import graphql.schema.idl.TypeDefinitionRegistry;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring;
+
+@Component(
+        service={javax.servlet.http.HttpServlet.class,javax.servlet.Servlet.class},
+        property = {"alias=/graphql", "jmx.objectname=graphql.servlet:type=graphql"}
+)
+public class CDPSDLServletImpl extends HttpServlet {
+
+    @Reference
+    private BundleContext bundleContext;
+
+    RuntimeWiring buildRuntimeWiring() {
+        return RuntimeWiring.newRuntimeWiring()
+                // .scalar(CustomScalar)
+                // this uses builder function lambda syntax
+                /*
+                .type("QueryType", typeWiring -> typeWiring
+                        .dataFetcher("hero", new StaticDataFetcher(StarWarsData.getArtoo()))
+                        .dataFetcher("human", StarWarsData.getHumanDataFetcher())
+                        .dataFetcher("droid", StarWarsData.getDroidDataFetcher())
+                )
+                .type("Human", typeWiring -> typeWiring
+                        .dataFetcher("friends", StarWarsData.getFriendsDataFetcher())
+                )
+                // you can use builder syntax if you don't like the lambda syntax
+                .type("Droid", typeWiring -> typeWiring
+                        .dataFetcher("friends", StarWarsData.getFriendsDataFetcher())
+                )
+                // or full builder syntax if that takes your fancy
+                .type(
+                        newTypeWiring("Character")
+                                .typeResolver(StarWarsData.getCharacterTypeResolver())
+                                .build()
+                )
+                */
+                .build();
+    }
+
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+
+        SchemaParser schemaParser = new SchemaParser();
+        SchemaGenerator schemaGenerator = new SchemaGenerator();
+
+        Reader schemaReader = getSchemaReader("cdp-schema.graphqls");
+        //File schemaFile2 = loadSchema("cdp-schema.graphqls");
+        //File schemaFile3 = loadSchema("cdp-schema.graphqls");
+
+        TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
+
+        // each registry is merged into the main registry
+        typeRegistry.merge(schemaParser.parse(schemaReader));
+        //typeRegistry.merge(schemaParser.parse(schemaFile2));
+        //typeRegistry.merge(schemaParser.parse(schemaFile3));
+
+        RuntimeWiring wiring = buildRuntimeWiring();
+        GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, wiring);
+    }
+
+    private Reader getSchemaReader(String resourceUrl) {
+        try {
+            return new InputStreamReader(bundleContext.getBundle().getResource(resourceUrl).openConnection().getInputStream());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}
diff --git a/graphql/cxs-impl/src/main/resources/cdp-schema.sdl b/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
similarity index 100%
rename from graphql/cxs-impl/src/main/resources/cdp-schema.sdl
rename to graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
diff --git a/graphql/karaf-feature/pom.xml b/graphql/karaf-feature/pom.xml
index c051b18..0437dba 100644
--- a/graphql/karaf-feature/pom.xml
+++ b/graphql/karaf-feature/pom.xml
@@ -82,7 +82,7 @@
             <version>1.0.2</version>
         </dependency>
 
-
+<!--
         <dependency>
             <groupId>com.graphql-java-kickstart</groupId>
             <artifactId>graphql-java-servlet</artifactId>
@@ -98,6 +98,7 @@
                 </exclusion>
             </exclusions>
         </dependency>
+-->
         <dependency>
             <groupId>com.graphql-java</groupId>
             <artifactId>graphql-java</artifactId>
@@ -109,12 +110,13 @@
                 </exclusion>
             </exclusions>
         </dependency>
+<!--
         <dependency>
             <groupId>io.github.graphql-java</groupId>
             <artifactId>graphql-java-annotations</artifactId>
             <version>${graphql.java.annotations.version}</version>
         </dependency>
-
+-->
         <dependency>
             <groupId>org.apache.unomi</groupId>
                 <artifactId>cdp-graphql-api-impl</artifactId>


[unomi] 02/02: UNOMI-180 CDP Specification implementation - Get CDP feature to install properly (but it doesn't start yet since it is missing custom scalar and event registrations) - Fixed GraphQL schema JSON encoding to UTF-8 - Removed references to incubating that are no longer needed.

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch UNOMI-180-CXS-GRAPHQLAPI
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit ed513dae2aa4ae3846d13e1401636983996bf8bc
Author: sergehuber <sh...@jahia.com>
AuthorDate: Sun May 12 23:49:05 2019 +0200

    UNOMI-180 CDP Specification implementation
    - Get CDP feature to install properly (but it doesn't start yet since it is missing custom scalar and event registrations)
    - Fixed GraphQL schema JSON encoding to UTF-8
    - Removed references to incubating that are no longer needed.
---
 graphql/cxs-impl/pom.xml                            |   4 ++--
 .../unomi/graphql/internal/CDPSDLServletImpl.java   |  17 +++++++++--------
 .../cxs-impl/src/main/resources/cdp-schema.graphqls | Bin 45752 -> 22300 bytes
 graphql/karaf-feature/pom.xml                       |  11 ++++-------
 graphql/pom.xml                                     |   2 +-
 5 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/graphql/cxs-impl/pom.xml b/graphql/cxs-impl/pom.xml
index 8a0e883..79cd629 100644
--- a/graphql/cxs-impl/pom.xml
+++ b/graphql/cxs-impl/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-graphql</artifactId>
-        <version>1.4.0-incubating-SNAPSHOT</version>
+        <version>1.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -76,7 +76,7 @@
         <dependency>
             <groupId>org.apache.unomi</groupId>
             <artifactId>unomi-api</artifactId>
-            <version>1.4.0-incubating-SNAPSHOT</version>
+            <version>1.4.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
index dfd1ca6..8cafa15 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CDPSDLServletImpl.java
@@ -16,35 +16,36 @@
  */
 package org.apache.unomi.graphql.internal;
 
+import com.google.common.base.Charsets;
 import graphql.schema.GraphQLSchema;
-import graphql.schema.StaticDataFetcher;
 import graphql.schema.idl.RuntimeWiring;
 import graphql.schema.idl.SchemaGenerator;
 import graphql.schema.idl.SchemaParser;
 import graphql.schema.idl.TypeDefinitionRegistry;
 import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 
-import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring;
-
 @Component(
         service={javax.servlet.http.HttpServlet.class,javax.servlet.Servlet.class},
-        property = {"alias=/graphql", "jmx.objectname=graphql.servlet:type=graphql"}
+        property = {"alias=/sdlgraphql", "jmx.objectname=graphql.servlet:type=graphql"}
 )
 public class CDPSDLServletImpl extends HttpServlet {
 
-    @Reference
     private BundleContext bundleContext;
 
+    @Activate
+    void activate(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
     RuntimeWiring buildRuntimeWiring() {
         return RuntimeWiring.newRuntimeWiring()
                 // .scalar(CustomScalar)
@@ -96,7 +97,7 @@ public class CDPSDLServletImpl extends HttpServlet {
 
     private Reader getSchemaReader(String resourceUrl) {
         try {
-            return new InputStreamReader(bundleContext.getBundle().getResource(resourceUrl).openConnection().getInputStream());
+            return new InputStreamReader(bundleContext.getBundle().getResource(resourceUrl).openConnection().getInputStream(), Charsets.UTF_8.name());
         } catch (IOException e) {
             e.printStackTrace();
         }
diff --git a/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls b/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
index 22fba9a..7a924ca 100644
Binary files a/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls and b/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls differ
diff --git a/graphql/karaf-feature/pom.xml b/graphql/karaf-feature/pom.xml
index 0437dba..b813872 100644
--- a/graphql/karaf-feature/pom.xml
+++ b/graphql/karaf-feature/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-graphql</artifactId>
-        <version>1.4.0-incubating-SNAPSHOT</version>
+        <version>1.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>feature</packaging>
@@ -59,7 +59,7 @@
         <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
-            <version>20.0</version>
+            <version>24.1.1-jre</version>
         </dependency>
         <dependency>
             <groupId>commons-fileupload</groupId>
@@ -82,7 +82,6 @@
             <version>1.0.2</version>
         </dependency>
 
-<!--
         <dependency>
             <groupId>com.graphql-java-kickstart</groupId>
             <artifactId>graphql-java-servlet</artifactId>
@@ -98,7 +97,7 @@
                 </exclusion>
             </exclusions>
         </dependency>
--->
+
         <dependency>
             <groupId>com.graphql-java</groupId>
             <artifactId>graphql-java</artifactId>
@@ -110,17 +109,15 @@
                 </exclusion>
             </exclusions>
         </dependency>
-<!--
         <dependency>
             <groupId>io.github.graphql-java</groupId>
             <artifactId>graphql-java-annotations</artifactId>
             <version>${graphql.java.annotations.version}</version>
         </dependency>
--->
         <dependency>
             <groupId>org.apache.unomi</groupId>
                 <artifactId>cdp-graphql-api-impl</artifactId>
-            <version>1.4.0-incubating-SNAPSHOT</version>
+            <version>1.4.0-SNAPSHOT</version>
         </dependency>
 
     </dependencies>
diff --git a/graphql/pom.xml b/graphql/pom.xml
index 191e642..260f787 100644
--- a/graphql/pom.xml
+++ b/graphql/pom.xml
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-root</artifactId>
-        <version>1.4.0-incubating-SNAPSHOT</version>
+        <version>1.4.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>unomi-graphql</artifactId>