Why is it important to know what Graph Types are? One, when trying to create a new schema or extending an existing schema of a query, it is important to know which Graph Type to use in the code. And Second, It is always good to learn something new.
From a code stand point, Graph Types are nothing but C# classes which emit some fields and properties required within the graph queries. We will start with the base class of the Graph Type which is inherited by intermediate classes and finally end with the derived class which inherits the intermediate class. There are also some stand alone classes which can be directly used such as FieldType.
The GraphType itself is an abstract C# class which is meant to be inherited. This class provides certain fields and properties such as Name, Description, HasMetadata(), CollectionTypes() etc. This Name and Description field is used to define the name and description of the schema. Refer image below
This class also inherits from certain interfaces to extend their properties.
Fields | Properties |
---|---|
public string Name { get; set; } | public TType GetMetadata(string key, TType defaultValue = default(TType)) |
public string Description { get; set; } | public bool HasMetadata(string key) |
public string DeprecationReason { get; set; } | public virtual string CollectTypes(TypeCollectionContext context) |
protected bool Equals(IGraphType other) |
Intermediate classes are those who inherit from the GraphType class. Currently will see 2 intermediate classes.
It is an abstract C# class which inherits the GraphType class. The properties of this class are Serialize(), ParseValue() and ParseLiteral() which are abstract as well. From the names of the properties its functionalities can also be assumed. As it inherits from GraphType class it also extends the properties such as Name, Description etc.
Properties
The ComplexGraphType
Properties
Derived classes are classes which inherit from scalar or complex graph types (Not restricted to these two). These classes inherit all the properties of GraphType class and scalar/complex graph type class. These classes override the Serialize(object value), ParseValue(object value), ParseLiteral(IValue value) properties to render specific values.
This class derives from Scalar class and uses its properties to define functionalities render an Integer value.
This class derives from Scalar class and uses its properties to define functionalities render a String value.
This class derives from Scalar class and uses its properties to define functionalities render a Boolean value.
This class derives from ObjectGraphTypeField
Effective use of Sitecore Graph Types is essential for developers tasked with schema creation or extension. These types, ranging from base to derived classes, enhance development by offering a structured framework for data interactions. Understanding the roles of scalar, complex, and derived graph types helps in achieving more efficient application management. This guide highlights the critical aspects of Sitecore Graph Types, setting the stage for developers to further improve their projects.