This repository contains code that provides a GraphQL API and a search API using MeiliSearch. It also creates the Vanderbilt Course Catalog database using MongoDB and the Vanderbilt API. Fastify is used to create the server and Mercurius is used for to create the GraphQL endpoints.
To install and run this project, follow these steps:
-
Clone the repository:
git clone https://github.com/SySyAli/vanderbilt_catalog-api.git
-
Install the dependencies:
cd your-repo npm install
-
Set up the environment variables:
MONGODB_URI
: MongoDB connection URI (default:'mongodb://localhost:27017'
)PORT
: Server port (default:3000
)MEILISEARCH_HOST
: MeiliSearch host URL (e.g.,'http://localhost:7700'
)
-
Set up MeiliSearch:
- Install MeiliSearch following the instructions in the official documentation.
- Start the MeiliSearch server using the appropriate command for your setup.
-
Start the server:
npm start
The server will start running on
http://localhost:3000
.
The GraphQL API allows you to interact with the course catalog.
GET /graphql?query&operationName&variables
query
, the GraphQL query.operationName
, the operation name to execute contained in the query.variables
, a JSON object containing the variables for the query.- The
operationName
andvariables
field are not need to be used for this repo as there is not need to specify the type of operation and there are no variables need to specify for the query. - This information was taken from Mercurius
type Course {
_id: ID!
code: String!
name: String!
department: String!
departmentAbbreviation: String!
hours: String!
description: String!
}
Below are the available query types:
Fetches a single course by its ID.
Example request:
GET /graphql?query={course(_id: "123456789"){ _id, code, name, department, departmentAbbreviation, hours, description}}
courses(code: String, name: String, department: String, departmentAbbreviation: String, hours: String, description: String)
Fetches multiple courses based on the provided filters. If a field is not needed, do not send it in the request. No filters will fetch the entire database.
Request to fetch the entire database:
GET /graphql?query={courses(){ _id, code, name, department, departmentAbbreviation, hours, description}}
Example request with a filter:
GET /graphql?query={courses(department: "Chemistry"){ _id, code, name, department, departmentAbbreviation, hours, description}}
The search API allows you to perform keyword-based searches on the course catalog using MeiliSearch.
Performs a search query on the course catalog.
Example request:
GET /search/cs
This will return courses related to "cs".
Contributions to this project are welcome. If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License. Feel free to use and modify the code as per the license terms.