What is GraphQL?
Before we start learning how to use GraphQL, let’s first focus on what GraphQL is. Like REST, it is a way to query APIs. However, it is also much more than that. GraphQL includes a server-side runtime for executing queries and a type system to define your data. It works with many database engines and can be integrated into your existing backend.
GraphQL services are created by defining types (such as a User
type), fields on types (such as a username
field), and functions to resolve values of fields. Let’s assume we have defined the following User
type with a function to get a username:
type User { username: String } function User_username(user) { return user.getUsername() }
We could then define a Query
type and a function to get the current user:
type Query { currentUser: User } function Query_currentUser(req) { return req.auth.user }
Info
The Query
type is a special type that defines the...