3 ms·
Explain the spec, or the tech? Well the spec basically exists because some people at Facebook noticed that it's more efficient for the client to request exactly
by satvikpendem 4y ago
Explain the spec, or the tech? Well the spec basically exists because some people at Facebook noticed that it's more efficient for the client to request exactly the data it needs than to have the server send everything and the client has to transform it. Yes, REST could work, but once you have more complex data structures, it becomes harder.
For example with a todo list app, if you want a user's todos that are complete, your request might look like
/api/todos/$userId/$completionStatus
Now if you want the todo titles, completion status, and description, but don't want a field like subtitle, you could send the entire todo from which the client could extract the necessary fields, but why? That's extra data sent over the wire and extra computation done on the client, for basically no real reason. So maybe in your api, you do something like
/api/todos/$userId/fields=title&$completionStatus&description
Congratulations, you reinvented GraphQL.