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 af70f6f8921a5445f371365b5596a6ac5b5e6344
Author: Serge Huber <shu...@jahia.com>
AuthorDate: Tue May 28 17:55:54 2019 +0200

    Add custom unomi types with custom event types.
---
 .../unomi/graphql/internal/CDPSDLServletImpl.java  | 16 ++++-
 .../src/main/resources/cdp-schema.graphqls         |  6 --
 .../src/main/resources/unomi-schema.graphqls       | 74 ++++++++++++++++++++++
 3 files changed, 87 insertions(+), 9 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
index 2deae05..6a0e7ff 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
@@ -148,7 +148,15 @@ public class CDPSDLServletImpl extends HttpServlet {
                         .typeResolver(new TypeResolver() {
                             @Override
                             public GraphQLObjectType 
getType(TypeResolutionEnvironment env) {
-                                return 
env.getSchema().getObjectType("CDP_ProfileUpdateEvent");
+                                Map<String,Object> object = env.getObject();
+                                String unomiEventType = (String) 
object.get("__unomiEventType");
+                                if ("view".equals(unomiEventType)) {
+                                    return 
env.getSchema().getObjectType("Unomi_PageViewEvent");
+                                } else if 
("sessionCreated".equals(unomiEventType)) {
+                                    return 
env.getSchema().getObjectType("Unomi_SessionCreatedEvent");
+                                } else {
+                                    return 
env.getSchema().getObjectType("Unomi_UnknownEvent");
+                                }
                             }
                         }))
                 .type("CDP_ProfileInterface", typeWiring -> typeWiring
@@ -282,14 +290,16 @@ public class CDPSDLServletImpl extends HttpServlet {
         SchemaParser schemaParser = new SchemaParser();
         SchemaGenerator schemaGenerator = new SchemaGenerator();
 
-        Reader schemaReader = getSchemaReader("cdp-schema.graphqls");
+        Reader cdpSchemaReader = getSchemaReader("cdp-schema.graphqls");
+        Reader unomiSchemaReader = getSchemaReader("unomi-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(cdpSchemaReader));
+        typeRegistry.merge(schemaParser.parse(unomiSchemaReader));
         //typeRegistry.merge(schemaParser.parse(schemaFile2));
         //typeRegistry.merge(schemaParser.parse(schemaFile3));
 
diff --git a/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls 
b/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
index 1e71cbe..bea3348 100644
--- a/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
+++ b/graphql/cxs-impl/src/main/resources/cdp-schema.graphqls
@@ -972,9 +972,3 @@ 
https://github.com/graphql-java/graphql-java-extended-scalars for example
 implementation 
 """
 scalar Time
-
-schema {
-  query : Query
-  mutation : Mutation
-  subscription : Subscription
-}
\ No newline at end of file
diff --git a/graphql/cxs-impl/src/main/resources/unomi-schema.graphqls 
b/graphql/cxs-impl/src/main/resources/unomi-schema.graphqls
new file mode 100644
index 0000000..73a87ec
--- /dev/null
+++ b/graphql/cxs-impl/src/main/resources/unomi-schema.graphqls
@@ -0,0 +1,74 @@
+#
+# 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.
+#
+
+# This file contains extensions to the CDP specification that are specific to 
Apache Unomi
+
+type Unomi_PageView {
+    url : String
+    path : String
+    referrer : String
+}
+
+type Unomi_PageViewEvent implements CDP_EventInterface {
+    id: ID!
+    cdp_source: CDP_Source
+    cdp_client: CDP_Client
+    cdp_profileID: CDP_ProfileID!
+    cdp_profile: CDP_Profile!
+    cdp_object: CDP_Object!
+    cdp_location: GeoPoint
+    cdp_timestamp: DateTime
+    cdp_topics: [CDP_Topic]
+
+    pageView : Unomi_PageView
+}
+
+type Unomi_SessionCreated {
+    creationTime : DateTime
+    duration : Int
+}
+
+type Unomi_SessionCreatedEvent implements CDP_EventInterface {
+    id: ID!
+    cdp_source: CDP_Source
+    cdp_client: CDP_Client
+    cdp_profileID: CDP_ProfileID!
+    cdp_profile: CDP_Profile!
+    cdp_object: CDP_Object!
+    cdp_location: GeoPoint
+    cdp_timestamp: DateTime
+    cdp_topics: [CDP_Topic]
+
+    sessionCreated : Unomi_SessionCreated
+}
+
+type Unomi_PropertyPair {
+    name : String
+    value : JSON
+}
+
+type Unomi_UnknownEvent implements CDP_EventInterface {
+
+    id: ID!
+    cdp_source: CDP_Source
+    cdp_client: CDP_Client
+    cdp_profileID: CDP_ProfileID!
+    cdp_profile: CDP_Profile!
+    cdp_object: CDP_Object!
+    cdp_location: GeoPoint
+    cdp_timestamp: DateTime
+    cdp_topics: [CDP_Topic]
+
+    unknownProperties : [Unomi_PropertyPair]
+}
\ No newline at end of file

Reply via email to