This repository showcases the creation of a GraphQL server using Fastify, Mercurius, and GraphQL. The project evolves through different versions, each offering more features and complex responses.
The project consists of three versions of a GraphQL server:
server_v0.js
: Returns a hardcoded name and message.server_v1.js
: Expands functionality to request name and message.server.js
: Returns properties with attributes such as description and address.
Ensure you have the following libraries installed:
This is how to get the project from Github
git clone https://github.com/tomsouza4/graphql-from-scratch.git
Or you can create your own: Navigate to the desired folder:
cd ~/Documents
Create and enter the folder:
mkdir graphql-from-scratch
cd graphql-from-scratch
Initialize the project:
npm init --yes
Install required libs for this project
npm install fastify mercurius graphql
Open the project with Visual Code(May require to add this PATH, on Visual Code run: Shell Command: Install 'code' command in PATH)
code .
data
sayHello
name "Akshay"
message "Akshay> Learning GraphQL"
{
"data": {
"sayHello": {
"name": "Luis F.",
"message": "Luis F.> I like GraphQL"
}
}
}
-
- Sample result from code:
{
"data": {
"availableProperties": [
{
"description": "A big house",
"address": {
"street": "123 Elm St",
"city": "Miami",
"state": "FL",
"zipCode": 33137
}
}
]
}
}
-
- After updating const resolvers to filter by city
{
"data": {
"availableProperties": [
{
"description": "A big pink house with yellow people",
"address": {
"street": "321 Evergreen Lane",
"city": "Springfield",
"state": "MO",
"zipCode": 44212
}
}
]
}
}