Transiente Abfragen
Transiente Abfragen erlauben es Ihnen, Runtime-Entitäten dynamisch mit konfigurierbaren Spaltenpfaden abzufragen. Anders als bei regulären Abfragen, bei denen die zurückgegebenen Felder in der GraphQL-Abfrage selbst definiert werden, geben transiente Abfragen Daten in einer tabellenartigen Struktur mit Zeilen und Zellen zurück.
Anwendungsfälle
Transiente Abfragen sind nützlich, wenn:
- Dynamische Tabellenansichten erstellt werden, bei denen Spalten benutzerkonfigurierbar sind
- Die Menge der abzurufenden Attribute zur Kompilierzeit nicht bekannt ist
- Sie ein tabellarisches Datenformat mit Metadaten über die Spalten benötigen
Grundlegende Verwendung
query getTransientRuntimeQuery(
$ckId: String!
$columnPaths: [String!]!
$first: Int
$after: String
) {
runtime {
transientRuntimeQuery(
ckId: $ckId
columnPaths: $columnPaths
first: $first
after: $after
) {
items {
columns {
attributePath
attributeValueType
}
rows(first: $first, after: $after) {
totalCount
items {
rtId
cells {
items {
attributePath
value
}
}
}
}
}
}
}
}
Variablen:
{
"ckId": "EnergyCommunity/Customer",
"columnPaths":["rtId", "contact.firstName"],
"first": 10
}
Struktur der Antwort
Die Antwort enthält:
- columns: Metadaten über jede angeforderte Spalte (Attributpfad und Werttyp)
- rows: Die tatsächlichen Datenzeilen mit Zellen, die Werte enthalten
{
"data": {
"runtime": {
"transientRuntimeQuery": {
"items": [
{
"columns": [
{
"attributePath": "contact.firstName",
"attributeValueType": "STRING"
},
{
"attributePath": "rtId",
"attributeValueType": "STRING"
}
],
"rows": {
"totalCount": 9,
"items": [
{
"rtId": "693c4cd3464d7d9e1396cf0d",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4cd3464d7d9e1396cf0d"
}
]
}
},
{
"rtId": "693c4d3e464d7d9e1396cf0e",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4d3e464d7d9e1396cf0e"
}
]
}
},
{
"rtId": "693c4d97464d7d9e1396cf0f",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4d97464d7d9e1396cf0f"
}
]
}
},
{
"rtId": "693c4d97464d7d9e1396cf10",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "Jane"
},
{
"attributePath": "rtId",
"value": "693c4d97464d7d9e1396cf10"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf11",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf11"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf12",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "Jane"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf12"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf13",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "Max"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf13"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf14",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "Erika"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf14"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf15",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "Paul"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf15"
}
]
}
}
]
}
}
]
}
}
}
}
Spaltenpfade
Spaltenpfade können referenzieren:
- Direkte Attribute:
"name","voltage","state" - Verschachtelte Attribute (Records):
"contact.firstName","address.street" - Assoziationsattribute:
"customer.name"(über Assoziation)
Kombination mit Filtern und Sortierung
Transiente Abfragen unterstützen alle Standard-Abfrageparameter:
query getTransientRuntimeQuery(
$ckId: String!
$columnPaths: [String!]!
$first: Int
$after: String
) {
runtime {
transientRuntimeQuery(
ckId: $ckId
columnPaths: $columnPaths
first: $first
after: $after
searchFilter: {
searchTerm: "John"
type: ATTRIBUTE_FILTER
attributePaths: ["contact.firstName"]
}
fieldFilter: [
{ attributePath: "state", operator: EQUALS, comparisonValue: "ACTIVE" }
]
sortOrder: [
{ attributePath: "contact.firstName", sortOrder: ASCENDING }
]
) {
items {
columns {
attributePath
attributeValueType
}
rows(first: $first, after: $after) {
totalCount
items {
rtId
cells {
items {
attributePath
value
}
}
}
}
}
}
}
}
Diese Abfrage filtert nach Entitäten, bei denen der Vorname des Kontakts „John" enthält und der state „ACTIVE" ist, sortiert nach dem Vornamen.
{
"data": {
"runtime": {
"transientRuntimeQuery": {
"items": [
{
"columns": [
{
"attributePath": "contact.firstName",
"attributeValueType": "STRING"
},
{
"attributePath": "rtId",
"attributeValueType": "STRING"
}
],
"rows": {
"totalCount": 4,
"items": [
{
"rtId": "693c4cd3464d7d9e1396cf0d",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4cd3464d7d9e1396cf0d"
}
]
}
},
{
"rtId": "693c4d3e464d7d9e1396cf0e",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4d3e464d7d9e1396cf0e"
}
]
}
},
{
"rtId": "693c4d97464d7d9e1396cf0f",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c4d97464d7d9e1396cf0f"
}
]
}
},
{
"rtId": "693c51af464d7d9e1396cf11",
"cells": {
"items": [
{
"attributePath": "contact.firstName",
"value": "John"
},
{
"attributePath": "rtId",
"value": "693c51af464d7d9e1396cf11"
}
]
}
}
]
}
}
]
}
}
}
}
Parameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
ckId | String | Ja | Die abzufragende Construction-Kit-Typ-ID |
columnPaths | [String!] | Ja | Liste von Attributpfaden, die als Spalten aufgenommen werden |
first | Int | Nein | Anzahl der zurückzugebenden Zeilen (Pagination) |
after | String | Nein | Cursor für die Pagination |
searchFilter | SearchFilter | Nein | Textsuchfilter |
fieldFilter | [FieldFilter] | Nein | Attributbasierte Filter |
sortOrder | [Sort] | Nein | Sortierreihenfolge für Ergebnisse |
Transiente Abfragen vs. reguläre Abfragen
| Aspekt | Reguläre Abfrage | Transiente Abfrage |
|---|---|---|
| Spaltendefinition | Fest in der GraphQL-Abfrage | Dynamisch über columnPaths |
| Antwortformat | Typisierte Objektstruktur | Tabellenstruktur (rows/cells) |
| Typsicherheit | Volle GraphQL-Typsicherheit | Werte werden als generischer value zurückgegeben |
| Anwendungsfall | Bekannte Datenstruktur | Dynamische/konfigurierbare Ansichten |
| Performance | Für bestimmte Felder optimiert | Etwas mehr Overhead |
Verwenden Sie reguläre Abfragen, wenn die Datenstruktur zur Entwicklungszeit bekannt ist. Verwenden Sie transiente Abfragen für dynamische Szenarien wie benutzerkonfigurierbare Datengitter.