I've got the following JSON payload:
"user": {
"id": 1,
"username": "bla",
"first_name": "bla",
"self": {
"info": "MyInfo",
"website": "MyWebsite"
},
//... some more properties doesn't matter
}
I try to map that nested object self into the user model as well and did the following property mappings:
mapping.addAttributeMappingsFromDictionary(
["id" : "id",
"username" : "username",
"first_name" : "firstname",
"self.info" : "info",
"self.website" : "website"])
Now when I trigger a GET - request everything maps fine instead of the nested properties self.info and self.website. When I do a relationship mapping it works as well but I need a separate model which is a bit ugly for these informations.
I'm using RestKit 0.25
I just encountered that the problem relies to the method [object valueForKeyPath:] which RestKit uses for its mappings. This method returns the object itself when it gets called with self so when I change the JSON keyPath to something different e.g. personal.info it works as expected! I think this has changed in a recent RestKit release because another app using RestKit 0.23.x works with a self keypath.
Related
Has anyone had luck with placing a GraphQL custom type argument as a Postman or Graphql variable? I'm kinda spinning in circles right now, I hope a fresh pair of eyes could point me in the right direction.
What I'm trying to do is to send a mutation request using Postman. The problem I'm having is that the method I'm calling is taking a custom type as an argument. Placing the content of that variable as GraphQL variable or Postman variable is giving me a headache. I can't embedd pictures yet, so here are the links (they are safe).
Schema
This custom type is a JSON-like structure, consisting of two enums and a set of primitive types (strings, ints...). I can screenshot the entire thing but basically that's it: two enums followed by strings, ints...
Custom type definition
What I've tried so far:
Simply hardcoding the request in Postman works but I wish to send multiple requests with varying data
Placing it in a GraphQL variable results in error message
{
"errors": [
{
"message": "Bad request - invalid request body.",
"locations": []
}
],
"data": null
}
Placing the custom type content as a Postman environment variable works, but I'm getting a syntax error (although the request passes...).
Request body is below. Hardcoding it and using a Postman variable produces the same request body, apart from the syntax error.
query: "mutation {
createApplication(request: {
applicationKind: NEW_ISSUANCE,
documentKind: REGULAR_PASSPORT,
personalData: {
timestamp: null,
firstname: "NAME",
lastname: "LASTNAME",
middlename: "MIDDLENAME",
dateOfBirth: "2011-09-28",
citizenshipCountryCode: "USA",
gender: MALE,
personalNumber: "3344",
placeOfBirth: "CHICAGO",
municipalityOfBirth: "SOUTH",
countryCodeOfBirth: "USA"},
addressData:{
street: "WEST",
municipality: "EAST",
place: "CHICAGO",
country: {
code: "USA",
name: null
},
entrance: "б",
flat: "13",
number: "35"}
})
{
__typename
... on AsyncTaskStatus {
taskID
state
payload {
... on ApplicationUpdated {
applicationID
applicationNumber
__typename
}
__typename
}
__typename
}
... on Error {
...errorData
__typename
}
}
}
fragment errorData on Error {
__typename
code
message
}"
Postman variable with a squiggly line
I'm spinning in circles right now. Has anyone had any luck with Postman requests of this kind?
I can post more info, screenshots...just let me know. I'll be watching this topic closely and provide feedback.
Thank you for your time.
please add a the variable in variable section as :
{
"request": {{request}}
}
and then refer this in your query as
$request
Currently making a project in Laravel that uses MapboxGLJS. I've currently got a database server that I'm connected to that contains comments which I need to convert to a GeoJSON FeatureCollection that includes the ID and the spacial data. I've seen an example of the code to do this which I'll provide below but when I try to use said code and try to use the addSource Mapbox method it comes back with Error: Input data is not a valid GeoJSON object..
CommentController.php
...
public function all(){
$comments = Comment::whereNotNull('user_id')->get();
$mapFeatures = array();
$mapFeatures['type'] = 'FeatureCollection';
$mapFeatures['name'] = 'comments';
$mapFeatures['crs'] = array(
'type' => 'name',
'properties' => array(
'name' => 'urn:ogc:def:crs:OGC:1.3:CRS84'
),
);
$mapFeatures['features'] = array();
foreach ($comments as $comment) {
$mapItem = array(
'type' => 'Feature',
'properties' => array(
'id' => $comment->id,
),
'geometry' => $comment->location
);
array_push($mapFeatures['features'], $mapItem);
}
return json_encode($mapFeatures);
}
...
Using Postman I collected the following from the api request:
{
"type": "FeatureCollection",
"name": "comments",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
"id": 143
},
"geometry": "0101000020E6100000E17A14AE47E111C085EB51B81E054A40"
},
...
]
}
Running the data through https://geojsonlint.com/ it comes back with Line 1: old-style crs member is not recommended, this object is equivalent to the default and should be removed. Also stating that geometry was expected as an object but got a string which I assume is to do with the crs property not decoding the geometry correctly.
Is there a different crs that I need in order to get the geometry to be correctly decoded?
I unfortunately cannot change the data on the database to include a lat/long geometry as the current data is being used by another project which relies on it being in this format.
This:
"0101000020E6100000E17A14AE47E111C085EB51B81E054A40"
is not a GeoJSON geometry. I'm not sure exactly what it is. It looks like PostGIS's native format (see here) but I don't know what that is called or how to convert from it outside PostGIS.
A GeoJSON geometry would look like:
{
"type": "LineString",
"coordinates": [[...]]
}
If you have access to the PostGIS queries, you should use the ST_AsGeoJSON function.
This has nothing to do with CRS's - the message is just telling you not to bother adding that crs property, assuming that your data is in EPSG:4326.
Discovered there is a package specifically to fix this issue available here:
https://github.com/mstaack/laravel-postgis
This just needs to be installed and referenced in the Controller that gets the coordinates.
Want to add a transformed object along with other response, I have used following code:
$accessToken = Authorizer::issueAccessToken();
$user = User::where('email', $request->get('username'))->with('profile')->first();
if ($user) {
$accessToken['user'] = $this->response->item($user, new UserTransformer);
}
return $accessToken;
Expected Response:
{
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 31536000,
"data": {
"id": 1,
"email": "xxxxx",
"profile": {
"data": {
"id": 1,
"first_name": "Muhammad",
"last_name": "Shakeel",
}
}
}
}
but not getting transformed object, there must be some better way to add multiple transformed objects with response. Am I missing something?
Edit
Current response returns user object without transformation and if I return only user transformed object like following, it returns correct transformed object:
return $this->response->item($user, new UserTransformer);
As discussed on the issue tracker(https://github.com/dingo/api/issues/743#issuecomment-160514245), jason lewis responded to the ticket with following:
The only way you could do this at the moment would be to reverse that. So you'd return the response item, then add in the access token data, probably as meta data.
So, something like this.
return $this->response->item($user, new UserTransformer)->setMeta($accessToken);
The response will then contain a meta data key which will contain your access token data.
I got it to work using Internal Requests. https://github.com/dingo/api/wiki/Internal-Requests
So what you can do is
Suppose you have a route that fetches transformed user object at api/users/{email_id}?access_token=...
While issuing the access_token you can do the following :
$dispatcher = app('Dingo\Api\Dispatcher');
$array = Authorizer::issueAccessToken();
$array['user'] = $dispatcher->get('api/users/'.$request->get("username").'?access_token='.$array['access_token']);
return $array;
This will return transformed data.
NOTE : You will need to have a route that fetches user data.
You will have to handle cases in /api/users/{email-id} where email-id does not exist.
I have a file modified.json containing JSON documents which contain the following:
{"index":{"_index": "trial", "_type": "trial", "_id":"1"}}
{"clinics" : [{"price": 1048, "city": "Bangalore", "Location": {"lon": 77.38381692924742, "lat": 12.952155989068519}}, {"price": 1048, "city": "Bangalore", "Location": {"lon": 77.38381692924742, "lat": 12.952155989068519}}]
.... And more similar documents. I am running a bulk insert through this command:
curl -s -XPOST 'http://localhost:9200/_bulk' --data-binary #modified.json
Next, through the Sense (Google Chrome) plugin, I am issuing the following request
Server: localhost:9200/trial/trial
PUT _search
{
"mappings": {
"clinics": {
"properties": {
"Location": {"type": "geo_point"}
}
}
}
}
I don't know whether or not this is creating a mapping for the Location fields.
After issuing a search request, like this:
Server: localhost:9200/trial/trial
GET _search
{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "20km",
"Location" : {
"lat" : 12.958487287824958,
"lon" : 77.69648881178146
}
}
}
}
}
}
I am getting an error saying:
failed to find geo_point field [Location]]; }]",
Please help me regarding this. Also, if possible also guide me on how to do faceted search on this data, to show clinics within a range of distance: like between 20 and 30 kilometers
You need to reverse your ordering. PUT your mapping mapping first and then do the bulk insert.
By putting the map before the insert you are letting ES know what the datatype are so that it can index them correctly. ES allows you to add mappings to an existing index but the data that's already there isn't going to get re-indexed automatically. (This is a known issue).
I am making a website that follows John Papa's Code Camper SPA Jumpstart Pluralsight course. My database/entities has the following hierarchy:
Proficiency contains Action(s) and Level(s).
When I delete a "Proficiency", I get the following server side error:
"Object reference not set to an instance of an object."
Looking at the json JObject saveBundle in the BreezeController, I am seeing a mysterious:
"undefined": false,
in every entity. None of my entities have a Boolean in them. Just like in Code Camper, I am adding an "isPartial" in the constructor of each entity as shown in the code below.
var proficiencyConstructor = function () {
this.isPartial = false;
}
metadataStore.registerEntityTypeCtor('Proficiency', proficiencyConstructor, proficiencyInitializer);
function proficiencyInitializer(proficiency) {
var empty = "00000000-0000-0000-0000-000000000000";
if (proficiency.id() === empty) {
proficiency.id(breeze.core.getUuid());
}
};
My gut says the mysterious "undefined":false is the "isPartial" property. According to the documentation, the "Breeze adds the isPartial property to the Entity metadata as an unmapped property. The values of unmapped properties are not transmitted to the service." I am stuck. Anyone recommend things I can do to figure this out?
Thanks,
Dan
Here is a sample from the savebundle
{ "entities":
[
{ "Id": "a0223d7c-35e5-458f-ba83-65ec7ec189fa", "Name": "AST Prof0", "IsEnabled": true, "Description": "AST Prof0", "ProficiencyType": "TBD", "ApplicationId": "7ba4b47f-06a3-4ceb-bca6-de3fd3699bbd", "undefined": false, "entityAspect": { "entityTypeName": "Proficiency:#LobGame.Model", "entityState": "Deleted", "originalValuesMap": { "IsPartial": true }, "autoGeneratedKey": null } },
This is likely due to a bug fix that is now in breeze 1.2.8. This fixed it for me.
From their release notes:
Bug fix for the case where a save involving a delete would fail when
that save also involved a modification to an unmapped property.
http://www.breezejs.com/documentation/download