Modify Apollo Cache Root Query with variable - apollo

I am trying to use cache.modify to change the status and feeling for one of the movies in the following query. I can't figure out what to pass cache.identify() to get this query.
ROOT_QUERY:
searchMovies:{"data":{"term":"hoosiers"}}:
cursor: null
movies:
610b67ac02500b064693f29b:
__typename: "MovieStatus"
movie : {__ref: 'Movie:610b67ac02500b064693f29b'}
status: null
feeling: null
610b67b202500b064694368f: {__typename: 'MovieStatus', movie: {…}, status: null, feeling: null}
610b67c202500b064694edc7: {__typename: 'MovieStatus', movie: {…}, status: null, feeling: null}
610b682d02500b0646999238: {__typename: 'MovieStatus', movie: {…}, status: null, feeling: null}
610b682202500b0646992249: {__typename: 'MovieStatus', movie: {…}, status: null, feeling: null}
610b684602500b06469a9b78: {__typename: 'MovieStatus', movie: {…}, status: null, feeling: null}
[[Prototype]]: Object
totalCount: 6
[[Prototype]]: Object
I tried using cache.readQuery:
const search = cache.readQuery({
query: SEARCH_MOVIES_QUERY,
variables: {
term: searchTerm
}
})
but I get an error: (Invariant Violation: Invariant Violation: 44)

Related

Django index value of array

I am sending an array of arrays a post request through $ajax
ie:
[[1, "25, 25, 25", "pounds", "exercise note 1"],[2, "", "No Weight", "note 2"]]
My ajax:
$.ajax({
type: 'POST',
url: '',
dataType: 'json',
data:{
csrfmiddlewaretoken: csrftoken,
targets:JSON.stringify(targets),
// notes:notes,
// time:time,
// rating:rating
},
success: (res)=>{
console.log(res)
},
error: (error)=>{
console.log(error)
}
})
In django, when I print(request.POST), I get
'targets[0][]':[1, "25, 25, 25", "pounds", "exercise note 1"], 'target[1][0]':[2, "", "No Weight", "note 2"].
I have tried
JSON.stringify([[1, "25, 25, 25", "pounds", "exercise note 1"],[2, "", "No Weight", "note 2"]])
and I get back
'targets': ['[[2,"25, 25, 25","Pounds","note 1"],[1,"","NoWeights","note 2"]]'],
I've also tried:
ts.push(t)
django returns:
'targets[]': ['[2,"25, 25, 25","Pounds","note 1"]', '[1,"","NoWeights","note 2"]
which is what I want. But when I do
targets = request.POST.getlist('targets[])
for target in targets:
print(target[2]) -->I want either "25, 25, 25" or , ""
But all I get is , and when I print(len(target)) the first array returns 34. Why? How do I get the strings? What am I doing wrong? I want to assigned each index in the target array to a varible so I can save to the database
If you send targets as JSON in your request(NOTE: only the targets part is JSON) then you have to decode it when you get it on the server side.
targets = [[1, "25, 25, 25", "pounds", "exercise note 1"],[2, "", "No Weight", "note 2"]];
$.ajax({
type: 'POST',
url: '',
dataType: 'json',
data:{
csrfmiddlewaretoken: csrftoken,
targets:JSON.stringify(targets),
// notes:notes,
// time:time,
// rating:rating
},
success: (res)=>{
console.log(res)
},
error: (error)=>{
console.log(error)
}
}
});
targets_json = request.POST.get('targets')
targets = json.loads(targets_json)
for target in targets:
print(target[2])

How do I create a polymorphic 1:1 relationships wtih Ember Data fixtures?

Page has a polymorphic 1:1 relationship with a model called PageContent. PageContent has two subtypes (TextOnly and Video). I want to be able to able to do a findAll for "page" and get all of the content back. What am I doing wrong?
JSBin
This seems to work: http://jsbin.com/names/1/edit
Only wrong thing I could see is the App.Page.FIXTURES.
It should be:
App.Page.FIXTURES = [
{
id: 1,
title: "Introduction",
pageContent: 1,
pageContentType: "textOnly"
},{
id: 2,
title: "Summary",
pageContent: 1,
pageContentType: "Video"
}
];
or
App.Page.FIXTURES = [
{
id: 1,
title: "Introduction",
pageContent: {
id: 1,
type: "textOnly"
}
},{
id: 2,
title: "Summary",
pageContent: {
id: 1,
type: "Video"
}
}
];

Trying To Do A Simple Add Item To FIXTURE

I have a simple fixture:
App.User.FIXTURES = [
{ userid: 1, name: 'George', email: 'george#gmail.com', bio: 'Lorem Ipsum', created: 'Jan 5, 2015' },
{ userid: 2, name: 'Tom', email: 'tom#hotmail.com', bio: 'Lorem Ipsum 2', created: 'Jan 15, 2015' },
{ userid: 3, name: 'Mary', email: 'mary#aol.com', bio: 'Lorem Ipsum 3', created: 'Jan 25, 2015' }
];
And I have a simple submit: (snippet)
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
App.User.createRecord({ id: 4, userid: 4, name: 'Created person', email: 'sdh', bio: 'my bio', created: '6543456' });
I THINK this is right as I'm not getting an error on createRecord anymore, but now I'm getting an error, any ideas? One more step I'm missing just to shove something into a fixture?
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
Kingpin2k is correct in that calling createRecord on the UserModel itself is an older way of using Ember Data. If you're using the latest version you should call createRecord from the store object.
Here's what it should look like:
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
//Create a new user
var user = this.store.createRecord('user',{
id: 4,
userid: 4,
name: 'Created person',
email: 'sdh',
bio: 'my bio',
created: '6543456'
});
// Saves the new model, but not needed if you're just using FIXTURES
// Making the call shouldn't throw any errors though and is used in the Guide
user.save();
// Now you can find your record in the store
this.store.find('user', 4).then(function(user){
console.info(user);
});
}
}
});
This was tested on:
DEBUG: -------------------------------
DEBUG: Ember : 1.6.0-beta.1+canary.24b19e51
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 2.0.2
DEBUG: -------------------------------
I'd recommend reviewing the "Creating a New Model Instance" portion of the Ember getting started guide as they cover this topic there:
http://emberjs.com/guides/getting-started/creating-a-new-model/

