2024-04-22

I will be giving an overview of what GraphQL entails

Blog post by MF Mabala

GraphQL Overview

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. In this blog you will learn the basics of GraphQL.

GRAPHQL INTRODUCTION

1.Describing your data.

Describing your data means giving types to the data that you will be using. You always have to specify the types We will be using typescript so make sure you are familiar with the concept.

Example

type Hero {
  name: string,
  age: Int,
  tenant: boolean,
}

This will make sure that the data that we use is not used in wrong way.

2.Asking what you want

With the code below we are saying in the defined type project we want the age of the object(s) with the name "tommy".

{
project(name: "tommy"){
  age
}
  
}

3. Get what you asked for.

You have asked for the data in number two and this is what you will receive as a response below.

{
  "project":{
    "age": "34"
  }
}

There are a lot of things that you will learn in GraphQL and it is important to do so with understanding. Everything is linked.

Scalar Types

A scalar- is a type that represents a single value and it is the basic building block of the schema that you will want to create. We can say that they are the leaf values in GraphQL. Here are examples of the scalar types

  • String- A UTF‐8 character sequence.
  • Int- A signed 32‐bit integer.
  • Boolean -True or False.
  • Float- A signed double-precision floating-point value.
  • ID - The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache.

Defined Schema.

type Query { 
  human: Human
} 
type Human { 
  studentID :ID 
  name: String 
  age: Int 
  isStudent: Boolean 
  weight: Float 
}

Now that we have described our data we can make queries and get our expected response. We will go deeper into context. In the next part I will be writing about GraphQL migration to pothos.

Thank you for reading my blog.