I wanted to bring up a discussion/proposal/feature request. Looking at Netflix’s Falcor and Facebook’s Graphql, it’s very apparent that these were thought through with the front-end in mind as the consumer.
The current data fetching in Meteor is good but what would make it great is the ability to just write what JSON data we want declaratively. Meteor should just handle getting it for the template.
This is going to be exacerbated once we get SQL support. I mean who really wants to write SQL on the front-end to fetch data??
The back-end can also be declarative. Specify what a user is allowed to fetch and deny everything else (this could help solve the lack of a schema). Our publication is already the same concept of a custom endpoint, usually per resource (user, posts, comments).
Both Falcor and GraphQL are platform/DB agnostic so I think these ideas can be used with Meteor fairly easily. If we can bake this (or something similar) into core it would make it much easier to be the consumer. How nice would it be to do a meteor create myapp
and meteor add graphql
and be done?!?
If interested checkout these videos:
Exploring GraphQL at react-europe 2015
Netflix JavaScript Talks - Falcor
Here’s a sample request and response with GraphQL syntax:
Template.post.queryData({
user(_id: '1234') {
_id,
name,
isViewerFriend,
profilePicture(size: 50) {
uri,
width,
height
}
}
})
and the template would receive this data: (it would handle the subscribe and fetching)
{
"user" : {
"_id": '1234',
"name": "Jane Doe",
"isViewerFriend": true,
"profilePicture": {
"uri": "http://someurl.cdn/pic.jpg",
"width": 50,
"height": 50
}
}
}