GraphQL is (from their site):
- DECLARATIVE
- Query responses are decided by the client rather than the server. A GraphQL query returns exactly what a client asks for and no more.
- COMPOSITIONAL
- A GraphQL query itself is a hierarchical set of fields. The query is shaped just like the data it returns. It is a natural way for product engineers to describe data requirements.
- STRONG-TYPED
- A GraphQL query can be ensured to be valid within a GraphQL type system at development time allowing the server to make guarantees about the response. This makes it easier to build high-quality client tools.
The GraphQL website has a lot of additional information, documentation, and some initial implementations.
I'm going to assume that you're at least roughly familiar with it, but as a quick example, this query:
{ hero { id name friends { id name } } }
This query could return something like:
{ "data": { "hero": { "id": "2001", "name": "R2-D2", "friends": [ { "id": "1000", "name": "Luke Skywalker" }, { "id": "1002", "name": "Han Solo" }, { "id": "1003", "name": "Leia Organa" } ] } } }
A simpler query over the same data that is parameterized might look like:
query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } }
And a response from that, given a value of 1000 for $someId would …
read more »