What is the correct format for `child-resource-references` responses? - onem2m

TS-0004 Table 7.5.2-2 states that the R/6 (retrieve child-resource-references) call (?fu=1&rcn=6) should return an m2m:resourceRefList. Is this correct? At least two open-source implementations i have seen return m2m:URIList for this query.
Is there anywhere listed examples that show a more complete list of responses for combinations of query parameters?

You are right. fu=1 (discovery request) and rcn=6 should return a m2m:resourceRefList. Such as:
{
"m2m:ch": [
{
"nm": "aResource",
"typ": 99,
"val": "cse-in/aResource"
},
{
"nm": "anotherResource",
"typ": 99,
"val": "cse-in/anotherResource"
}
]
}
There are a couple of examples in the developer guides: https://www.onem2m.org/developer-guides

Related

How to mention array of object in hasura graphql action type?

How to define the Action type in Hasura graphql(console) for below given API response?
{
"data": [
{
"name": "Jordan Smith",
"id": 101,
"location": "Florida",
"speciality_id": 214
},
{
"name": "Cathy Morphy",
"id": 104,
"location": "london",
"speciality_id": 214
}
],
"count": 2 }
If you have control over what's in your API response, and can change it to just return an array of objects (what's inside data), then something like this should work:
type Query {
doctors(specialty_id: Int, search: String, limit: Int, offset: Int): [Doctor]
}
type Doctor {
name: String
id: Int
location: String
specialty_id: Int
}
If you don't have control over the API response, you'll need another layer (e.g. a serverless function or another server endpoint to request the data and transform the response into the format Hasura Actions can handle).
See also:
https://github.com/hasura/graphql-engine/issues/4806
https://hasura.io/docs/latest/graphql/core/actions/types/index.html#custom-graphql-types

How to group GraphQL query result with individual key as array

I'm using GraphQL with .NET Core. I have query like below. As I'm new in GraphQL.NET, I can't understand how to group individual key as array.
`{
readingQuery{
readingsDBFilter(buildingId: 30, objectId: 1, datafieldId: 1, startTime: "02-05-201812-00-00-AM", endTime: "30-05-201811-59-00-PM"){
value,
unix
}
}
}`
I have Output Like this
`{
"data": {
"readingQuery": {
"readingsDBFilter": [
{
"value": 0.66,
"unix": 1525254180000
},
{
"value": 0.68,
"unix": 1525254240000
}
]
}
}
}`
But, Is it possible to return result like this from query.
`{
"data": {
"readingQuery": {
"readingsDBFilter": [
{
"value":[ 0.66, 0.68],
"unix": [1525254180000, 1525254240000]
}
]
}
}
}`
Looks like you need to group values from different records
I guess you have two option here
1) try to group it on SQL level (maybe better to create dateview)
2) do it on runtime level, in code. from my point of view - it's bad. any grouping in code it's much slower then the same operation in db-level

How to get name/confidence individually from classify_text?

Most of the other methods in the language api, such as analyze_syntax, analyze_sentiment etc, have the ability to return the constituent elements like
sentiment.score
sentiment.magnitude
token.part_of_speech.tag
etc etc etc....
but I have not found a way to return name and confidence in isolation from classify_text. It doesn't look like it's possible but that seems weird. Am missing something? Thanks
The language.documents.classifyText method returns a ClassificationCategory object which contains name and confidence. If you only want one of the fields you can filter by categories/name or categories/confidence. As an example I executed:
POST https://language.googleapis.com/v1/documents:classifyText?fields=categories%2Fname&key={YOUR_API_KEY}
{
"document": {
"content": "this is a test for a StackOverflow question. I get an error because I need more words in the document and I don't know what else to say",
"type": "PLAIN_TEXT"
}
}
Which returns:
{
"categories": [
{
"name": "/Science/Computer Science"
},
{
"name": "/Computers & Electronics/Programming"
},
{
"name": "/Jobs & Education"
}
]
}
Direct link to API explorer for interactive testing of my example (change content, filters, etc.)

Which is the better design for this API response

