You can use the Apollo GraphQL Library in your iOS / Swift Applications:
Node-RED
You can use a function node in Node-RED and create a custom GraphlQL query that forwards data directly into Node-RED as a parsed JSON-Object.
// Datacake API Token and Workspace
var token = "123456mytoken123456";
var workspace = "1234myworkspace1234";
// GraphQL API URL
msg.url = "https://api.datacake.co/graphql";
// GraphQL Header
msg.headers = {
"Authorization": "Token "+token,
"Content-Type": "application/json"
};
// GraphQL Query
var query = `query {
allDevices(inWorkspace:${workspace}) {
id
serialNumber
verboseName
currentMeasurements(allActiveFields: true) {
field {
fieldName
verboseFieldName
}
value
}
}
}`;
msg.payload = {"query": query};
msg.body = {"query": query};
return msg;
Node-RED Flow Export
Copy the following Node-RED Flow of a working Datacake GraphQL Example and paste this into your Node-RED using "Import" function.
Workspaces
List of Workspaces
query {
allWorkspaces {
id
name
}
}
List of Devices
query {
allDevices(inWorkspace:"f6331019-8978-4a86-b1bc-3522546f67d5") {
id
verboseName
}
}
Current Measurements
All Devices in Workspace
You can use the currentMeasurements option to have all the last recorded measurements of one or more devices returned.
Use the allActiveFields option as follows to return only those fields that are active in the database.
query {
allDevices(inWorkspace:"f6331019-8978-4a86-b1bc-3522546f67d5") {
currentMeasurements(allActiveFields: true) {
value
modified
field {
verboseFieldName
fieldName
}
}
}
}
Specific Fields only
query {
allDevices(inWorkspace:"f6331019-8978-4a86-b1bc-3522546f67d5") {
currentMeasurements(fieldNames:["BATTERY"]) {
value
modified
field {
verboseFieldName
fieldName
}
}
}
}
Single Fields only
Instead of providing an Array of Field Identifiers you can use the currentMeasurement Option to Query a specific field only.
query {
allDevices(inWorkspace:"f6331019-8978-4a86-b1bc-3522546f67d5") {
currentMeasurement(fieldName:"BATTERY") {
value
modified
field {
verboseFieldName
fieldName
}
}
}
}
Specific Device
The above examples are using the allDevices Option to query all devices in a given Workspace. If you just want to access data from a specific device only, you can use the device Option.