Unassigned relationship delivers id=0 instead of undefined/null

I have a basic question.
I have an item model:
App.Item = DS.Model.extend({
...
user: belongsTo('user')
});
But if I send the JSON:
"user" : ""
it assigns it to the User with the ID of 0. Probably because of Javascript problems to differentiate between an empty string and 0
Does anybody know how to test for an unassigned relationship in a computed property?
Thx!
I'm not seeing the same behavior, would you mind setting up a jsbin?
I'm seeing it attempt to find a record with an empty string. The proper way to do it is to return null.
App.Order.FIXTURES = [
{
id: 1,
cow: "",
name: "Some Order"
}, {
id: 2,
cow: null, // This is the right way to say no element
name: "Some Other Order"
},{
id: 3,
cow: 0,
name: "Some Other Order 3"
}
];
http://emberjs.jsbin.com/AvOYIwE/3/edit

ExtJS 4.1.0 proxy returns update api instead of create

I was working on a code which was about integrating ExtJS 4 and Django. The link is:
https://github.com/diegocmsantos/extjs4-tdc2011-django
It works fine on ExtJS 4.0.0. But when I upgrade to 4.1.0 it's proxy returns update api instead of create.
I have added the 'idProperty' parameter to the Model, but still gives me the same result.
Model class:
Ext.define('TDC2011.model.Contact', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields : [
{ name : "id", type : "int", mapping : "#id" },
{ name : "name", type : "string"},
{ name : "phone", type : "string"},
{ name : "email", type : "string"}]
});
Store Class:
Ext.define('TDC2011.store.Contacts', {
extend: 'Ext.data.Store',
model: 'TDC2011.model.Contact',
autoLoad: true,
pageSize: 35,
autoLoad: {start: 0, limit: 35},
proxy: {
type: 'ajax',
api: {
read : 'contact/view.action',
create : 'contact/create.action/',
update: 'contact/update.action/',
destroy: 'contact/delete.action/'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: false,
root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});
Is there anyone who knows the main cause of problem?