Solved

Can create an edge with any "type" through API call but could not see it in the UI


It seems I can create an edge with any type. In the code example below, the externalId of the “type” is set to “xxx” when calling POST Add edges, which should not exist. However, the edge was added successfully. Furthermore, I could not see any edges were created in the SimulationModel table, even the “externalId” was set to “SimulatonModelSimulator”.

 

        {
"instanceType": "edge",
"space": "XiaofengTest",
"externalId": "externalId:edge1",
"type": {
"space": "XiaofengTest",
"externalId": "xxx"
},
"startNode": {
"space": "XiaofengTest",
"externalId": "externalId:simulator1"
},
"endNode": {
"space": "XiaofengTest",
"externalId": "externalId:simmodel1"
}
}

 

icon

Best answer by Jason Dressel 7 March 2023, 08:55

View original

4 replies

Userlevel 4
Badge

Xiaofeng,

Looking at XiaofengTestDataModel, I don’t exactly know between which 2 types you are relating (creating edge for). 

There are 2 types of relations 
If your model looked something like:

type SimulationModel {
name: String!
simulator: Simulator
nodes: [Node]
}

type Simulator {
name: String!
}

type Node {
name: String!
}

You would need to create a Simulator instance first (I presume you have that).  Let’s assume that the id of a Simulator node instance is “simulator-s”

A SimulationModel Instance creation would look something like this:

        {
"instanceType": "node",
"existingVersion": 1,
"space": "your-space",
"externalId": "sim-model-id-x",
"sources": [
{
"source": {
"type": "view",
"space": "your-space",
"externalId": "SimulationModel",
"version": "1"
},
"properties": {
"name": "a name"
"simulator": {
"space": "your-space",
"externalId": "simulator-s"
}
}
}
]
}

The Nodes Edge instance item should look something like this:

        {
"instanceType": "edge",
"existingVersion": 1,
"space": "your-space",
"externalId": "unique edge id",
"type": {
"space": "your-space",
"externalId": "SimulationModel.nodes"
},
"startNode": {
"space": "your-space",
"externalId": "sim-model-id-x"
},
"endNode": {
"space": "your-space",
"externalId": "node-id-123"
}
}

Hope this helps,

Jason

Hi Jason,

 

Thanks for your reply. As you may see, I created an instance for SimulationModel and also an instance for Simulator and would like to create a direct relation between those two instances. I tried to use “SimulationModel.simulator” and “SimulationModel.Simulator” or any string as the “externalId” of the “type” when creating the edge but seems no matter what I used a new edge was created successfully.

Request:

{
"items": [
{
"instanceType": "node",
"space": "XiaofengTest",
"externalId": "externalId:simmodel1",
"sources": [
{
"source": {
"type": "view",
"space": "XiaofengTest",
"externalId": "SimulationModel",
"version": "1"
},
"properties": {
"modelName": "firstSimulationModelName",
"modelId": "xxx-xxx-xxx-xxx-xxx"
}
}
]
},
{
"instanceType": "node",
"space": "XiaofengTest",
"externalId": "externalId:simulator1",
"sources": [
{
"source": {
"type": "view",
"space": "XiaofengTest",
"externalId": "Simulator",
"version": "1"
},
"properties": {
"type": "OLGA",
"version": "2021.1",
"name": "FASimulator"
}
}
]
},
{
"instanceType": "edge",
"space": "XiaofengTest",
"externalId": "externalId:edge4",
"type": {
"space": "XiaofengTest",
"externalId": "SimulationModel.simulator"
},
"startNode": {
"space": "XiaofengTest",
"externalId": "externalId:simulator1"
},
"endNode": {
"space": "XiaofengTest",
"externalId": "externalId:simmodel1"
}
}
],
"autoCreateStartNodes": false,
"autoCreateEndNodes": false,
"skipOnVersionConflict": false,
"replace": false
}

Response:

{
"items": [
{
"instanceType": "node",
"version": 1,
"wasModified": false,
"space": "XiaofengTest",
"externalId": "externalId:simmodel1",
"createdTime": 1677858518363,
"lastUpdatedTime": 1677858518363
},
{
"instanceType": "node",
"version": 1,
"wasModified": false,
"space": "XiaofengTest",
"externalId": "externalId:simulator1",
"createdTime": 1677858518363,
"lastUpdatedTime": 1677858518363
},
{
"instanceType": "edge",
"version": 1,
"wasModified": true,
"space": "XiaofengTest",
"externalId": "externalId:edge4",
"createdTime": 1678174622351,
"lastUpdatedTime": 1678174622351
}
]
}

However, in the UI those two instance were not connected and the “simulator” is null

Could you help me find out what was missing in my request?

Userlevel 4
Badge

Have a look at the sample I shared.  The “Direct” relation is not established by creating an Edge. It’s established by setting the property on the Node

        {
"instanceType": "node",
"space": "XiaofengTest",
"externalId": "externalId:simmodel1",
"sources": [
{
"source": {
"type": "view",
"space": "XiaofengTest",
"externalId": "SimulationModel",
"version": "1"
},
"properties": {
"modelName": "firstSimulationModelName",
"modelId": "xxx-xxx-xxx-xxx-xxx"
#DECLARE THE DIRECT RELATION
"simulator": {
"space": "XiaofengTest",
"externalId": "externalId:simulator1"
####
}
}
]
}

 

Aha, I see. So a one to one relation or “Direct” relation does not need an Edge. Now I am able to create a “Direct” relation between those two instances following your suggestion. Thanks a lot!

Reply