UNOMI-180 Implement CXS GraphQL API - Started implementing mutation for event type definitions, but still struggling with some limitations in the graphql-java-annotations project, notably it doesn't easily provide a way to build input types, and it seems to prefix all input types with "Input" which is not something wanted as we have already postfixed them. Postfixing seems to be more of a conventation than prefixing them in the GraphQL world.
Signed-off-by: Serge Huber <shu...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/a120d3dd Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/a120d3dd Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/a120d3dd Branch: refs/heads/UNOMI-180-CXS-GRAPHQLAPI Commit: a120d3ddb50a6f228306b4f8595a27e11c0e3578 Parents: 6491ac2 Author: Serge Huber <shu...@apache.org> Authored: Fri May 11 14:52:56 2018 +0200 Committer: Serge Huber <shu...@apache.org> Committed: Wed Nov 21 14:56:46 2018 +0100 ---------------------------------------------------------------------- .../graphql/AbstractPropertyTypeInput.java | 40 ++++++++++++++ .../graphql/CXSBooleanPropertyTypeInput.java | 28 ++++++++++ .../unomi/graphql/CXSDatePropertyTypeInput.java | 26 +++++++++ .../apache/unomi/graphql/CXSEventTypeInput.java | 36 +++++++++++++ .../graphql/CXSFloatPropertyTypeInput.java | 30 +++++++++++ .../graphql/CXSGeoPointPropertyTypeInput.java | 25 +++++++++ .../graphql/CXSIdentifierPropertyTypeInput.java | 28 ++++++++++ .../unomi/graphql/CXSIntPropertyTypeInput.java | 30 +++++++++++ .../unomi/graphql/CXSPropertyTypeInput.java | 56 ++++++++++++++++++++ .../unomi/graphql/CXSSetPropertyTypeInput.java | 27 ++++++++++ .../graphql/CXSStringPropertyTypeInput.java | 28 ++++++++++ .../internal/CXSGraphQLProviderImpl.java | 43 ++++++++++++++- 12 files changed, 396 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java new file mode 100644 index 0000000..ad7ae5e --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java @@ -0,0 +1,40 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class AbstractPropertyTypeInput { + + @GraphQLField + public String id; + @GraphQLField + public String name; + @GraphQLField + public int minOccurrences; + @GraphQLField + public int maxOccurrences; + @GraphQLField + public List<String> tags; + @GraphQLField + public List<String> systemTags; + @GraphQLField + public boolean personalData; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java new file mode 100644 index 0000000..3843f5a --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java @@ -0,0 +1,28 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +@GraphQLName("CXSBooleanPropertyTypeInput") +public class CXSBooleanPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public boolean defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java new file mode 100644 index 0000000..e8036aa --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java @@ -0,0 +1,26 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSDatePropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventTypeInput.java new file mode 100644 index 0000000..b84175f --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventTypeInput.java @@ -0,0 +1,36 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class CXSEventTypeInput { + + @GraphQLField + public String id; + + @GraphQLField + public String scope; + + @GraphQLField + public String typeName; + + @GraphQLField + public List<CXSPropertyTypeInput> properties; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java new file mode 100644 index 0000000..038f4a5 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java @@ -0,0 +1,30 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSFloatPropertyTypeInput extends AbstractPropertyTypeInput{ + + @GraphQLField + public float minValue; + @GraphQLField + public float maxValue; + @GraphQLField + public float defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java new file mode 100644 index 0000000..c32def1 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java @@ -0,0 +1,25 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSGeoPointPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public String defaultValue; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java new file mode 100644 index 0000000..49869bc --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java @@ -0,0 +1,28 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSIdentifierPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public String regexp; + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java new file mode 100644 index 0000000..f2dac72 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java @@ -0,0 +1,30 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSIntPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public int minValue; + @GraphQLField + public int maxValue; + @GraphQLField + public int defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java new file mode 100644 index 0000000..60a1aa4 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java @@ -0,0 +1,56 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +@GraphQLName("CXSPropertyTypeInput") +public class CXSPropertyTypeInput { + + @GraphQLField + @GraphQLName("identifier") + public CXSIdentifierPropertyTypeInput identifierPropertyTypeInput; + + @GraphQLField + @GraphQLName("string") + public CXSStringPropertyTypeInput stringPropertyTypeInput; + + @GraphQLField + @GraphQLName("int") + public CXSIntPropertyTypeInput integer; + + @GraphQLField + @GraphQLName("float") + public CXSFloatPropertyTypeInput floatPropertyTypeInput; + + @GraphQLField + @GraphQLName("date") + public CXSDatePropertyTypeInput datePropertyTypeInput; + + @GraphQLField + @GraphQLName("boolean") + public CXSBooleanPropertyTypeInput booleanPropertyTypeInput; + + @GraphQLField + @GraphQLName("geopoint") + public CXSGeoPointPropertyTypeInput geoPointPropertyTypeInput; + + @GraphQLField + @GraphQLName("set") + public CXSSetPropertyTypeInput setPropertyTypeInput; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java new file mode 100644 index 0000000..5db69dd --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java @@ -0,0 +1,27 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class CXSSetPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public List<CXSPropertyTypeInput> properties; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java new file mode 100644 index 0000000..c44496f --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java @@ -0,0 +1,28 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSStringPropertyTypeInput extends AbstractPropertyTypeInput { + + @GraphQLField + public String regexp; + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a120d3dd/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java index e451dde..b9e876a 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java @@ -17,6 +17,11 @@ package org.apache.unomi.graphql.internal; import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +import graphql.annotations.processor.typeBuilders.InputObjectBuilder; import graphql.schema.*; import graphql.servlet.GraphQLMutationProvider; import graphql.servlet.GraphQLQueryProvider; @@ -31,6 +36,7 @@ import org.osgi.service.component.annotations.Deactivate; import java.util.*; import static graphql.Scalars.*; +import static graphql.schema.GraphQLArgument.newArgument; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLObjectType.newObject; @@ -41,6 +47,7 @@ import static graphql.schema.GraphQLObjectType.newObject; public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryProvider, GraphQLTypesProvider, GraphQLMutationProvider { private Map<String,GraphQLOutputType> registeredOutputTypes = new TreeMap<>(); + private Map<String,GraphQLInputType> registeredInputTypes = new TreeMap<>(); @Activate void activate( @@ -52,8 +59,15 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP registeredOutputTypes.put(CXSProperties.class.getName(), GraphQLAnnotations.object(CXSProperties.class)); registeredOutputTypes.put(CXSEventType.class.getName(), GraphQLAnnotations.object(CXSEventType.class)); + GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); + GraphQLInputObjectType cxsEventTypeInput = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), + new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). + getInputObjectBuilder(CXSEventTypeInput.class, GraphQLAnnotations.getInstance().getContainer()).build(); + registeredInputTypes.put(CXSEventTypeInput.class.getName(), cxsEventTypeInput); + registeredOutputTypes.put("CXS_Event", buildCXSEventOutputType()); registeredOutputTypes.put("CXS_Query", buildCXSQueryOutputType()); + registeredOutputTypes.put("CXS_Mutation", buildCXSMutationOutputType()); } @Deactivate @@ -88,7 +102,18 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP @Override public Collection<GraphQLFieldDefinition> getMutations() { - return new ArrayList<>(); + List<GraphQLFieldDefinition> fieldDefinitions = new ArrayList<GraphQLFieldDefinition>(); + fieldDefinitions.add(newFieldDefinition() + .type(registeredOutputTypes.get("CXS_Mutation")) + .name("cxs") + .description("Root field for all CXS mutation") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + Map<String,Object> map = environment.getContext(); + return map.keySet(); + } + }).build()); + return fieldDefinitions; } private GraphQLOutputType buildCXSQueryOutputType() { @@ -103,6 +128,22 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP .build(); } + private GraphQLOutputType buildCXSMutationOutputType() { + return newObject() + .name("CXS_Mutation") + .description("Root CXS mutation type") + .field(newFieldDefinition() + .type(registeredOutputTypes.get(CXSEventType.class.getName())) + .name("createOrUpdateEventType") + .argument(newArgument() + .name("eventType") + .type(registeredInputTypes.get(CXSEventTypeInput.class.getName())) + ) + .description("Create or updates a CXS event type in the Apache Unomi server") + ) + .build(); + } + private GraphQLOutputType buildCXSEventOutputType() { return newObject()