A minimalistic yet versatile GraphQL server starter designed to streamline the development of GraphQL-powered applications. This project is built with scalability and simplicity in mind, making it suitable for side hustles, educational purposes, or full-fledged production-grade applications.
- Users have their own dynamic GraphQL endpoints at
/username/graphql
. - Each user endpoint is protected with authorization, ensuring privacy and security. Unauthorized access attempts are denied.
- Publicly accessible at
/graphql
without restrictions. - Ideal for shared resources or testing purposes.
- Enables users to search for word meanings.
- Utilizes web scraping techniques to fetch dictionary data.
- Great for developers new to web scraping—learn foundational techniques from the codebase.
- The power of GraphQL allows users to:
- Fetch only the fields they need.
- Control how the data is displayed and accessed.
- Supports resource queries like
users
andposts
, demonstrating relational data handling.
- Node.js (v16 or later)
- A Vercel account for deployment
-
Clone the repository:
git clone https://github.com/rockyessel/graphql-server-starter-vercel.git cd graphql-server-starter-vercel
-
Install dependencies:
npm install
-
Configure the environment variables:
- Create a
.env
file in the project root. - Add the necessary variables:
SAMPLE='HelloWorld' JWT_SECRET="JWT_SECRET"
- Create a
-
Run the server locally:
npm run dev
-
Visit the endpoints:
- Public endpoint: http://localhost:4000/graphql
- Dynamic user endpoint (example): http://localhost:4000/emilys/graphql
- Fork or clone the repository.
- Link the project to your Vercel account.
- Add environment variables in the Vercel dashboard.
- Deploy the project with one click from the dashboard.
Fetch the meaning of a word:
query {
dictionary(word: "example") {
word
meaning
}
}
Fetch user details and their posts:
query {
user(username: "emilys") {
name
email
posts {
title
content
}
}
}
Fetch all posts:
query {
posts {
title
author {
username
email
}
}
}
- Public endpoints (
/graphql
) are accessible without restrictions. - Private endpoints (
/username/graphql
) require a valid authorization token. - Unauthorized attempts to access protected resources are denied with an appropriate error message.
-
Web Scraping Techniques:
- Explore the dictionary query feature to understand scraping fundamentals.
-
Dynamic GraphQL Endpoints:
- Learn how to set up and manage user-specific paths dynamically.
-
Authorization in GraphQL:
- Implement secure access control to sensitive resources.
Contributions are welcome! If you have ideas for improvements or additional features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Special thanks to rockyessel for this incredible starter project.
- Inspired by the need for scalable and secure GraphQL applications.