Skip to main content

GetSchema

Retrieve schema information based on current data.

Requires objects.read permission. No input or output blobs are used.

Parameters​

Parameter

Type / required

Default and behavior

ref

integer / optional

Omitted: inspect the database. When supplied, inspect objects selected earlier in this query and always recompute their schema.

type

string / optional

both; accepts entities, connections, or both.

refresh

Boolean / optional

true requests current schema information. false permits previously computed information, which may omit recent changes. Ignored with ref.

Details​

If no parameters are provided, it returns refreshed schema information about entities and connections. This can be expensive when there is a sizeable amount of metadata.

A ref must identify an earlier Entity or Connection selection in this query. The returned schema describes only those objects. Use a preceding Find command to select a subset.

The response contains status and refreshed: a UTC ISO 8601 timestamp showing when the schema information was computed. Requested entities and connections summaries, when present, contain classes and returned. For entities, returned counts classes. For connections, it counts connection-class/source-class/ destination-class combinations, which can exceed the number of distinct connection class names. Cached responses may describe an earlier database state.

For each class of Entity, the following information is returned as a dictionary:

  • matched: Number of objects that match the search.

  • properties: Mapping of property names for the class. null if no properties are defined.

For each class of Connection, classes contains an array of dictionaries, one for each source/destination class pair. Each dictionary contains:

  • src: Source class of the connection.

  • dst: Destination class of the connection.

  • properties: Mapping of property names for the connection. null if no properties are defined.

  • matched: Number of objects that match the search.

Each property of an Entity or Connection is reported as an object such as {"count": 123, "type": "String"}.

  • count: Number of objects with the property.

  • type: Type for the property. See supported types.

Use GetIndexes and its indexes field to inspect index kinds and parameters.

Errors​

An invalid or undeclared ref, invalid type, or missing permission returns status: -1. Correct the request using the info message. A failed read does not itself change stored graph data. See Responses for envelopes.

Examples​

The following examples use three DocsSchemaPerson entities with name and numeric age properties: Ada (36), Grace (40), and Sam (20). One DocsSchemaKnows connection goes from Ada to Grace and has since: 2020. The queries restrict schema information to these selected objects; unrelated data does not contribute to their counts.

The first query selects people aged at least 30 and returns their schema. The Find command’s count counts selected people; GetSchema’s returned counts their classes. The Find command reports returned: 0 because it requests no entity property list.

[{
"FindEntity": {
"with_class": "DocsSchemaPerson",
"_ref": 1,
"constraints": ["$age", ">=", 30],
"results": {
"count": true
}
}
}, {
"GetSchema": {
"ref": 1
}
}]

Response, with the refreshed timestamp omitted:

[{
"FindEntity": {
"count": 2,
"returned": 0,
"status": 0
}
}, {
"GetSchema": {
"entities": {
"classes": {
"DocsSchemaPerson": {
"matched": 2,
"properties": {
"age": {
"count": 2,
"type": "Number"
},
"name": {
"count": 2,
"type": "String"
}
}
}
},
"returned": 1
},
"status": 0
}
}]

A reference can also select connections. Their schema reports the source and destination classes as well as connection properties:

[{
"FindConnection": {
"with_class": "DocsSchemaKnows",
"_ref": 1,
"results": {
"count": true
}
}
}, {
"GetSchema": {
"ref": 1
}
}]

Response, with the refreshed timestamp omitted:

[{
"FindConnection": {
"count": 1,
"returned": 0,
"status": 0
}
}, {
"GetSchema": {
"connections": {
"classes": {
"DocsSchemaKnows": [{
"dst": "DocsSchemaPerson",
"matched": 1,
"properties": {
"since": {
"count": 1,
"type": "Number"
}
},
"src": "DocsSchemaPerson"
}]
},
"returned": 1
},
"status": 0
}
}]