falcor
A JavaScript library for efficient data fetching
Falcor: One Model Everywhere a javascript library for efficient data fetching.
If I use the example in the README on netflix/falcor, this works:
return {path:['greeting'], value: 'Hello World'};
But if I try to change the value to an object:
return {path:['greeting'], value: {hello: 'Hello World'}};
It doesn't seem to work. I'm probably doing something obviously wrong, but I wanted to get some clarification.
Source: (StackOverflow)
What is the suggested approach for updating an objects value in an array, bearing in mind the array may have been reordered?
I'm wondering how dangerous using index based paths is, when an array could have possibly changed via a deletion, or reorder.
Would it be better to use objects instead, I wonder.
Source: (StackOverflow)
When using setValue() on a local Falcor model, it works as expected, but when the model is moved to the server, a '500 (Internal Server Error)' occurs.
The example below works properly (script runs in browser)
var $ref = falcor.Model.ref;
var model = new falcor.Model({
cache: {
productsById: {
1: {
name: "Product ABC",
otherAdd: "something 1"
},
2: {
name: "Product 123",
otherAdd: "something 2"
},
},
_view: [ $ref('productsById[1]') ],
_cart: []
}
});
model.
getValue("_view[0].name").
then(function(response1) {
console.log( response1 );
model.
setValue("_view[0].name", "Another book").
subscribe(function(response2){
console.log( response2 );
});
});
But when changing this setup to a remote Falcor model it fails. (script runs in browser)
var $ref = falcor.Model.ref;
var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json') });
model.
getValue("_view[0].name"). // <-- works fine
then(function(response1) {
console.log( response1 );
model.
setValue("_view[0].name", "Another book"). // <-- fails
subscribe(function(response2){ // <-- fails on both subscribe() and then()
console.log( response2 );
});
});
With the following node script (script runs on server):
var express = require('express');
var app = express();
var falcor = require('falcor');
var falcorExpress = require('falcor-express');
var $ref = falcor.Model.ref;
function example(){
return {
cache: {
productsById: {
1: {
name: "Product ABC",
otherAdd: "something 1"
},
2: {
name: "Product 123",
otherAdd: "something 2"
},
},
_view: [ $ref('productsById[1]') ],
_cart: []
}
}
}
app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) {
return new falcor.
Model( example() ).
asDataSource();
}));
app.use(express.static(__dirname + '/'));
var server = app.listen(8080);
Error message in console (when setValue()
is called):
POST http://localhost:8080/model.json 500 (Internal Server Error)
requestObserver @ falcor.browser.js:9294145.Observable.create.o.subscribe @ falcor.browser.js:9186_subscribe @ falcor.browser.js:2830182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256182.TapObservable.subscribeCore @ falcor.browser.js:16424tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:14304subscribe @ falcor.browser.js:14318182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256182.observableProto.materialize @ falcor.browser.js:16605tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:17513s @ falcor.browser.js:17530182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256182.MapObservable.subscribeCore @ falcor.browser.js:17073tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:14304subscribe @ falcor.browser.js:14318182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256182.MergeAllObservable.subscribeCore @ falcor.browser.js:15858tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:14304subscribe @ falcor.browser.js:14318182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256(anonymous function) @ falcor.browser.js:15419182.Rx.AnonymousObserver.AnonymousObserver.error @ falcor.browser.js:14066182.Rx.internals.AbstractObserver.AbstractObserver.onError @ falcor.browser.js:14000subscribeToSetResponse @ falcor.browser.js:4133182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256(anonymous function) @ falcor.browser.js:15409tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:17513s @ falcor.browser.js:17530182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:1425661.SetResponse.invokeSourceRequest @ falcor.browser.js:4031182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256182.observableProto.finally.observableProto.ensure @ falcor.browser.js:16522tryCatcher @ falcor.browser.js:12847setDisposable @ falcor.browser.js:17513182.ScheduledItem.invokeCore @ falcor.browser.js:13209182.ScheduledItem.invoke @ falcor.browser.js:13197runTrampoline @ falcor.browser.js:13517tryCatcher @ falcor.browser.js:12847scheduleNow @ falcor.browser.js:13528182.Rx.Scheduler.schedulerProto.scheduleWithState @ falcor.browser.js:13250s @ falcor.browser.js:17528182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:1425658.IdempotentResponse.ensureCollect @ falcor.browser.js:3696182.Rx.Observable.observableProto.subscribe.observableProto.forEach @ falcor.browser.js:14256subscribeToResponse @ falcor.browser.js:3956subscribe @ falcor.browser.js:3903(anonymous function) @ test.html:34
test.html:35 Error: Response code 500
at _handleXhrError (http://netflix.github.io/falcor/build/falcor.browser.js:9316:19)
at onXhrLoad (http://netflix.github.io/falcor/build/falcor.browser.js:9366:14)
at XMLHttpRequest.onreadystatechange (http://netflix.github.io/falcor/build/falcor.browser.js:9280:13)
Source: (StackOverflow)
GraphQL consists of a type system, query language and execution
semantics, static validation, and type introspection, each outlined
below. To guide you through each of these components, we've written an
example designed to illustrate the various pieces of GraphQL.
- https://github.com/facebook/graphql
Falcor lets you represent all your remote data sources as a single
domain model via a virtual JSON graph. You code the same way no matter
where the data is, whether in memory on the client or over the network
on the server.
- http://netflix.github.io/falcor/
What is the difference between Falcor and GraphQL (in the context of Relay)?
Source: (StackOverflow)
I'm experimenting with using Falcor to front the Guild Wars 2 API and want to use it to show game item details. I'm especially interested in building a router that can use multiple datasources to combine the results of different APIs.
The catch is, Item IDs in Guild Wars 2 aren't contiguous. Here's an example:
[
1,
2,
6,
11,
24,
56,
...
]
So I can't just write paths on the client like items[100..120].name
because there's almost certainly going to be a bunch of holes in that list.
I've tried adding a route to my router so I can just request items
, but that sends it into an infinite loop on the client. You can see that attempt on GitHub.
Any pointers on the correct way to structure this? As I think about it more maybe I want item.id
instead?
Source: (StackOverflow)
I'm continuing my experiments with falcor and enjoying most of it, but I'm noticing something concerning.
I'm assembling my JSONGraph from multiple disparate APIs, exactly what falcor-router
is intended to do. However I can't seem to find a way to cleanly provide a catch-all for fields that don't need special handling w/o blowing up any routes that do need to do special handling.
My routes look something like the following:
items[{integers:ids}].name
items[{integers:ids}][{keys:fields}]
No matter the order I declare the routes in the generic one always wins. Is there a better way to avoid this than the full-nuclear option of structuring my routes like this?
items[{integers:ids}].name
items[{integers:ids}]['fooga', 'wooga', 'booga', 'tooga', ... ]
That seems very brittle, if the data coming from the backing server changes I have to update not only my application code but my router as well. It also becomes a real mess if you have deeply nested objects as the number of permutations climb in a hurry.
Source: (StackOverflow)
Can I use falcorjs for building the social network graph? I think to have all data stored in the MySQL database and build the middleware for retrieving data from database and displaying it in nice format. Can I use falcorjs for it?
My main idea is to calculate, find and give a suggestion to add that known/unknown user to the own group of known contacts.
Source: (StackOverflow)
Back in May the Falcor twitter account posted:
@professorStats no. In fact I think that's the major hole at the moment, with Node, Ruby, Python, and PHP all in progress. Interested?
Referring to progress on a server side library for .net
Now that the Falcor developer preview has been made public, what is the plan for these server side libraries? Where can we find more information about them?
Source: (StackOverflow)
Given the following Router class running on the server:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
And the following path query in the browser (I am using the falcor-http-datasource):
model.get('petList[0..2].name');
I get the correct data of:
{
"jsonGraph": {
"petList": {
"0":{"name":"Shows of Artists I've been to before",
"1":{"name":"Shows of artists my friends have been to before",
"2":{"name":"Highly rated artists"}
}
}
}
My question is, on the server, is a way for me to get access to the actual results that falcor sends over the wire back to the browser in response to this get route request?
My use case is that I want to log out two pieces of data together:
- The pathSet that the route gets passed.
- The json result that falcor sends back over the wire.
I was thinking it might look something like this:
var PetsRouterBase = Router.createClass([{
route: 'petList[{integers:indices}].name',
done: function(pathSet, results) {
// Log out the result of the lookup
console.log(pathSet, results);
},
get: function(pathSet) {
return [
{
path: ['petList', 0, 'name'],
value: 'Pets I have now'
},
{
path: ['petList', 1, 'name'],
value: 'Pets I once had'
},
{
path: ['petList', 2, 'name'],
value: 'Pets my friends have'
}
];
}
}]);
Just to be clear. I know I can get the results in the client but I want to pipe them elsewhere on the server.
Source: (StackOverflow)