RapidAPI Profile picture
Feb 3 β€’ 20 tweets β€’ 5 min read
Let's break down the process of building a GraphQL server from scratch.

Thread πŸ§΅πŸ‘‡πŸ»
Let's start with the theoretical discussion.

Quickly take a look at this thread to get started with GraphQL. πŸ‘‡πŸ»

We are assuming you have Node.js installed on your machine. If you haven't installed it, click on the following link and install it simply.

nodejs.org/en/
As now you know what GraphQL is, let's start creating a quick GraphQL server.
Open your terminal and run the following commands: πŸ‘‡πŸ»

It will simply create a new directory as "graphql" and initialize the project. Create a new directory as "graphql" and initialize
The next step is to create an empty JavaScript file (File name could be anything, in this case, app.js) and install all the necessary packages.

We will discuss the use of each package as we progress further into this thread. Install express, express-graphql, and graphql packages.
Perfect! Now we have all the necessary packages and files, let's create a basic local server. πŸ‘‡πŸ»
In the below code snippet, we initialize our `app` and start the local server at port 3000.

Run `node index.js` to start the server. Start the server.
Our server is now running, it's time to build the schema that is nothing but the description of data that the client can request.
Let's create a new "schema" folder in our graphql directory.

Inside that schema folder, create a JavaScript file as schema.js.

graphql > schema > schema.js
Let's start with creating a simple `User` schema inside the schema.js file.

We need two things:

- Schema that defines the Query type.
- A β€œresolver” function for each API endpoint.

The resolver function is a collection of functions that generate responses for a GraphQL query. Build schema and resolver function of each endpoint.
The above code is pretty intuitive.

`User` type has two fields, name and age of type string and integer, respectively.

The `root` provides the resolver function. In this case, we are resolving `user` type which returns the value of name and age.
Visit RapidAPI Learn and get in-depth details about Schema Definition Language for more context.

RapidAPI.com/learn/graphql-…
Export `schema` and `root` so that we can use them in our app.js file.

Add below code snippet at the end of schema.js file. Exporting schema.
It's time to run this query on the GraphQL Server that we just built (app.js file).

We will use `graphql-express` libaray to run GraphQL server on "/graphql" HTTP endpoint. `graphql-express` libaray to run GraphQL server on "/gr
`graphiql: true` provides the GraphQL playground.

Head over to http://localhost:3000/graphql and you see the playground like this. πŸ‘‡πŸ» GraphQL playground.
Let's try to run the query and see what we get. Run query.
And we are getting the data.

In our query, we requested for `name` and `age` fields of the `User` type. Run query and get data.
Assuming you only need to fetch `age`, in GraphQL, you don't need to create a separate endpoint that you would have needed if you were working with REST API. Fetching age field from GraphQL server.
And with that being said, this is the end of this thread.

Follow @Rapid_API for more excellent content such as this one. πŸ’™πŸ™

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with RapidAPI

RapidAPI Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Rapid_API

Feb 3
What exactly is the HTTP-based system.

Thread πŸ§΅πŸ‘‡πŸ»
HTTP is a communication protocol that establishes the connection between web browsers and web servers.
HTTP is entirely based on the client-server model, where the client initiates the request then waits until it receives a response from the server.
Read 19 tweets
Feb 2
What exactly is GraphQL.

Thread πŸ§΅πŸ‘‡πŸ»
GraphQL is a query language that lets your client request the server to send only the required data.
GraphQL was created by developers at Facebook in 2012.

GraphQL was developed to support the complicated data structures required to show the Facebook News Feed on the mobile application.
Read 18 tweets
Feb 1
What exactly is an API?

Thread πŸ§΅πŸ‘‡πŸ»
API is the acronym for Application Programming Interface.

In simple terms, API is an interface that lets your application talk to another application.
API is a set of definitions and protocols that allow technology products and services to communicate.

This may not sound very clear. Let's break it down.
Read 15 tweets
Jan 31
How to make your API secure.

Thread πŸ§΅πŸ‘‡πŸ»
Building an API is one thing, and securing it is another.

If your API is vulnerable, the user's sensitive information will be at risk.

Hence, it's crucial to deliver a secure API.
If your API is not secure, the attackers can quickly access your network by exploiting vulnerabilities in your APIs.

Before deep-diving into making your API secure, let's first discuss what are some common attacks. πŸ‘‡πŸ»
Read 14 tweets
Jan 31
Top 10 Artificial Intelligence APIs.

Thread πŸ§΅πŸ‘‡πŸ»
1️⃣ Extract Table - DocumentDev

- Extract information from PDF Tables instantly. Using the power of Artificial Intelligence and NLP.

RapidAPI.com/documentdev/ap…
2️⃣ Sentiments

- Sentiments API returns the sentiment score of any given text.

RapidAPI.com/connexun-srl-c…
Read 12 tweets
Jan 27
API development becomes a little easier if you know the correct terms and their correct meaning.

Here, we complied with widely used terms in API development.

Thread 🧡
πŸ“Œ API Key

An API key is a unique code that lets you call an API.

The only rule is that these keys must be unique and not easy to guess.

Generally, API keys contain lower case and upper case letters with numbers.
πŸ“Œ API Token

The API token is a unique identifier of an application requesting access to your API.

An API token is a form of authentication similar to a username/password.
Read 17 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

:(