This file contains example GraphQL queries and mutations for the Sensor API. You can use these in the GraphQL Playground at http://localhost:8000/graphql
query GetSensorTypes {
sensorTypes {
id
name
description
unit
dataType
minValue
maxValue
isActive
}
}query GetLocations {
locations {
id
name
description
parentId
address
city
country
latitude
longitude
}
}query GetSensors {
sensors {
id
deviceId
name
description
manufacturer
model
isActive
isOnline
lastSeen
sensorType {
name
unit
}
location {
name
}
latestReading {
value
timestamp
}
}
}query GetSensorsByLocation($locationId: String!) {
sensors(locationId: $locationId) {
id
deviceId
name
sensorType {
name
unit
}
latestReading {
value
timestamp
}
}
}query GetSensorReadings($sensorId: String!, $limit: Int = 100) {
sensorReadings(sensorId: $sensorId, limit: $limit) {
id
value
timestamp
}
}query GetLatestReadings {
latestReadings {
id
value
timestamp
sensor {
name
deviceId
sensorType {
name
unit
}
location {
name
}
}
}
}query GetSensorByDeviceId($deviceId: String!) {
sensorByDeviceId(deviceId: $deviceId) {
id
name
description
isOnline
lastSeen
sensorType {
name
unit
}
location {
name
address
}
latestReading {
value
timestamp
}
}
}query GetTemperatureSensors($sensorTypeId: String!) {
sensors(sensorTypeId: $sensorTypeId) {
id
deviceId
name
location {
name
}
latestReading {
value
timestamp
}
}
}query GetAlerts($limit: Int = 50) {
alerts(limit: $limit) {
id
alertType
severity
title
message
status
triggeredAt
sensor {
name
deviceId
location {
name
}
}
}
}mutation CreateSensorType {
createSensorType(input: {
name: "CO2 Level"
description: "Carbon dioxide concentration sensor"
unit: "ppm"
dataType: "float"
minValue: 0.0
maxValue: 5000.0
}) {
id
name
unit
}
}mutation CreateLocation {
createLocation(input: {
name: "Laboratory A"
description: "Research laboratory on the 2nd floor"
address: "456 Science Avenue"
city: "Helsinki"
country: "Finland"
latitude: 60.1699
longitude: 24.9384
}) {
id
name
address
}
}mutation CreateSensor($sensorTypeId: String!, $locationId: String!) {
createSensor(input: {
deviceId: "CO2001"
name: "CO2 Sensor - Lab A"
description: "Monitors CO2 levels in Laboratory A"
sensorTypeId: $sensorTypeId
locationId: $locationId
manufacturer: "AirSense Corp"
model: "AS-CO2-100"
firmwareVersion: "v2.1.3"
samplingInterval: 60
}) {
id
deviceId
name
manufacturer
}
}mutation CreateSensorReading($sensorId: String!) {
createSensorReading(input: {
sensorId: $sensorId
value: 23.5
}) {
id
value
timestamp
}
}When using queries with variables, you can provide them like this:
{
"locationId": "your-location-uuid-here"
}{
"sensorId": "your-sensor-uuid-here",
"limit": 50
}{
"deviceId": "TEMP001"
}{
"sensorTypeId": "your-sensor-type-uuid-here",
"locationId": "your-location-uuid-here"
}query GetDashboardData {
sensors(activeOnly: true, onlineOnly: true) {
id
deviceId
name
sensorType {
name
unit
}
location {
name
}
latestReading {
value
timestamp
}
}
alerts(status: "active", limit: 10) {
id
severity
title
triggeredAt
sensor {
name
location {
name
}
}
}
}query GetLocationHierarchy {
locations(activeOnly: true) {
id
name
parentId
sensors {
id
deviceId
sensorType {
name
}
isOnline
latestReading {
value
timestamp
}
}
}
}- Use the GraphQL Playground: Navigate to http://localhost:8000/graphql for an interactive query interface
- Explore the Schema: Use the "Docs" panel in the playground to explore available fields
- Start Simple: Begin with basic queries and gradually add more fields
- Use Variables: For dynamic queries, use GraphQL variables instead of hardcoding values
- Monitor Performance: Large datasets should use pagination (limit parameter)
- Time Filters: Use
startTimeandendTimeparameters for time-range queries