Continuing my learning of the Node environment outside Meteor, I’m trying to reconcile what Apollo does compared to what I see in Express apps. Am I correct in saying GraphQL resolvers replace Express API endpoints? So rather than defining my GETs, POSTs, etc. I’m simply using queries and mutators?
It’s not that GraphQL replaces Express endpoints (you normally still create at least one end point via Express).
But it’s rather that you replace the very idea of endpoints, with data entities.
Your resolvers provide (only) the data the client queries for (e.g. by querying an external data source, one or more databases, an external REST API, etc.).
So you design your API in terms of logical business entities and return all the required data with one response, instead of the client having to query several endpoints to get it all:
So, for example, the client asks for posts, and for each of the posts it asks for the text, a date and all the comments on that post. Now you think in terms of nested data entities, all of which you want at the same time. A post has its own fields and one of it is a list of comments (and then each comment has its own list of fields, like author, date etc, but you don’t want the actual text for example)… And your GraphQL server returns all of this (and only this) in one response, where with REST you might have had to send requests to two or more end points, which in turn would have given you a bunch of data you possibly didn’t even want.
Awesome. That makes sense. Thanks.