-
Notifications
You must be signed in to change notification settings - Fork 9
Schema Definition
The GraphQL schemas used by CaaS are created from YAML definition files. Each file describes a GraphQL interface or object type with its inheritance and fields. It is best practice to define an interface and object type for each used CoreMedia content type and only define fields within the interface type (this is automatically done when using the Schema Generator).
Type Descriptor: !InterfaceType
Properties:
-
name: The type's name. -
parents: The type's parent interface type. -
fields: A list of defined fields.
Example:
!InterfaceType
name: CMLocalized
parents:
- CMObject
fields:
- !ContentProperty
name: languageId
sourceName: (locale)
typeName: StringType Descriptor: !ObjectType
Properties:
-
name: The type's name. -
parent: The type's parent object type. -
interfaces: A list of interfaces the type implements. -
fields: A list of defined fields.
Example:
!ObjectType
name: CMLocalizedImpl
parent: CMObjectImpl
interfaces:
- CMLocalizedFields are split into generic accessors to (scalar) UAPI content properties and methods and specialized accessors for more complex types, i.e. richtext or link lists.
Type Descriptor: !Constant
Properties:
-
name: The field's name. -
value: A special SpEL expression defining the value. Expressions encapsulated with#{<expr>}are evaluated at schema loading time. Expressions encapsulated with${<expr>}are evaluated at runtime. If no value expression is given null is returned. -
typeName: The returned value's type. -
nonNull: Optional constraint for the returned value.
Example:
- !Constant
name: tag
value: "#{'ROOT'}"
typeName: StringA field with a constant scalar value.
Type Descriptor: !Property
Properties:
-
name: The fields's name. -
sourceName: Optional SpEL expression for retrieving the value from the source object. The field's name is used as expression value if this property is not set. -
typeName: The returned value's type. -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Property
name: _name
sourceName: "name"
typeName: String
nonNull: trueType Descriptor: !ContentProperty
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The returned value's type. -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !ContentProperty
name: title
sourceName: "title"
typeName: StringType Descriptor: !Blob
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Blob
name: data
sourceName: "data"The GraphQL object type of a blob is fixed and contains the following attributes:
-
contentType: The blob's MIME type. -
size: The blob's size in bytes.
Type Descriptor: !Richtext
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: Must be set toStringorRichtextTree(see Richtext). -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Richtext
name: detailText
sourceName: "detailText"
typeName: StringSee Richtext for processing CoreMedia richtext properties.
Type Descriptor: !Link
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the link list property value from the source object. The first element (if any) from the list that matches the field's type is returned. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The returned value's type. -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Link
name: picture
sourceName: "pictures"
typeName: CMPictureType Descriptor: !Linklist
Properties:
-
name: The field's name. -
sourceName: SpEL expression for the retrieving the link list property value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The returned value's list type (the interface/object type prefixed withList:). -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Linklist
name: pictures
sourceName: "pictures"
typeName: List:CMPictureType Descriptor: !ExtendedLinklist
Properties:
-
name: The field's name. -
sourceName: SpEL expression for the retrieving the extended link list property value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The returned value's list type (the interface/object type prefixed withList:). -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !ExtendedLinklist
name: teaserTargets
sourceName: "targets?.links"
typeName: List:ExtendedTeaserTargetType Descriptor: !Struct
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the struct value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The type name of the static object model that applies to the struct value. -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Struct
name: timeLine
sourceName: "timeLine"
typeName: TimeLineIf the return type of a Struct Field is a Struct itself, a static object type must be defined for accessing it's values.
See the TimeLine and TimeLineEntry types in the sample schema for the returned object types.
Type Descriptor: !Uri
Properties:
-
name: The field's name. -
sourceName: SpEL expression for retrieving the value from the source object. -
fallbackSources: Optional list of SpEL expressions which are evaluated if the original source expression yields null or an empty result. -
typeName: The returned value's type (a string if using the example Link Builder). -
nonNull: Optional constraint for the returned value. -
directives: Optional list of directives to apply.
Example:
- !Uri
name: link
sourceName: "this"
typeName: StringType Descriptor: !Bean
Properties:
-
name: The field's name. -
sourceName: The Spring bean's name. -
fallbackSources: Optional list of source names passed to the bean. -
typeName: The returned value's type. -
nonNull: Optional constraint for the returned value.
Example:
- !Bean
name: subject
sourceName: "subjectBean"
typeName: StringA bean field uses a generic data fetcher which delegates value retrieval to a named bean defined in the Spring context.
The bean must be a subclass of DataFetcherDelegateBean:
package com.coremedia.caas.schema.datafetcher.delegate;
//...
public interface DataFetcherDelegateBean {
Object get(ContentProxy source, String sourceName, List<String> fallbackSourceNames, String typeName, DataFetchingEnvironment environment) throws Exception;
}Type Descriptor: !Meta
Properties:
-
name: The field's name. -
typeName: Matching type for the selected field. -
nonNull: Optional constraint for the returned value.
A metadata field returns internal schema information. Valid field names are:
-
__interfaces: List of all interface types implemented by the source object. SettypeNametoList:String. -
__baseinterface: The object's primary interface, e.g.CMLinkablefor object typeCMLinkableImpl. SettypeNametoString.
Example:
- !Meta
name: __baseinterface
typeName: String
nonNull: trueAll scalar types of the graphql-java library are supported:
BooleanBigDecimalBigIntegerByteCharFloatIDIntegerLongShortString
Interface types for content objects are named like their name in the document type model, e.g. CMLinkable.
Object types append Impl to their interface name, e.g. CMLinkableImpl.
List types are defined by using the base scalar or interface/object type prefixed with List:, e.g. List:String, List:CMLinkable.
Limited type conversion is performed on scalar types using the default Spring type converters.
Unless otherwise noted SpEL is used for all for source and fallback expressions. See Spring Expression Language (SpEL) for more details.
Example fetching the view type name from a CMLinkable:
sourceName: "getLink('viewtype')?.layout"If navigating through the object graph pay attention to the Safe Navigation operator to avoid NullPointerExceptions.
The special path expression this refers to the current object. It's used e.g. for generating links:
- !Uri
name: link
sourceName: "this"
typeName: StringThe schema supports the two directives if and filter which are the same as the ones applied to the queries.
Directives in the schema always take precedence over directives defined in the queries.
Example:
- !Struct
name: timeLine
sourceName: (timeLine)
typeName: TimeLine
directives:
- !Directive
name: if
arguments:
test: "getLink('viewtype')?.layout == 'shoppable'"With the introduction of SpEL the specialized data fetchers for e.g. navigation and page grid access have been removed with with special model objects that are directly used in the SpEL expressions:
- !CustomField
name: children
sourceName: "$navigation().children"
targetType: List:CMLinkable
dataFetcher: ContentProperty
- !CustomField
name: grid
sourceName: "$pageGrid('placement')"
targetType: PageGrid
dataFetcher: ContentPropertyA model accessor looks like a regular method call with the method name prefixed with $.
The following models are provided out of the box:
$navigation()
Provides access to navigation related properties. Uses TreeRelation and ContextStrategy implementations from Blueprint Base.
Available methods on the returned model are:
- isHidden: Hidden in navigation flag from the Blueprint model.
- isHiddenInSitemap: Hidden in navigation and sitemap flag from the Blueprint model.
- getContext: Navigational context.
- getChildren: Navigational children.
- getPathToRoot: Path to root page.
$pageGrid('<placement property name>')
Provides access to a page grid and it's placement.
Available methods on the returned model are:
- getCssClassName: The class name store with the grid.
- getPlacements: The list of placement models.
Placement models implement the following methods:
- getName: The placement's name.
- getViewtype: The placement's viewtype.
- getItems: The items stored in the placement.
$settings()
Provides access to the SettingsService.
Available methods on the returned model are:
- get(String propertyPath): Retrieves a setting with the given path.
- get(String propertyPath, Object defaultValue): Retrieves a setting with the given path. Returns the default value if retrieved value is null.
The path segments in the given property path must be separated by /. A leading / is optional.
Example:
$settings().get('callToActionDisabled', false)
$extendedLinks('<extended linklist property name>', '<legacy linklist property name>')
Provides access to the link target(s) of an extended link list or the legacy link list if the new property has not been written to yet.
Available methods on the returned model are:
- target: The singleton or first valid target of the link list.
- targets: All valid target of the link list.
This model is typically only required if you need to access properties from the target objects and not the link list itself.
See the CMTeaserImpl type from the Sample Schema.