I'm trying to decide upon the best format of response for my API. I need to return a reports response which provides information on the report itself and the fields contained on it. Fields can be of differing types, so there can be: SelectList; TextArea; Location etc..
They each use different properties, so "SelectList" might use "Value" to store its string value and "Location" might use "ChildItems" to hold "Longitude" "Latitude" etc.
Here's what I mean:
"ReportList": [
{
"Fields": [
{
"Id": {},
"Label": "",
"Value": "",
"FieldType": "",
"FieldBankFieldId": {},
"ChildItems": [
{
"Item": "",
"Value": ""
}
]
}
]
}
The problem with this is I'm expecting the users to know when a value is supposed to be null. So I'm expecting a person looking to extract the value from "Location" to extract it from "ChildItems" and not "Value". The benefit to this however, is it's much easier to query for things than the alternative which is the following:
"ReportList": [
{
"Fields": [
{
"SelectList": [
{
"Id": {},
"Label": "",
"Value": "",
}
]
"Location": [
{
"Id": {},
"Label": "",
"Latitude": "",
"Longitude": "",
"etc": "",
}
]
}
]
}
So this one is a reports list that contains a list of fields which on it contains a list of fieldtype for every fieldtype I have (15 or something like that). This is opposed to just having a list of reports which has a list of fields with a "fieldtype" enum which I think is fairly easy to manipulate.
So the Question: Which format is best for a response? Any alternatives and comments appreciated.
EDIT:
To query all fields by fieldtype in a report and get values with the first way it would go something like this:
foreach(field in fields)
{
switch(field.fieldType){
case FieldType.Location :
var locationValue = field.childitems;
break;
case FieldType.SelectList:
var valueselectlist = field.Value;
break;
}
The second one would be like:
foreach(field in fields)
{
foreach(location in field.Locations)
{
var latitude = location.Latitude;
}
foreach(selectList in field.SelectLists)
{
var value= selectList.Value;
}
}
I think the right answer is the first one. With the switch statement. It makes it easier to query on for things like: Get me the value of the field with the id of this guid. It just means putting it through a big switch statement.
I went with the first one because It's easier to query for the most common use case. I'll expect the client code to put it into their own schema if they want to change it.

How to remove a key from a RethinkDB document?

I'm trying to remove a key from a RethinkDB document.
My approaches (which didn't work):
r.db('db').table('user').replace(function(row){delete row["key"]; return row})
Other approach:
r.db('db').table('user').update({key: null})
This one just sets row.key = null (which looks reasonable).
Examples tested on rethinkdb data explorer through web UI.
Here's the relevant example from the documentation on RethinkDB's website: http://rethinkdb.com/docs/cookbook/python/#removing-a-field-from-a-document
To remove a field from all documents in a table, you need to use replace to update the document to not include the desired field (using without):
r.db('db').table('user').replace(r.row.without('key'))
To remove the field from one specific document in the table:
r.db('db').table('user').get('id').replace(r.row.without('key'))
You can change the selection of documents to update by using any of the selectors in the API (http://rethinkdb.com/api/), e.g. db, table, get, get_all, between, filter.
You can use replace with without:
r.db('db').table('user').replace(r.row.without('key'))
You do not need to use replace to update the entire document.
Here is the relevant documentation: ReQL command: literal
Assume your user document looks like this:
{
"id": 1,
"name": "Alice",
"data": {
"age": 19,
"city": "Dallas",
"job": "Engineer"
}
}
And you want to remove age from the data property. Normally, update will just merge your new data with the old data. r.literal can be used to treat the data object as a single unit.
r.table('users').get(1).update({ data: r.literal({ age: 19, job: 'Engineer' }) }).run(conn, callback)
// Result passed to callback
{
"id": 1,
"name": "Alice",
"data": {
"age": 19,
"job": "Engineer"
}
}
or
r.table('users').get(1).update({ data: { city: r.literal() } }).run(conn, callback)
// Result passed to callback
{
"id": 1,
"name": "Alice",
"data": {
"age": 19,
"job": "Engineer"
}
}

Resources