Skip to main content

Create

GraphQL allows to query and mutate data. Mutations are operations like create, update and delete. This chapter describes how data can be created.

Simple create mutation

The area runtime allows access to entities fo the Runtime Model Let's start with simple sample that requests the name of all energy meters.

mutation {
runtime {
energyCommunityCustomers {
create(
entities: [
{
contact:{
firstName: "John"
lastName: "Doe"
address: {
nationalCode: "AT"
street: "Example Avenue 99"
zipcode: 12345
cityTown: "Testville"
}
}
taxProcedureCreditNote: REVERSE_CHARGE
}
]
) {
rtId
}
}
}
}

This query will create an energy meter object with the given data. The result of the object will be like

{
"data": {
"runtime": {
"energyCommunityCustomers": {
"create": [
{
"rtId": "693c4cd3464d7d9e1396cf0d"
}
]
}
}
}
}

Create with variables

For programmatic use, it is recommended to use GraphQL variables:

mutation createCustomers($entities: [EnergyCommunityCustomerInput]!) {
runtime {
energyCommunityCustomers {
create(entities: $entities) {
rtId
}
}
}
}

Variables:

{
"entities": [
{
"contact": {
"firstName": "John",
"lastName": "Doe",
"address": {
"nationalCode": "AT",
"street": "Example Avenue 99",
"zipcode": 12345,
"cityTown": "Testville"
}
},
"taxProcedureCreditNote": "REVERSE_CHARGE"
}
]
}

Batch create

Multiple entities can be created in a single request by providing multiple entries in the entities array:

mutation {
runtime {
energyCommunityCustomers {
create(
entities: [
{
state: ACTIVE
contact:{
firstName: "John"
lastName: "Doe"
address: {
nationalCode: "AT"
street: "Example Avenue 99"
zipcode: 1010
cityTown: "Wien"
}
}
taxProcedureCreditNote: REVERSE_CHARGE
},
{
state: ACTIVE
contact:{
firstName: "Jane"
lastName: "Smith"
address: {
nationalCode: "DE"
street: "Sample Street 42"
zipcode: 10115
cityTown: "Berlin"
}
}
taxProcedureCreditNote: NO_TAX_PROCEDURE
},
{
state: ACTIVE
contact:{
firstName: "Max"
lastName: "Mustermann"
address: {
nationalCode: "AT"
street: "Musterstraße 12"
zipcode: 4020
cityTown: "Linz"
}
}
taxProcedureCreditNote: REVERSE_CHARGE
},
{
state: INACTIVE
contact:{
firstName: "Erika"
lastName: "Musterfrau"
address: {
nationalCode: "DE"
street: "Beispielweg 7"
zipcode: 80331
cityTown: "München"
}
}
taxProcedureCreditNote: NO_TAX_PROCEDURE
},
{
state: INACTIVE
contact:{
firstName: "Paul"
lastName: "Example"
address: {
nationalCode: "CH"
street: "Testgasse 5"
zipcode: 8001
cityTown: "Zürich"
}
}
taxProcedureCreditNote: REVERSE_CHARGE
}
]
) {
rtId
}
}
}
}

This will create two separate entities in a single mutation call. The result will be like

{
"data": {
"runtime": {
"energyCommunityCustomers": {
"create": [
{
"rtId": "693c4cd3464d7d9e1396cf0d"
},
{
"rtId": "693c4cd3464d7d9e1396cf0e"
}
]
}
}
}
}

Create with associations

When creating entities that have associations to other entities, you can specify the associated entities using their rtId and ckTypeId.

mutation {
runtime {
energyCommunityOperatingFacilitys {
create(
entities: [
{
state: ACTIVE
facilityType: HOUSEHOLD
name: "Demo"
address: {
nationalCode: "AT"
street: "Example Avenue 99"
zipcode: 1010
cityTown: "Wien"
},
parent:[{modOption:CREATE, target: {rtId:"5fc8fda18b2fc75f925e21ac", ckTypeId: "Basic/TreeNode"}}]
customer: [{modOption:CREATE, target:{rtId:"693c4cd3464d7d9e1396cf0d", ckTypeId: "EnergyCommunity/Customer"}}]
}
]
) {
rtId
}
}
}
}

This mutation creates an OperatingFacility entity and associates it with an existing TreeNode and Customer entity.

The result will be like

{
"data": {
"runtime": {
"energyCommunityOperatingFacilitys": {
"create": [
{
"rtId": "693c5b93464d7d9e1396cf1c"
}
]
}
}
}
}