Zum Hauptinhalt springen

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​

ParameterTypErforderlichBeschreibung
ckIdStringJaDie abzufragende Construction-Kit-Typ-ID
columnPaths[String!]JaListe von Attributpfaden, die als Spalten aufgenommen werden
firstIntNeinAnzahl der zurückzugebenden Zeilen (Pagination)
afterStringNeinCursor für die Pagination
searchFilterSearchFilterNeinTextsuchfilter
fieldFilter[FieldFilter]NeinAttributbasierte Filter
sortOrder[Sort]NeinSortierreihenfolge für Ergebnisse

Transiente Abfragen vs. reguläre Abfragen​

AspektReguläre AbfrageTransiente Abfrage
SpaltendefinitionFest in der GraphQL-AbfrageDynamisch über columnPaths
AntwortformatTypisierte ObjektstrukturTabellenstruktur (rows/cells)
TypsicherheitVolle GraphQL-TypsicherheitWerte werden als generischer value zurückgegeben
AnwendungsfallBekannte DatenstrukturDynamische/konfigurierbare Ansichten
PerformanceFür bestimmte Felder optimiertEtwas 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.