Zencargo and GraphQL
GraphQL is Zencargo's technology of choice for building APIs. If you're used to working with REST APIs, then GraphQL might seem confusing at first. When you begin using GraphQL, you need to change how you think about retrieving and working with data. The following guides are designed to introduce you to GraphQL concepts and to help you begin experimenting with GraphQL.
What is GraphQL?
GraphQL is a query language and a runtime for fulfilling those queries. Clients form requests (Queries & Mutations) by using the GraphQL query language, and the GraphQL server executes the request and returns the data in a response. Unlike REST APIs, which expose a different endpoint for each resource object, a GraphQL API makes all data available at a single endpoint. GraphQL gives clients the power to ask for exactly what they need and nothing more.
GraphQL & its benefits
Before you start playing with GraphQL and sending requests, let's examine some of the benefits of using GraphQL
| GraphQL | REST |
|---|---|
| Only get exactly what you need from the server, and receive that data in a predictable way | No control over received data, always getting whole payload |
| Ability to retrieve many resources in a single request | Fetching associated data often requires multiple HTTP calls |
| Everything is typed and part of a schema which allows API consumers to know exactly what data is available, and in what form it exists | Usually weakly-typed and lack machine-readable metadata |
| Documentation & Deprecation are first class citizens | Needs versioning & Explicit documentation of endpoints and payloads |
Your first steps with GraphQL
- Your first GraphQL call tutorial
- API Console is your GraphQL playground!
- GraphQL queries
- GraphQL Mutations (submitting changes)
- GraphQL Variables
- Paginating results with GraphQL
Other GraphQL resources
If you want to look deeper into GraphQL here are some guides & starting points to do so:
Guides
-
GraphQL official documentation Read the official GraphQL user documentation and learn about other features of GraphQL, including more advanced aspects such as fragments, aliases, and directives.
-
How to GraphQL Read an in-depth guide about GraphQL, and complete the full-stack tutorial. In the tutorial you create a GraphQL schema and server (available in several languages), and then build an app that runs queries and mutations against the schema.
Libraries
- Apollo Client official documentation Apollo Client enables you to define data requirements as part of UI components. Apollo also has a library for creating your own GraphQL server and defining your own API schema.