Records
Records sind zusammengesetzte Wertetypen, die verwandte Attribute zusammenfassen. Anders als Typen werden Records direkt in Entitäten eingebettet, statt eigenständige Entitäten mit eigenen Runtime-IDs zu sein.
Records auflisten
Alle Records abrufen:
query getCkRecords($after: String, $first: Int, $ckModelIds: [String]) {
constructionKit {
records(after: $after, first: $first, ckModelIds: $ckModelIds) {
totalCount
items {
ckRecordId {
fullName
semanticVersionedFullName
}
}
}
}
}
Antwort
{
"data": {
"constructionKit": {
"records": {
"totalCount": 5,
"items": [
{
"ckRecordId": {
"fullName": "Basic-1.0.0/Contact-1",
"semanticVersionedFullName": "Basic/Contact"
}
},
{
"ckRecordId": {
"fullName": "Basic-1.0.0/Address-1",
"semanticVersionedFullName": "Basic/Address"
}
}
]
}
}
}
}
Nach Modell filtern
Records aus bestimmten Modellen abrufen:
query {
constructionKit {
records(ckModelIds: ["Basic-1"]) {
totalCount
items {
ckRecordId {
fullName
}
}
}
}
}
Details eines Records
Detaillierte Informationen zu einem bestimmten Record abrufen, einschließlich seiner Attribute und Vererbung:
query getCkRecordDetails($ckId: String) {
constructionKit {
records(ckId: $ckId) {
totalCount
items {
ckRecordId {
fullName
semanticVersionedFullName
}
description
isAbstract
isFinal
baseRecordTypes {
ckRecordId {
fullName
semanticVersionedFullName
}
isAbstract
isFinal
}
derivedRecordTypes {
pageInfo {
endCursor
hasNextPage
}
items {
ckRecordId {
fullName
}
isAbstract
isFinal
}
}
attributes {
pageInfo {
endCursor
hasNextPage
}
items {
attributeName
attributeValueType
ckAttributeId {
fullName
semanticVersionedFullName
}
isOptional
}
}
}
}
}
}
Variablen:
{
"ckId": "Basic-1.0.0/Contact-1"
}
Antwort
{
"data": {
"constructionKit": {
"records": {
"totalCount": 1,
"items": [
{
"ckRecordId": {
"fullName": "Basic-1.0.0/Contact-1",
"semanticVersionedFullName": "Basic/Contact"
},
"description": "Contact information including name and address",
"isAbstract": false,
"isFinal": false,
"baseRecordTypes": [],
"derivedRecordTypes": {
"pageInfo": {
"endCursor": null,
"hasNextPage": false
},
"items": []
},
"attributes": {
"pageInfo": {
"endCursor": "YXJyYXljb25uZWN0aW9uOjU=",
"hasNextPage": false
},
"items": [
{
"attributeName": "firstName",
"attributeValueType": "STRING",
"ckAttributeId": {
"fullName": "Basic-1.0.0/FirstName-1",
"semanticVersionedFullName": "Basic/FirstName"
},
"isOptional": true
},
{
"attributeName": "lastName",
"attributeValueType": "STRING",
"ckAttributeId": {
"fullName": "Basic-1.0.0/LastName-1",
"semanticVersionedFullName": "Basic/LastName"
},
"isOptional": true
},
{
"attributeName": "companyName",
"attributeValueType": "STRING",
"ckAttributeId": {
"fullName": "Basic-1.0.0/CompanyName-1",
"semanticVersionedFullName": "Basic/CompanyName"
},
"isOptional": true
},
{
"attributeName": "address",
"attributeValueType": "RECORD",
"ckAttributeId": {
"fullName": "Basic-1.0.0/Address-1",
"semanticVersionedFullName": "Basic/Address"
},
"isOptional": true
}
]
}
}
]
}
}
}
}
Record-Vererbung
Records unterstützen Vererbung ähnlich wie Typen. Ein abgeleiteter Record erbt alle Attribute von seinem Basis-Record:
query {
constructionKit {
records(ckId: "Basic-1.0.0/ExtendedContact-1") {
items {
ckRecordId {
fullName
}
baseRecordTypes {
ckRecordId {
fullName
}
}
attributes {
items {
attributeName
attributeValueType
}
}
}
}
}
}
Antwort
{
"data": {
"constructionKit": {
"records": {
"items": [
{
"ckRecordId": {
"fullName": "Basic-1.0.0/ExtendedContact-1"
},
"baseRecordTypes": [
{
"ckRecordId": {
"fullName": "Basic-1.0.0/Contact-1"
}
}
],
"attributes": {
"items": [
{ "attributeName": "firstName", "attributeValueType": "STRING" },
{ "attributeName": "lastName", "attributeValueType": "STRING" },
{ "attributeName": "companyName", "attributeValueType": "STRING" },
{ "attributeName": "address", "attributeValueType": "RECORD" },
{ "attributeName": "email", "attributeValueType": "STRING" },
{ "attributeName": "phone", "attributeValueType": "STRING" }
]
}
}
]
}
}
}
}
Verschachtelte Records
Records können andere Records als Attribute enthalten. Im obigen Beispiel enthält Contact einen Address-Record:
query {
constructionKit {
records(ckId: "Basic-1.0.0/Address-1") {
items {
ckRecordId {
fullName
}
attributes {
items {
attributeName
attributeValueType
}
}
}
}
}
}
Antwort
{
"data": {
"constructionKit": {
"records": {
"items": [
{
"ckRecordId": {
"fullName": "Basic-1.0.0/Address-1"
},
"attributes": {
"items": [
{ "attributeName": "street", "attributeValueType": "STRING" },
{ "attributeName": "cityTown", "attributeValueType": "STRING" },
{ "attributeName": "zipcode", "attributeValueType": "INT32" },
{ "attributeName": "country", "attributeValueType": "STRING" }
]
}
}
]
}
}
}
}
Record-Felder
CkRecord
| Feld | Typ | Beschreibung |
|---|---|---|
ckRecordId | CkRecordId | Der Identifier des Records |
description | String | Beschreibung des Records |
isAbstract | Boolean | Ob der Record abstrakt ist |
isFinal | Boolean | Ob der Record erweitert werden kann |
baseRecordTypes | [CkRecord] | Übergeordnete Records (Vererbung) |
derivedRecordTypes | CkRecordConnection | Records, die diesen Record erweitern |
attributes | CkRecordAttributeConnection | Auf diesem Record definierte Attribute |
CkRecordAttribute
| Feld | Typ | Beschreibung |
|---|---|---|
attributeName | String | Der Name des Attributs |
attributeValueType | String | Der Datentyp |
ckAttributeId | CkAttributeId | Referenz auf die Attributdefinition |
isOptional | Boolean | Ob das Attribut optional ist |
Records in Runtime-Operationen verwenden
Records werden als eingebettete strukturierte Daten innerhalb von Entitäten verwendet. Sie treten in zwei Formen auf:
| Attributtyp | Beschreibung | Anwendungsfall |
|---|---|---|
| Record | Einzelner eingebetteter Record | Kontaktinformationen, primäre Spezifikation |
| RecordArray | Array eingebetteter Records | Liste von Spezifikationen, mehrere Kontakte |
Records im Construction Kit definieren
Records werden in YAML-Dateien innerhalb des Construction Kit definiert:
# records/specification.yaml
$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
records:
- recordId: Specification
attributes:
- id: ${this}/SpecificationName
name: Name
- id: ${this}/SpecificationValue
name: Value
- id: ${this}/SpecificationUnit
name: Unit
isOptional: true
Records in Typdefinitionen verwenden
# types/product.yaml
$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
types:
- typeId: Product
derivedFromCkTypeId: ${System}/Entity
attributes:
- id: ${this}/ProductName
name: ProductName
# Record attribute (single)
- id: ${this}/MainSpecification
name: MainSpecification
isOptional: true
# RecordArray attribute (multiple)
- id: ${this}/TechnicalSpecifications
name: TechnicalSpecifications
isOptional: true
Attributdefinition für Record-Typen
# attributes/product.yaml
$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
attributes:
# Single Record
- id: MainSpecification
valueType: Record
valueCkRecordId: ${this}/Specification
description: "Main specification of the product"
# Array of Records
- id: TechnicalSpecifications
valueType: RecordArray
valueCkRecordId: ${this}/Specification
description: "List of technical specifications"
GraphQL-Schema-Generierung
Für einen Typ mit Record-Attributen generiert OctoMesh:
Input-Typen (für Mutationen):
ProductInput– mitmainSpecification: SpecificationInputSpecificationInput– mit den Feldernname,value,unit
Output-Typen (für Abfragen):
Product– mitmainSpecification: SpecificationSpecification– mit den Feldernname,value,unit
Beispiele für Runtime-Daten
Ausführliche Beispiele zum Erstellen und Aktualisieren von Entitäten mit Record- und RecordArray-Attributen finden Sie unter: