Meteor/Fibers - How to use Meteor.call callback? - serialization

I have this code, where I call a Meteor method from the client and expect a result in the callback. the results object is a well formed object that I can stringify and print from the server's console.
When I run this code, with a valid results and no error, the callback is not called on the client. However, if I substitute fut.return(results) with fut.return(JSON.parse(JSON.stringify(results))), the callback is called and I get "a string" in the client. Any idea why I can return a string but no object?
Server code (in Meteor.Methods()):
getUserEvents : function(userId,start,end) {
var fut = new Future();
getUserEventsPrivate(userId,start,end,function(err,results){
if(err){
fut.throw(new Meteor.Error( 500, 'Oops, something wrong happened'));
}else{
fut.return(results); // works when fut.return(JSON.parse(JSON.stringify(results)));
}
});
return fut.wait();
}
Client:
Meteor.call('getUserEvents',Meteor.user()._id, startStr, endStr,function(err,results){
console.log(results);
});
EDIT
here is the Json I'm trying to pass as 'results':
[
{
"title": "ResponsiveMTL #1",
"start": "2015-10-13T21:30:00.000Z",
"end": "2015-10-14T00:30:00.000Z"
},
{
"title": "Meteor Global Distributed Hackathon",
"start": "2015-10-10T15:00:00.000Z",
"end": "2015-10-11T15:00:00.000Z"
},
{
"title": "retenues a la source",
"start": "2015-10-08T19:25:00.275Z",
"end": "2015-10-08T19:25:00.275Z"
},
{
"title": "Salsa",
"start": "2015-09-19T22:00:00.000Z",
"end": "2015-09-19T23:00:00.000Z"
},
{
"title": "Salsa",
"start": "2015-10-09T22:00:00.000Z",
"end": "2015-10-09T23:00:00.000Z"
}
]

It is entirely possible to return an object this way.
Your object is probably not EJSON-serializable out of the box, although it is hard to tell without actually looking at a sample of it.
If, for example, your objects contain circular references, EJSON will silently fail and your callback won't be called. It is unlikely that this is the case, as you are able to get JSON to serialize it.
You can try to find the offending properties and modify them, but it might be a good idea to register it as a custom type with EJSON.
http://docs.meteor.com/#/full/ejson_add_type
Anyway, it would be interesting to see your actual objects and be able to tell more.
What version of Meteor are you using?

Related

Where do I store GraphQL errors

Basically what the title asks. As far as I know, GraphQL responses are structured as follows:
{
"data": { ... },
"errors":
{
"message": "This message describes what happened",
"path": [
"somePath",
"inGraphQLQuery"
],
"locations": [
{
"line": 2,
"column": 3
}
]
}
]
}
And that works for simple errors. But what if my error is more complicated than just a message? For example, I have mutation that changes some fields of user, such as username, email, password, etc. That mutation might result in error if user-provided data for any field is invalid. But what do I do if validation for multiple fields fails? Ideal way in my opinion to show that to user would be to send structure like this
[
{
"field": "username",
"details": "Username must contain only latin letters and digits"
},
{
"field": "email",
"details": "Email address must contain '#'"
}
{
"field": "password",
"details": "Password must contain at least 8 characters"
}
]
But to my knowledge, there's no way to send this in errors section. So I tend to put this into data section of response and specify that user will receive either User or FieldValidationError.
So, to sum it up, there are some structures that I can't fit into errors, so (for consistency) it seems logical to put every error into data. And by doing so, errors section becomes redundant, since it isn't used for errors at all. What am I getting wrong?

JMeter - save assertion results as a variable

In JMeter I have an automation test plan with several assertions. In my assertion result listener I can see the result off all assertions in a handy overview. So far so good.
At the end of the test plan, I'm calling JIRA to post a new issue with the test results. I want the description of that issue to contain the overview from the assertion result listener.
How can I define the assertion results as a variable, so that I can reference them later in my JIRA call?
How can I map this view to a variable?
My JIRA call should look like this:
POST /rest/api/2/issue
{
"fields": {
"project":
{
"key": "Blah"
},
"assignee": {
"name": "Joe"
},
"priority": {
"name": "Major"
},
"summary": "Jmeter Test Result",
"description": "${assertionresults}",
"issuetype": {
"name": "Test Execution"
}
}
You can add after the Sampler with the assertion:
Test Action and inside it a JSR223 PreProcessor and write the following code using AssertionResult.getFailureMessage method:
vars.put("assertionresults", prev.getAssertionResults()[0].getFailureMessage());
It will save in assertionresults variable the first assertion message.

Validating correctness of $ref in json schema

The requirement is to validate given json schema that there are no dangling $ref pointing to the definitions within the file.
{
"$schema": "http://json-schema.org/draft-6/schema#",
"definitions": {
"date": {
"type": "string",
"pattern": "^(0?[1-9]|[12][0-9]|3[01])\\-(0?[1-9]|1[012])\\-\\d{4}$"
},
},
"properties": {
"my_date": {"$ref": "#/definitions/dat"}
}
}
Here, there is a typo in the reference (dat instead of date). I want to catch such instances rather than having a run time failure.
Library being used: https://github.com/java-json-tools/json-schema-validator
You could validate that the use of $ref resolves by digesting the JSON, recursivly extracting the value of $ref, splitting on slash, and checking the path exists.
This COULD get more complicated as you might have external references which target URLs.
I can't give you any code as I don't know JAVA. It doesn't seem like what you want is specifically available using that library.

How do I create an event using the SocialTables API?

I'm trying to use the /4.0/legacyvm3/teams/{team}/events endpoint to create an event. I'm running into some trouble with spaces.
I used the /4.0/legacyvm3/teams/{team}/venues endpoint to get a list of venues. I chose one to include in the spaces section and posted this:
{
"name": "Event via API Test 04",
"category": "athletic event",
"public": true,
"attendee_management": true,
"start_time": "2017-04-05T16:13:54.217Z",
"end_time": "2017-04-05T16:13:54.217Z",
"uses_metric": false,
"venue_mapper_version": 0,
"spaces": [
{
"venue_id": 128379,
"name": "Snurrrggggg"
}
]
}
The endpoint returns a 400 code and this error:
{
"code": 400,
"message": "Cannot read property 'toLowerCase' of undefined"
}
I tried including the wizard section, but each time it would return this error:
{
"message": "Access Denied to this feature"
}
After some experimentation, this body succeeded:
{
"name": "Event via API Test 03",
"category": "athletic event",
"public": true,
"attendee_management": true,
"start_time": "2017-04-05T16:13:54.217Z",
"end_time": "2017-04-05T16:13:54.217Z",
"uses_metric": false,
"venue_mapper_version": 0,
"spaces": [
{
"name": "Fake News Room"
}
]
}
But the application itself would not display the diagram, and the newly created room did not show up in my list of venues. Perhaps it did not assign permissions to it?
In any case, I don't actually want to create a new venue/space. I want to pass in an existing venue/space. How do I do that?
The short answer is to create a working diagram in 4.0 you will need to POST some data to the /4.0/diagrams endpoint.
The room you create doesn't map to the same concept as venues. When you create an event as you did, it creates a new space entity. The spaces endpoints can return information on those.

How to get recent folders via microsoft graph REST API

I want to fetch my recent folders via the Microsoft Graph REST API.
This API contains the following:
GET https://graph.microsoft.com/v1.0/me/drive/recent
According to the references the result should look like this:
{
"value": [
{
"id": "1312abc!1231",
"remoteItem":
{
"id": "1991210caf!192",
"name": "March Proposal.docx",
"file": { },
"size": 19121,
"parentReference": {
"driveId": "1991210caf",
"id": "1991210caf!104"
}
}
},
{
"id": "1312def!9943",
"name": "Vacation.jpg",
"file": { },
"size": 37810,
"parentReference": {
"driveId": "1312def",
"id": "1312def!123"
}
}
]
}
If the results was like this I could get the parent folder by using the driveId and id of the parentReference but in my results I only get the driveId. This causes the need to do one extra call to graph to fetch the folder.
This means I need 3 calls to the graph API to fetch a recent folder.
My question is if there is a way to also fetch the id or the parentReference so I only need two calls or if there even is an easier way for fetching recent folders?
Thanks in advance!
Sadly the answer is no. 'Recents' feature is pretty bare. They could extend it and provide more flexibility.
If this is critical for you, you can always create a request at:
https://officespdev.uservoice.com/