Getting started with GraphQL

John Kilonzi
Level Up Coding
Published in
4 min readMay 16, 2020

--

For a long time, the world of API had been relying on REST and SOAP. Simple Object Access Protocol (SOAP) was invented in 1998, while Representational State Transfer (REST) came into existence in 2000. These two have dominated application programming interfaces for almost one and a half decades. In 2015, GraphQL was released by Facebook. This has become the new way query data, and can be considered to be a competitive alternative to SOAP and REST.

GraphQL is ushering in a new era when it comes to defining APIs but as with all technologies, there are specific cases where one is likely to do a better job with REST.

GraphQL is known for being simpler, faster, and efficient allowing users to fetch exactly the data they need. Additionally, GraphQL is both a query language and an execution engine and can be tied to any backend service, data source including REST itself.

In this article, I will provide a simple introduction to GraphQL and a tool that can simplify your learning or you can use in your future work.

API development with GraphQL requires a schema to define the resources it is going to operate on. In order to access or modify these resources, you need to create a Query or Mutation type that will be sent to the server. All the three, Resource Definition, Query and Mutation can be defined on one file depending on the language preferences. GraphQL files have the extension (. gql or. graphql) c cn

The code output here can also be created from https://skimaql.com.

Every GraphQL implementation is a description of what types of objects it can return (GraphQL type system) and is the most crucial part of the GraphQL Schema. The type system is just an explanation of the kind of characteristics or attributes that are associated with an object. Let's assume we are building a twitter clone (with Users, Posts, and Comments).

The user object can contain an [id to uniquely identify the user, the name, an email, a password, a phone] all these can be represented in a GraphQL Type System.

type User {       id: ID!       name: String       phone: String       email: String! #Cannot be null

--

--