Meteor’s data layer is no longer used.
Grapher is composed of 3 modules
- Linking
- Query (Hypernova / Publish Composite Bridge)
- Exposure (The client-server bridge (publication and methods))
Because of Apollo, the 3rd module Exposure is no longer needed. However, where Grapher shines is in it’s way to modularise links, how fast it performs fetching nested links, and the security offered by named queries or global queries.
Let’s take the example, where you want, all posts, all comments, and the users that commented. With GraphQL, after you setup the resolvers, you would simply bombard the database with requests 1 for posts , length(posts) for comments, lenght(allComments) for users.
When you’re dealing with a remote database, the time to do that increases dramatically (you’ll be doing something along 100 db requests). While Grapher can do this in 3 requests using the Hypernova technology. My initial tests with a local database, showed improvements up to 40x, which is crazy.
And your resolvers can look like this:
{
Post: {
comments: (root, args, context) {
if (root.comments) return root.comments;
return Posts.getLink(root._id, 'comments').fetch(); // optional
}
}
}
Now, here’s the interesting part, we’ve checked that if we already have comments than we just return them from the parent, (because resolver takes precedence over field)
I’ve build a quick function that transforms the ATS into a Grapher Query, meaning:
posts(root, args, context, ast) {
return Posts.createQuery(toGrapherQuery(ast)).fetch()
}
toGrapherQuery
transforms the AST into the default format that Grapher accepts with keys and 1
s. This is not exposed yet to the public, I plan on releasing a full Reactive Apollo Implementation that works hand-in-hand with Meteor/Grapher/Redis-Oplog, and in next release have Reactive Graphs (like we have with Grapher leveraging publishComposite). I have already blueprints stored and technical specs, it’s just a matter of time.
Another problem that this solves is that you don’t get from the db ALL THE FIELDS, you get only the fields you need, lowering bandwidth and ultimately increasing performance.
Apollo is still behind in terms of security, meaning that the amount of code to restrict some fields or links is just too much code to write. I plan on helping on that part as well, to use the technologies innovated in Grapher for that.
Hope this was helpful, cheers!