for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. — graphql.org
users, just shout ‘/USERS’, and I’ll give you a list of them. But if you want to see the products the user has bought, you gotta shout ‘/USER/PRODUCTS’ along with the user’s ID and if you want…etc. Got it? *in Morty’s voice* Man, that was a lot of things, could you write that down for me? No way I could remember all that. Sure, the devs have written really nice documentation for you.
can call. Just a bit more powerful, because the client can determine exactly what it wants returned and can combine some of these functions. If you’ve ever used SQL, this should have started becoming clear by now. In SQL you write queries to get the data you want from the database, how you want it. The difference here is that: • You’re not querying from within the same application, you’re using the client application to query the server application. • You get to define what these queries are/can be.
would make if it wanted to get a list of Heroes and their names, powers & a list of Villains, their names, powers and crimes they committed between ‘82 and 2017
tools like GraphiQL can generate docs from your server code easily. The client no longer needs to make multiple queries to display data of different models on one view. You can adopt it incrementally. One can just add GraphQL to their server without changing how it works. It’s not tied to any specific language or framework, you can use any DB you like! It improves organisation, communication between developers and stability of code.
of a schema An Object Type is a type with some fields Built in scalar type. Like primitive types. This means non-nullable An array of Episode types This is a field. Define what can appear in a GraphQL query
is language agnostic, and we cannot rely on specific syntax to describe our data. That’s why the schema language is necessary. Each field is backed by an arbitrary function in the server’s code. ‼‼ More Pros Because GraphQL is strongly typed. It can provide descriptive error messages before queries are executed. Both on the server and client. GraphQL is introspective. Clients can query servers for the types it supports. IDEs and libraries leverage this for hints and code generation.