Skip to main content

GraphQL Queries

To query data, we are supporting query data with GraphQL. More information about GraphQL can be found in the official page.

GraphQL allows us to query only the data we need, which helps partners easier to read the data.

Refer to guppy to know which type of queries we currently support.

You can switch between Graph Model and Flat Model – each using different databases (Postgres and Elastisearch). The “Docs” button can be pressed to see documentation of the queryable nodes and properties.

alt text

For example, typing the name of a node, “sample”, into the “Search Schema” search-box in the Graph Model, and clicking the “Query.sample” option will display all the properties that can be queried for that node.

alt text

For example, query this:

{
subject {
subject_id
submitter_id
}
}

will return:

alt text

Or if we want to query "count" data with the information aboutkey and termsFields. The query will be like:

query ($filter: JSON, $nestedAggFields: JSON) {
_aggregation {
subject(filter: $filter, filterSelf: false, nestedAggFields: $nestedAggFields, accessibility: all) {
original_area {
histogram {
key
count
missingFields {
field
count
}
termsFields {
field
terms {
key
count
}
}
}
}
}
}
}

with query variable is $filter and $nestedAggFields are like:

{"filter":{"AND":[]},"nestedAggFields":{"termsFields":["gender"]}}

The result will be shown accordingly.

{
"data": {
"_aggregation": {
"subject": {
"original_area": {
"histogram": [
{
"key": "Ha Noi",
"count": 110,
"missingFields": null,
"termsFields": [
{
"field": "gender",
"terms": [
{
"key": "female",
"count": 73
},
{
"key": "male",
"count": 37
}
]
}
]
},
{
"key": "Binh Thuan",
"count": 4,
"missingFields": null,
"termsFields": [
{
"field": "gender",
"terms": [
{
"key": "male",
"count": 3
},
{
"key": "female",
"count": 1
}
]
}
]
},
{
"key": "Bac Kan",
"count": 1,
"missingFields": null,
"termsFields": [
{
"field": "gender",
"terms": [
{
"key": "male",
"count": 1
}
]
}
]
}
]
}
}
}
}
}