Skip to content

Commit

Permalink
Merge pull request #7 from CoreMedia/develop
Browse files Browse the repository at this point in the history
Release: updates for 1.2.0
  • Loading branch information
mweikard committed Mar 8, 2018
2 parents 94cd1f3 + 59d661e commit 8995d8c
Show file tree
Hide file tree
Showing 31 changed files with 304 additions and 151 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
![Status: Active](https://documentation.coremedia.com/badges/badge_status_active.png "Status: Active")
![For CoreMedia CMS](https://documentation.coremedia.com/badges/badge_coremedia_cms.png "For CoreMedia CMS")
![Tested: 9.1707.3](https://documentation.coremedia.com/badges/badge_tested_coremedia_9-1707-3.png "Tested: 9.1707.3")
![Tested: 9.1707.4](https://documentation.coremedia.com/badges/badge_tested_coremedia_9-1707-4.png "Tested: 9.1707.4")
![Tested: 9.1710.1](https://documentation.coremedia.com/badges/badge_tested_coremedia_9-1710-1.png "Tested: 9.1710.1")
![Tested: 9.1801.1](https://documentation.coremedia.com/badges/badge_tested_coremedia_9-1801-1.png "Tested: 9.1801.1")

![CoreMedia Labs Logo](https://documentation.coremedia.com/badges/banner_coremedia_labs_wide.png "CoreMedia Labs Logo Title Text")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ includedTypes:
- CMNavigation
- CMObject
- CMPicture
- CMProduct
- CMResourceBundle
- CMSite
- CMTeasable
- CMTeaser
- CMVideo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: CMProductImpl
customFields:
- !CustomField
name: title
sourceName: (productName)
targetType: String
dataFetcher: Property
- !CustomField
name: teaserTitle
sourceName: (productName)
targetType: String
dataFetcher: Property
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CMVideo
excludedProperties:
- asset
- data
- dataUrl
customFields:
- !CustomField
name: timeLine
sourceName: (timeLine)
targetType: TimeLine
dataFetcher: Struct
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
!ObjectType
name: TimeLine
fields:
- !Property
name: defaultTarget
sourceName: (defaultTarget)
typeName: CMTeasable
- !Property
name: sequences
sourceName: (sequences)
typeName: List:TimeLineEntry
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!ObjectType
name: TimeLineEntry
fields:
- !Property
name: position
sourceName: (position)
typeName: Int
- !Property
name: startTimeMillis
sourceName: (startTimeMillis)
typeName: Int
- !Property
name: target
sourceName: (link)
typeName: CMTeasable
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!query name=videos view=default type=CMVideoImpl

query VideoQuery {

... Teasable

link
timeLine {
defaultTarget {
... Teasable
}
sequences {
position
startTimeMillis
target {
... Teasable
... on CMCollection {
viewtype
items {
... Teasable
}
}
}
}
}
}


fragment Teasable on CMTeasable {
... ContentInfo

teaserTitle
teaserText(view: "teaser")
teaserTarget {
... Reference
}
picture {
... ContentInfo

title
alt
link
}
... on CMProduct {
price: floatSetting(key: "price")
}
}


fragment Reference on CMLinkable {
... ContentInfo

title
segment
link
}


fragment ContentInfo on Content_ {
__typename
__baseinterface
_id
_name
_type
}
4 changes: 4 additions & 0 deletions headless-schema-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>com.coremedia.caas.generator.GeneratorRunner</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public String getTargetType() {
return targetType.getName();
}
break;
case INTEGER:
return "Int";
default:
return getTypeName().substring(0, 1).toUpperCase() + getTypeName().substring(1).toLowerCase();
}
Expand Down
8 changes: 4 additions & 4 deletions headless-server-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>com.coremedia.caas.CaasServletInitializer</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.coremedia.caas.CaasServletInitializer</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
12 changes: 0 additions & 12 deletions headless-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@

<description>Headless Server Spring Boot Application Core</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.coremedia.caas.link.builder;

import com.coremedia.caas.link.LinkBuilder;
import com.coremedia.cap.common.Blob;
import com.coremedia.cap.common.CapBlobRef;
import com.coremedia.cap.common.IdHelper;
import com.coremedia.cap.content.Content;

import org.springframework.stereotype.Component;

@Component(SimpleLinkBuilder.NAME)
Expand All @@ -22,16 +24,28 @@ public String createLink(Object target) {

if (content.getType().isSubtypeOf("CMImage")) {
return "coremedia:///image/" + IdHelper.parseContentId(content.getId()) + "/data";
} else if (content.getType().isSubtypeOf("CMPicture")) {
}
else if (content.getType().isSubtypeOf("CMPicture")) {
return "coremedia:///image/" + IdHelper.parseContentId(content.getId()) + "/data";
} else if (content.getType().isSubtypeOf("CMArticle")) {
}
else if (content.getType().isSubtypeOf("CMArticle")) {
return "coremedia:///article/" + content.getString("segment") + "~" + IdHelper.parseContentId(content.getId());
} else if (content.getType().isSubtypeOf("CMNavigation")) {
}
else if (content.getType().isSubtypeOf("CMNavigation")) {
return "coremedia:///page/" + content.getString("segment") + "~" + IdHelper.parseContentId(content.getId());
} else if (content.getType().isSubtypeOf("CMExternalLink")) {
}
else if (content.getType().isSubtypeOf("CMExternalLink")) {
return content.getString("url");
}
} else if (target instanceof String) {
else if (content.getType().isSubtypeOf("CMVisual") || content.getType().isSubtypeOf("CMAudio")) {
Blob blob = content.getBlob("data");
if (blob != null) {
return "coremedia:///media/" + IdHelper.parseContentId(content.getId()) + "/data";
}
return content.getString("dataUrl");
}
}
else if (target instanceof String) {
return (String) target;
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.coremedia.caas.schema.Types;
import com.coremedia.caas.schema.query.RootDataFetcher;
import com.google.common.collect.ImmutableSet;
import graphql.GraphQLException;
import graphql.schema.GraphQLSchema;

import java.util.List;
Expand All @@ -20,7 +21,7 @@ class ListQueryLoader implements QuerySchemaLoader {

ListQueryLoader(String queryName, String typeName, SchemaService schema) {
querySchema = newSchema().query(newObject().name(queryName + "QueryType")
.field(newFieldDefinition().name("data")
.field(newFieldDefinition().name("items")
.type(Types.getType(typeName, true))
.dataFetcher(new RootDataFetcher()))
.build())
Expand All @@ -31,7 +32,7 @@ class ListQueryLoader implements QuerySchemaLoader {
@Override
public GraphQLSchema load(Object target) {
if (!(target instanceof List)) {
throw new RuntimeException("Invalid Type: " + target);
throw new GraphQLException("Invalid root type: " + target);
}
return querySchema;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.coremedia.caas.query;

import com.coremedia.caas.schema.SchemaService;
import com.coremedia.cap.content.Content;
import com.coremedia.cap.content.ContentType;
import com.google.common.collect.ImmutableSet;
import graphql.GraphQLException;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;

import java.util.Map;
Expand All @@ -17,7 +17,7 @@ class ObjectQueryLoader implements QuerySchemaLoader {
private SchemaService schema;

// cache for built query schemas
private Map<ContentType, GraphQLSchema> querySchemas = new ConcurrentHashMap<>();
private Map<String, GraphQLSchema> querySchemas = new ConcurrentHashMap<>();


ObjectQueryLoader(String typeName, SchemaService schema) {
Expand All @@ -29,11 +29,12 @@ class ObjectQueryLoader implements QuerySchemaLoader {
@Override
public GraphQLSchema load(Object target) {
if (!schema.isInstanceOf(target, typeName)) {
throw new RuntimeException("Invalid Type: " + target);
throw new GraphQLException("Invalid root type: " + target);
}
Content content = (Content) target;
// return most specific object type
return querySchemas.computeIfAbsent(content.getType(), e -> newSchema().query(schema.getObjectType(e))
.build(ImmutableSet.copyOf(schema.getTypes())));
GraphQLObjectType type = schema.getObjectType(target);
if (type == null) {
throw new GraphQLException("No object type for root: " + target);
}
return querySchemas.computeIfAbsent(type.getName(), __ -> newSchema().query(type).build(ImmutableSet.copyOf(schema.getTypes())));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.coremedia.caas.schema;

import com.coremedia.caas.schema.datafetcher.converter.DataFetcherConverter;
import com.coremedia.caas.schema.type.scalar.MapOfScalars;
import com.google.common.collect.ImmutableSet;
import graphql.schema.GraphQLScalarType;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -12,12 +15,23 @@
@Configuration
public class SchemaConfig {

public static final String CONVERSION_SERVICE = "dataFetcherConversionService";


@Bean
@Qualifier("dataFetcherConversionService")
@Qualifier(CONVERSION_SERVICE)
public ConversionService dataFetcherConversionService(Set<DataFetcherConverter> converters) {
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
factory.setConverters(converters);
factory.afterPropertiesSet();
return factory.getObject();
}


@Bean
public Set<GraphQLScalarType> builtinScalars(@Qualifier(CONVERSION_SERVICE) ConversionService conversionService) {
ImmutableSet.Builder<GraphQLScalarType> builder = ImmutableSet.builder();
builder.addAll(new MapOfScalars(conversionService).getTypes().values());
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.coremedia.caas.schema.field.property.StructPropertyField;
import com.coremedia.caas.schema.field.property.UriPropertyField;
import com.coremedia.caas.schema.field.settings.SettingsField;
import com.coremedia.caas.schema.type.StructObjectType;
import com.coremedia.caas.schema.type.object.StructObjectType;
import com.coremedia.cap.content.ContentRepository;
import com.google.common.collect.ImmutableList;
import org.yaml.snakeyaml.TypeDescription;
Expand Down Expand Up @@ -60,7 +60,7 @@ public SchemaService read(ContentRepository contentRepository) throws IOExceptio
for (ConfigResource resource : getResources("schema/*.yml")) {
builder.add((TypeDefinition) yaml.load(resource.asString()));
}
// add fixed types
// add builtin types
builder.add(new StructObjectType());
// create schema registry and service
return new TypeDefinitionRegistry(builder.build()).createSchemaService(contentRepository);
Expand Down
Loading

0 comments on commit 8995d8c

Please sign in to comment.