Note: Sign in to access the data in this sample. username
password
Getting Started
Knowledge graphs allow you to model real-world systems that contain both spatial and nonspatial entities (such as people, places and things) and the relationships that connect them, allowing you to leverage both spatial and nonspatial tools in your analysis. A knowledge graph allows you work with a graph network. Both entities and relationships are objects in the graph data structure and can have associated properties. Entity types can be defined with or without spatial information.
The sample dataset contains observations of bumble bees made at locations around the United States. Each observation was made and verified by users and is of a specific species of bumble bee.

1. Sign in
The data in this example is secured, as most knowledge graph data will be since the ArcGIS Knowledge Graph Server license is required. Therefore, the first step is to sign in to load the data.
2. Fetch the graph
In order to update the data model for a knowledge graph, you first have to fetch the graph which retrieves the knowledge graph service definition and the current data model.
let kg = await KnowledgeGraphService.fetchKnowledgeGraph(url)
3. Add new named types
Start by adding a new entity type to the graph. First define the entity type to add.
//define the new entity type
const newEntityType = {
type: "entity",
name: "MyNewEntityType" + Math.floor(Math.random() * 100) + 1,
alias: "NewEntityType",
properties: [
{
name: "name",
alias: "full name",
fieldType: "esriFieldTypeString",
defaultValue: "new entity",
role: "esriGraphPropertyRegular",
},
{
name: "shape",
alias: "location",
fieldType: "esriFieldTypeGeometry",
geometryType: "esriGeometryPoint",
role: "esriGraphPropertyRegular",
required: false,
editable: true,
},
],
};
Then use knowledge
to add the new entity type to the knowledge graph.
The knowledge graph data model will be updated with a new entity type that contains a name
property and a shape
property.
//Add the new entity type to the knowledge graph data model
KnowledgeGraphService
.executeAddNamedTypes(kg, {
newEntityTypes: [newEntityType],
})
.then((response) => {
console.log("Response from add named types: ", response);
//set the working knowledge graph to be the newly updated graph
kg = response.updatedKnowledgeGraph;
updateUI(newEntityType.name);
})
.catch((e) => {
//catch errors and provide user feedback
});
Next add a new relationship type by to the graph. Relationships include additional information about the origin entity types and destination entity types for the relationship type.
//define the new relationship type
const newRelationshipType = {
type: "relationship",
name: "MyNewRelationshipType" + Math.floor(Math.random() * 100) + 1,
properties: [
{
name: "nameProp",
fieldType: "esriFieldTypeString",
role: "esriGraphPropertyRegular",
},
],
endPoints: [
{
originEntityType: "Observation",
destinationEntityType: "User",
},
],
};
Add the new relationship type to the knowledge graph data model using the same execute
.
You can add entity types and relationship types to the data model in the same execute
call as separate lists.
The knowledge graph data model will be updated with a new relationship type that contains a name
property.
The origin and destination entity types for this relationship are set as Observation
and User
.
//add it to the knowledge graph data model
KnowledgeGraphService
.executeAddNamedTypes(kg, {
newRelationshipTypes: [newRelationshipType],
})
.then((response) => {
//set the working knowledge graph to be the newly updated graph
//with the new type and update the UI.
kg = response.updatedKnowledgeGraph;
updateUI(newRelationshipType.name);
})
.catch((e) => {
//catch errors and provide user feedback
});
4. Add a graph property to a named type
Graph properties can be added to entity types and relationship types after they are created. Graph properties are the properties
that all instances of an entity type or relationship type will have. For example, the User
entity type has a graph property username
so all
User
entities will have a username
property. To add a graph property,
click the plus under the type and provide a name for the graph property. All properties added to an existing
named type must have the nullable
property set to true
so that existing records of that type can be updated with the new property.
See GraphProperty for more information on the properties you can set for a graph property.
/**
* Add a GraphProperty to an existing entity type or relationship type
*/
const addPropertyToType = (namedType, name) => {
KnowledgeGraphService
.executeAddGraphProperties(kg, namedType, [
{//autocasts as a new GraphProperty
name: name,
fieldType: "esriFieldTypeString",
role: "esriGraphPropertyRegular",
nullable: true, //when you are adding a property to an existing type you must set nullable to true
}
])
.then((response) => {
kg = response.updatedKnowledgeGraph;
updateUI(namedType, name);
})
.catch((e) => {
//catch errors and provide user feedback
});
}