Coreo GraphQL API – Queries
Coreo’s GraphQL API only currently supports 2 types of operation: queries and mutations. Queries operate like GET requests in a REST API, while mutations are equivalent to POST/PATCH/DELETE requests.
GraphQL queries return only the data you specify. To form a query, you must specify fields within fields (also known as nested subfields) until you return only scalars.
Queries are structured like this:
{
projects {
id
name
}
}
This should return a response that looks like this:
{
"data": {
"projects": [
{
"id": 7483,
"name": "My Project"
}
]
}
}
Alternatively you can query a specific project by ID:
{
project(id: 7483) {
id
name
}
}
Resulting in a response of:
{
"data": {
"project": {
"id": 7483,
"name": "My Project"
}
}
}
As shown above it is possible to pass arguments to objects and fields, where available. You can check a field’s arguments in the documentation at https://api.coreo.io/graphql/ (docs are in the top right corner).
Inside the documentation (specifically for queries, looking inside RootQueryType
) you can also view the fields available on a project:
Using this we can instruct our queries to return the specific information we require. For example if we would like to query the project’s records we can construct a query as follows:
{
project(id: 349) {
id
name
records {
id
data
userId
}
}
}
which will return a response in the form of:
{
"data": {
"project": {
"id": 349,
"name": "Habitat Condition",
"records": [
{
"id": 8306791,
"userId": 23203
"data": {
"date_epa0af": "2020-07-10T10:40:55.503Z",
"habitat_type_ls9ml": "u"
}
},
...
]
}
}
}