Our Web API returns Ember Data compatible objects with relationships defined like so:
{containers: [
{
id: "12345678",
name: "name",
items: [1, 2]
}
],
items: [
{
id: 1
name: "item 1"
},
{
id: 2
name: "item 2"
}
]
}
Notice that the item IDs are included in the container object, and that each related item is sideloaded in the same call. Is there any way to set up this kind of relationship with RestKit?
Related
I set up a basic model and controller connected to mysql database. Everything looks good and is working.
My Definition Model looks like this.
import { Entity, model, property } from '#loopback/repository';
#model({
settings: {
mysql: {
table: 'definition'
}
}
})
export class Definition extends Entity {
#property({
type: 'number',
id: true,
generated: true,
forceId: true,
required: false,
description: 'The unique identifier for a definition',
})
id: number;
#property({
type: 'string',
required: true,
})
name: string;
#property({
type: 'string',
required: true,
})
process_id: string;
constructor(data?: Partial<Definition>) {
super(data);
}
}
export interface DefinitionRelations {
// describe navigational properties here
}
export type DefinitionWithRelations = Definition & DefinitionRelations;
When I have it up and running and click on the explorer to test it out.
I click on "Try it out" for get /definitions and the only editable field that gets enabled is the filter field.
It is repopulated with a value like this...
{
"where": {},
"fields": {
"id": true,
"name": true,
"process_id": true
},
"offset": 0,
"limit": 0,
"skip": 0,
"order": [
"string"
]
}
I have to clear that to get it to work which is fine. When I run it with no filter it returns these results.
[
{
"id": 10,
"name": "Place Manual Payoff Order Process Config",
"process_id": "Process_PlaceManualPayoffOrderProcessConfig"
},
{
"id": 11,
"name": "test",
"process_id": "Test"
},
{
"id": 12,
"name": "test2",
"process_id": "test2"
}
]
I am trying to use the filter expression to only return ones with a specific process_id field. So I change the filter to look like this.
{
"where": {"process_id": "test2"}
}
And it still returns the same results.
[
{
"id": 10,
"name": "Place Manual Payoff Order Process Config",
"process_id": "Process_PlaceManualPayoffOrderProcessConfig"
},
{
"id": 11,
"name": "test",
"process_id": "Test"
},
{
"id": 12,
"name": "test2",
"process_id": "test2"
}
]
Do filters currently work in Loopback 4 or am I using them incorrectly?
EDIT: if I post the filters in the URL string they work. It seems as though the openapi ui isn't generating that part of the filter Into the URL string.
It seems as though the openapi ui isn't generating that part of the filter Into the URL string.
Yes, this a precise description.
OpenAPI Spec version 3.x does not specify how to serialize deeply-nested values to URL queries and swagger-js, the library powering swagger-ui (which powers LoopBack's REST API Explorer), silently ignores such values.
The issue has been reported and is being discussed here:
swagger-api/swagger-js#1385
OAI/OpenAPI-Specification#1706
Here are my body's model
{
"specs": [
{
"name": "test",
"id": "7dcf2db8-858e-4c00-bbde-e0c5c734770c"
}
]
}
trying to convert this last for uri module
body_format: json
body:
specs:
id: "id"
name: "name"
how to convert this last correctly ? switch to raw ?
specs is an array of dicts so the right syntax is:
body_format: json
body:
specs:
- id: "id"
name: "name"
AppSync appears to be loading the incorrect resolver template for some fields of nested objects. Also, it appears to only happen when the nested object has a field with the same name as a field on the parent object.
I've included an example below because I think that might be the best way to explain the issue. As you can see, the id fields for the nested objects are not being resolved correctly.
Each type, Task, User, List, and Tag, have a resolver for their id field because the data for each has a prefix on the id field. For example, Task.id has a resolver that returns $context.source.task_id and User.id has a resolver that returns $context.source.user_id. Same for List and Tag.
What appears to be happening is AppSync is loading the id resolver template for the parent type. You can see that this is the case for task.owner.id, where owner is a User but the id gets resolved as "$context.source.task_id". Same for task.list.id where list is a List. Again we can see this for task.tags[0].owner.id. owner is once again a User except this time the parent is a Tag so task.tags[0].owner.id is resolved as "$context.source.tag_id". These three example show that the problem is not with a particular type since User and List are behaving the same when they are nested in a Task. Also, we can see that the issue is not with Task since User is behaving similarly when nested in a Tag. Lastly, we can see that task.tags[1].owner.id actually behaves correctly. This indicates that the issue only presents itself on first execution.
At this point I strongly suspect this is a bug with AppSync however, I'm not 100% on that. Has anyone else experienced this issue? Am I doing something terribly wrong?
Example
Query
{
task(id: "task-123") {
id,
title,
owner {
id,
username,
},
list {
id,
name,
},
tags {
id,
name,
owner {
id,
username,
},
},
},
}
Result
{
"data": {
"task": {
"id": "task-123",
"title": "First Task",
"owner": {
"id": "$context.source.task_id",
"username": "tom"
},
"list": {
"id": "$context.source.task_id",
"name": "Inbox"
},
"tags": [
{
"id": "tag-123",
"name": "one",
"owner": {
"id": "$context.source.tag_id",
"username": "tom"
}
},
{
"id": "tag-234",
"name": "two",
"owner": {
"id": "user-123",
"username": "tom"
}
}
]
}
}
}
Task Schema
type Task {
id: ID!
title: String!
owner: User!
list: List
tags: [Tag]
}
User Schema
type User {
id: ID!
username: String!
}
List Schema
type List {
id: ID!
name: String!
}
Tag Schema
type Tag {
id: ID!
name: String!
owner: User!
}
Task Data
{
task_id: "task-123",
title: "First Task",
owner_id: "user-123",
list_id: "list-123",
tags: [
"tag-123",
"tag-234"
]
}
User Data
{
user_id: "user-123",
username: "tom"
}
List Data
{
list_id: "list-123",
name: "Inbox"
}
Tag Data
{
tag_id: "tag-123",
name: "one",
owner_id: "user-123"
}
{
tag_id: "tag-234",
name: "two",
owner_id: "user-123"
}
Example id resolver (User)
Request Mapping Template
{
"version": "2017-02-28",
"payload": "$context.source.user_id"
}
Response Mapping Template
$util.toJson($context.result)
The id resolvers for the other types are very similar
It may also be worth noting that I created different None Data Sources for each type, Task, User, List, and Tag. The id resolver for each type is using their respective None Data Source.
im using Ember Data 1.13.3. and i want to convert my old JSON format to new JSONAPI format using normalizeResponse in JSONAPISerializer.
for example i have my json coming from web service like
{
user: { id: 1, name: 'wecc', accounts: [1, 2] },
accounts: [
{ id: 1, email: 'wecc#sweden.se' },
{ id: 2, email: 'wecc#greece.gr' }
]
}
now in my JSONAPISerializer how can i get the JSONAPI format out of my old json. im getting old format. but i want that format converted automatically into JSONAPI. like below one
{
data: {
id: '1',
type: 'user',
attributes: {
name: 'wecc'
},
relationships: {
accounts: {
data: [
{ id: '1', type: 'account' },
{ id: '2', type: 'account' }
]
}
}
},
included: [{
id: '1',
type: 'account',
attributes: {
email: 'wecc#sweden.se'
}
}, {
id: '2',
type: 'account',
attributes: {
email: 'wecc#greece.gr'
}
}]
}
i found some help from ember itself.
http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_internal-format-change-to-json-api
they recommand to use normalizeResponse
It won't happen automatically. If you are also in control of your REST API I'd recommend normalizing the data on the server itself. Otherwise as you suggested it will have to happen within normalizeResponse, but with custom code written to match your data format.
Another solution is to keep using the RESTSerializer for now and wait until the JSON API specification gets a bit more popular. Tools will likely be released for most server frameworks to provide standard JSON API payloads in the coming months.
I create an WebSQL database on my Sencha Touch project. An table named Product have 100 record.
I config my Store as
Ext
.define('Mark.store.Product', {
extend: 'Ext.data.Store',
requires: [
'Mark.model.Product',
'Ext.data.proxy.Sql'
],
config: {
autoLoad: true,
autoSync: true,
model: 'Mark.model.Product',
storeId: 'Product',
proxy: {
type: 'sql',
database: 'osadb'
}
}
});
By default it will load 25 record from the Product table to the product List on View (listpaging plugin added)
And this is my list configuration:
{
xtype: 'list',
docked: 'bottom',
height: '100%',
hidden: false,
itemId: 'productList',
emptyText: 'Data not found',
itemTpl: [
'<div style="font-size:15px">{METRO_DESC}</div>',
'<div style="font-size:13px" class="mark-list-item-secondary">{Brand} {PACKSIZE}</div>'
],
scrollToTopOnRefresh: false,
store: 'Product',
useSimpleItems: false,
plugins: [
{
autoPaging: true,
type: 'listpaging'
}
]
}
When i run the project. It have load 25 record to screen, and it show "No more records" at the bottom
.
But the table Product in Database have 100 record. The Store just load 25, why it's not show the "Load More" button instead of "No more record"